atdatabases icon indicating copy to clipboard operation
atdatabases copied to clipboard

migrationsScript property not working with a string

Open isaiasmb opened this issue 5 years ago • 2 comments

Hi,

When I run my tests, I received this error:

Error: MySqlConfig.test.migrationsScript should be array

packaged.json config:

"mysql": {
        "test": {
            "migrationsScript": "npm run db:migrate"
        }
    }

If I change to Array:

"migrationsScript": [ "npm run db:migrate" ]

I received this:

Error: spawn npm run db:migrate ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

In the file node_modules/@databases/mysql-config/lib/MySqlConfig.validator.js has this validation:

migrationsScript: {
                    description: 'Optional script to run after the database\nhas been started but before running tests',
                    items: {
                        type: 'string'
                    },
                    type: 'array'
                },

But in the @databases/[email protected] TAG has this:

migrationsScript: {
          anyOf: [
            {
              items: {
                type: 'string',
              },
              type: 'array',
            },
            {
              type: 'string',
            },
          ],
          description:
            'Optional script to run after the database\nhas been started but before running tests',
        }

"@databases/mysql-test": "^2.0.0" Node: v12.18.4 NPM: 6.14.6

isaiasmb avatar Sep 27 '20 12:09 isaiasmb

It's working with:

"mysql": {
        "test": {
            "migrationsScript": [
                "npm",
                "run",
                "db:migrate"
            ]
        }
    }

isaiasmb avatar Sep 28 '20 07:09 isaiasmb

This needs updating in the documentation to show using an array. Using an array is much more reliable than using a string would be, so it makes sense to prefer this approach.

ForbesLindesay avatar Feb 15 '22 12:02 ForbesLindesay