Giter Club home page Giter Club logo

mongo-migrate-ts's People

Contributors

dependabot[bot] avatar gustawdaniel avatar ispirals avatar juancarlosllhl avatar krispy2009 avatar mycodeself avatar pouyio avatar timonmasberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mongo-migrate-ts's Issues

No migrations found

The second execution of ts-node migrations/index.ts up will prompt "No migrations found". how to solve it

ERR_REQUIRE_ESM after installing globally

Hi, I've installed the package using npm install -g mongo-migrate-ts according to the instructions, but when I try to run the CLI using mongo-migrate I get:

internal/modules/cjs/loader.js:1015
      throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
      ^

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /opt/homebrew/lib/node_modules/mongo-migrate-ts/node_modules/ora/index.js
require() of ES modules is not supported.
require() of /opt/homebrew/lib/node_modules/mongo-migrate-ts/node_modules/ora/index.js from /opt/homebrew/lib/node_modules/mongo-migrate-ts/dist/lib/commands/down.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /opt/homebrew/lib/node_modules/mongo-migrate-ts/node_modules/ora/package.json.

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1015:13)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/opt/homebrew/lib/node_modules/mongo-migrate-ts/dist/lib/commands/down.js:7:31)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14) {
  code: 'ERR_REQUIRE_ESM'
}

I tried both on node v14.18.2 and v12.22.10 installed via homebrew on an M1 mac

Is this a known issue, or is this something I've messed up on my side?

Transactions support

Hey, thanks a lot for this package!

I think it would be really nice to be able to enable transactions (when the instance supports it) to wrap up the migration execution.

I'd be thrilled to implement this if you support this :)

No migrations found

Steps I have taken

  1. npm install mongo-migrate-ts
  2. mkdir migrations
  3. touch index.ts

index.ts


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

const MONGO_URL = "mongodb://localhost:27017";

mongoMigrateCli({
  uri: MONGO_URL,
  database: "db",
  migrationsDir: "migrations",
  migrationsCollection: "migrations_collection",
});

migrations/migration_1.ts

import { MigrationInterface } from "mongo-migrate-ts";
import { Db } from "mongodb";
import { getItem, MY_COLLECTION } from "../common";

export class MyMigration implements MigrationInterface {
  async up(db: Db): Promise<any> {
    const item = getItem();
    const data = await db
      .collection(MY_COLLECTION)
      .find()
      .toArray();
    if (data.length === 0) {
      await db.collection(MY_COLLECTION).insertOne(item);
    }
  }

  async down(db: Db): Promise<any> {
    const item = getItem();
    await db.collection(MY_COLLECTION).deleteOne(resident);
  }
}
  1. tsc index.ts && node index.js up

response: ⚠ No migrations found

Tryed installing globally and using CLI, resilt is the same

Custom timestamp format for files generated by command "new"

