Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hey, thanks a lot for this package! init file is in json format. How i convert it in ts format? So the connection string generated from db file is use in all places. #87

Closed
Hassan829 opened this issue May 22, 2023 · 4 comments

Comments

@Hassan829
Copy link

No description provided.

@Hassan829 Hassan829 changed the title init file is in json format. How i convert it in ts format? So the connection string generated from db file is use in all places. Hey, thanks a lot for this package! init file is in json format. How i convert it in ts format? So the connection string generated from db file is use in all places. May 22, 2023
@gustawdaniel
Copy link
Contributor

User

tsx src/index.ts new

instead of mongo-migrate command and src/index.ts like

import { mongoMigrateCli } from 'mongo-migrate-ts';

mongoMigrateCli({
  uri: 'mongodb://username:password@0.0.0.0:27017',
  database: 'db',
  migrationsDir: __dirname + '/../migrations',
  migrationsCollection: 'migrations_collection',
});

finally to apply migrations

tsx src/index.ts up

@gustawdaniel
Copy link
Contributor

gustawdaniel commented Jul 25, 2023

I tested and it does not works with tsx.

Problem is with migrations detection because of line

    const fileExt = (0, isTsNode_1.isTsNode)() ? new RegExp(/\.ts$/i) : new RegExp(/\.js$/i);

in loadMigrations function.

Ther is js extension detected in tsx because of output of function isTsNode_1.isTsNode

where

const isTsNode_1 = require("./utils/isTsNode");

which is implemented as

const isTsNode = () => {
    const symbol = Symbol.for('ts-node.register.instance');
    return !!process[symbol] || !!process.env.TS_NODE_DEV;
};

@gustawdaniel
Copy link
Contributor

fixed by

TS_NODE_DEV=1 tsx src/index.ts up

lol

@mycodeself
Copy link
Owner

Yes, it supports ts-node, I haven't tried tsx, but I think this is a good workaround

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants