seppevs / migrate-mongo

A database migration tool for MongoDB in Node
MIT License
927 stars 163 forks source link

Latest version (8.1.1) possible regression issue #227

Closed arketec closed 4 years ago

arketec commented 4 years ago

I have a migration script that works without issue on my local version of migrate-mongo (v4.1.2) but fails on the latest version (v8.1.1)

here is the information:

script: `module.exports = { async up(db) { // TODO write your migration here. Return a Promise (and/or use async & await). // See https://github.com/seppevs/migrate-mongo/#creating-a-new-migration-script // Example: // return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: true}});

await db.collection('deductibles').updateOne({key: 2001500}, {$set: {default_for_rating:  [ 
    "AR", 
    "AZ", 
    "CA", 
    "CO", 
    "ID", 
    "NM", 
    "NV", 
    "OK", 
    "OR", 
    "TX", 
    "UT", 
    "WA"
]}})

await db.collection('deductibles').insertOne({
    "key" : 2001500,
    "value" : "1500",
    "data_to" : null,
    "date_from" : new Date("1900-01-01T00:00:00Z"),
    "states" : [
        "AR",
        "AZ",
        "CO",
        "ID",
        "NM",
        "NV",
        "OK",
        "OR",
        "TX",
        "UT",
        "WA"
    ],
    "default_for_rating" :  [
        "AR", 
        "AZ", 
        "CO", 
        "ID", 
        "NM", 
        "NV", 
        "OK", 
        "OR", 
        "TX", 
        "UT", 
        "WA"
    ]
})

await db.collection('deductibles').insertOne({
    "key" : 2002500,
    "value" : "2500",
    "data_to" : null,
    "date_from" : new Date("1900-01-01T00:00:00Z"),
    "states" : [
        "AR",
        "AZ",
        "CA",
        "CO",
        "ID",
        "NM",
        "NV",
        "OK",
        "OR",
        "TX",
        "UT",
        "WA"
    ],
    "default_for_rating" :  [
        "CA"
    ]
})

},

async down(db) { // TODO write the statements to rollback your migration (if possible) // Example: // return db.collection('albums').updateOne({artist: 'The Beatles'}, {$set: {blacklisted: false}});

await await db.collection('deductibles').deleteOne({key: 2001500})
await await db.collection('deductibles').deleteOne({key: 2002500})

} }; `

And here is the console output:

console log: 17:51:34 /usr/local/lib/node_modules/migrate-mongo/node_modules/fs-extra/lib/mkdirs/make-dir.js:85 17:51:34 } catch { 17:51:34 ^ 17:51:34 17:51:34 SyntaxError: Unexpected token { 17:51:34 at createScript (vm.js:80:10) 17:51:34 at Object.runInThisContext (vm.js:139:10) 17:51:34 at Module._compile (module.js:617:28) 17:51:34 at Object.Module._extensions..js (module.js:664:10) 17:51:34 at Module.load (module.js:566:32) 17:51:34 at tryModuleLoad (module.js:506:12) 17:51:34 at Function.Module._load (module.js:498:3) 17:51:34 at Module.require (module.js:597:17) 17:51:34 at require (internal/module.js:11:18) 17:51:34 at Object.<anonymous> (/usr/local/lib/node_modules/migrate-mongo/node_modules/fs-extra/lib/mkdirs/index.js:3:44)

seppevs commented 4 years ago

Are you running Node 8? If so, try to upgrade to Node 10 (or higher). I'm pretty sure that is the issue. Can you confirm this please? Thank you.

Letarion commented 4 years ago

I don't think it's that, as I am trying to initialize a migrate-mongo (v8.1.1) project freshly and getting the same error. On a docker image that is running node 10.16.3

seppevs commented 4 years ago

I have just tested with node 10.16.3, and I can initialize a project, migrate up and get the status without any problem?

$ node -v
v10.16.3
$ mkdir test-project
$ cd test-project
$ migrate-mongo init
Initialization successful. Please edit the generated `migrate-mongo-config.js` file
$ migrate-mongo create "abc"
Created: migrations/20200722153528-abc.js
$ migrate-mongo up
MIGRATED UP: 20200722153528-abc.js
$ migrate-mongo status
┌───────────────────────┬──────────────────────────┐
│ Filename              │ Applied At               │
├───────────────────────┼──────────────────────────┤
│ 20200722153528-abc.js │ 2020-07-22T15:35:31.956Z │
└───────────────────────┴──────────────────────────┘
arketec commented 4 years ago

You were right about it being node 8. Our build machine was running node 8 and after upgrading to node 10.16.3 the script functioned properly. Thanks for the assist!

seppevs commented 4 years ago

I'm closing this issue.