Just thinking out loud: since this package is based on migrate-mongo (https://github.com/seppevs/migrate-mongo/) I think it's nice to have transition plan to how to switch from migrate-mongo JS to mongo-migrate-ts.

Anyway, for this particular case, during that switch (from migrate-mongo JS to mongo-migrate-ts) I faced the issue of different format of files:

image

  • 1697236860399_Migration.ts | generated by mongo-migrate-ts
  • 20230105075728-migration.js | generated by migrate-mongo JS

So this is enhancement suggestion: unify format for file naming OR add the config option (migrations.json) to use specific time format.

πŸ““ The difference of timestamps:

Sample migration file

Overriding the sample migration

To override the content of the sample migration that will be created by the create command, create a file sample-migration.js in the migrations directory.

Is it possible to make something similar, to avoid linter erorrs and e.t.c?

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


Cannot push to the Git repository.

semantic-release cannot push the version tag to the branch master on the remote Git repository with URL https://[secure]@github.com/mycodeself/mongo-migrate-ts.git.

This can be caused by:


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Down Function does not seem to work

When I call the down function, for some reason, it does not work and in terminal I see output as if you had called for a --help command. Any idea why the down function is not working or how to debug this?

image

Migrations exception handling

Hello, first of all, thank you for developing this package it is very useful and easy to use.

I've mostly used migrate-mongo, but now I'm working on a TypeScript project and decided to try this out.

Something I found is that if an error occurs during for instance the down process of migration, the error case of this is not handled by the package, and the CLI gets stuck.

E.g.
Screenshot 2023-03-30 at 11 48 32

I've added the --unhandled-rejections=strict flag and it seems like a workaround, but not sure if it is the best way to handle such cases.

Thanks in advance!

Migrate process fails with replica set connection string

When using connection string in SRV format like mongodb://mongo1:27017,mongo2:27017,mongo3:27017/socio?replicaSet=replset0 or mongodb+srv://mongo1:27017,mongo2:27017,mongo3:27017/socio?replicaSet=replset0 module fails as it uses standard URL parser which cannot work with connection string syntaxt (which actually not WHATWG URL).

It can be fixed by using special module like connection-string module which is aware of multi-host URIs

No migrations found when running in ts-node

Using the version 1.0.9 doesn't detect properly when running in ts-node.
I tried to make a migration using the following commands:

$ env-cmd tsnd src/migrations/index.ts up
$ ts-node-dev -r dotenv/config src/migrations/index.ts up
$ ts-node -r dotenv/config src/migrations/index.ts up

And despite them executes the index with ts-node (direct or indirectly), the function isTsNode doesn't return true making the loadMigrations function looking for files with js extensions, so the command ends without finding any migrations:
image

I solved this downgrading to the version 1.0.6, but I think it's something to take in consideration in future versions.

Add nested migration directories support

Hello,

Is it possible to add support for nested directories ?

Let's say i have many directories ordered by version :
--- migrations /
---------------V1.1/
---------------------V1.1.001_add_user.ts
---------------V1.2/
---------------------V1.2.001_update_user.ts

up command does not find migration files for /migrations path.

Thanks a lot for the package, works like a charm :)

Regards

Error executing migrations

When I use the ts-node migrations/index.ts up command to execute migrations I get the following error

Error executing migration Migration1658840191491 βœ– Error executing migrations ExecuteMigrationError: MongoServerError: ns not found

The command only executes the first migration and all others throw an error.

my index.ts file contains the following:

`import { mongoMigrateCli } from "mongo-migrate-ts";
import 'dotenv/config';

mongoMigrateCli({
uri: mongodb:${process.env.MONGO_HOST},
database: ${process.env.MONGO_DB},
migrationsDir: __dirname,
migrationsCollection: "migrations_collection",
});`

Migration naming

I think it is better to accept a name for creating new migration

Configure migration template

It would be nice to configure a custom migration template for the mongo-migrate new command. This would enable us to prevent copy-paste mistakes with boilerplate code. At the moment, the template is hard-coded into the library source.

I imagine it could be an easy win to implement something like the -t option in migrate-mongoose. There, you can supply a template file (via command line flag or config file). The content of the template is copied verbatim into new migrations.

init option requires an existing config file

When running mongo-migrate init (or mongo-migrate -h for that matter), it throws an error due to no config file being found, even though the command itself should create that config file.

Migration does not work when invoking compiled code with node

When you compile the project ant try tu run it using command node build/migrations/index up migration fails with error:

Migrations up/home/projects/dist/migrations/20200326_01.d.ts:1
import { MigrationInterface } from 'mongo-migrate-ts';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1063:16)
    at Module._compile (internal/modules/cjs/loader.js:1111:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /home/danielius/projects/efi/git/efi-fatca/node_modules/mongo-migrate-ts/dist/lib/migrations.js:27:69
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.exports.loadMigrationFile (/home/danielius/projects/efi/git/efi-fatca/node_modules/mongo-migrate-ts/dist/lib/migrations.js:27:21)

The issue is that node tryes to load *.ts files found in migration diretory and fails. It should load only *.js files

add glob option to pick migrations

mostly if somebody is ever interested into testing their migrations before, the obvious choice will be to do:

/migrations
  1234567890-migration.ts
  1234567890-migration.test.ts

then when you do index up then the .test runs as a migration. bummer

MongoDB version constraint

The mongodb package is listed in the peerDependencies at major version 4, which is preventing me from updating mongodb to the latest major version.
Is there any compatibility issues with version 5 that require version 4 specifically? My testing so far shows that version 5 works fine, but it's possible I haven't tested everything.
In any case, thank you for sharing this package, it is very useful.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.