sequelize-auto-migrations icon indicating copy to clipboard operation
sequelize-auto-migrations copied to clipboard

db:makemigrations not working

Open osvaldokalvaitir opened this issue 3 years ago • 6 comments

I read a tutorial on how to use, installing:

npm install --save github:scimonster/sequelize-auto-migrations#a063aa6535a3f580623581bf866cef2d609531ba

Edit package.json "scripts": { ... "db:makemigrations": "./node_modules/sequelize-auto-migrations/bin/makemigration.js", }

After: npm run db:makemigrations

But when running, nothing happens, just open the file 'makemigration.js'.

I have a .sequelizerc file:

const { resolve } = require('path');

module.exports = { config: resolve(__dirname, 'src', 'config', 'database.js'), 'models-path': resolve(__dirname, 'src', 'app', 'models'), 'migrations-path': resolve(__dirname, 'src', 'database', 'migrations'), 'seeders-path': resolve(__dirname, 'src', 'database', 'seeds'), };

Could that be it? if anyone can help me, i will be very grateful.

osvaldokalvaitir avatar Aug 10 '20 14:08 osvaldokalvaitir

Make sure you are running the file, not just opening it from the terminal.

Try node ./node_modules/sequelize-auto-migrations/bin/makemigration.js in your package.json instead so it is being run.

ericbenedetto16 avatar Aug 10 '20 15:08 ericbenedetto16

Eric! you're right, I forgot to put node, I remember that I had done a test here, but this error occurred:

image

It looks like he can't find my folder, or can't find the models! But there are 4 in the folder.

osvaldokalvaitir avatar Aug 10 '20 17:08 osvaldokalvaitir

Do you have an index.js file in the models directory that imports all of the models? (if you ran sequelize init there should be one for you)

ericbenedetto16 avatar Aug 10 '20 17:08 ericbenedetto16

Eric, yes, I have!

image

I had no index in the model folder. Delete my 'database' file and it generated both.

Thank you very much, Eric !! Everything worked.

I know it has nothing to do with this issue, but he didn't accept the 'imports' I have on the models, is this library supported?

osvaldokalvaitir avatar Aug 10 '20 18:08 osvaldokalvaitir

Seems like a dead repo, but what I did earlier since my imports weren't working was I forked the repo and made it so I can pass my connection in the CLI. Check it out Here

How I used it was when I instantiate and export my db connection:

config/db.js

const Sequelize = require('sequelize');

module.exports = new Sequelize(
    process.env.DB_DATABASE,
    process.env.DB_USER,
    process.env.DB_PASS,
    {
        host: process.env.DB_HOST,
        dialect: 'mysql',
        operatorAliases: false,

        define: {
            timestamps: false,
        },

        pool: {
            max: 5,
            min: 0,
            acquire: 30000,
            idle: 10000,
        },
    }
);

Then in my models directory I left index.js completely empty.

Lastly, in the command inside your package.json you can use "db:makemigrations": "node ./node_modules/sequelize-auto-migrations/bin/makemigration.js --conn ./config/db.js"

Let me know if this helps!

ericbenedetto16 avatar Aug 10 '20 19:08 ericbenedetto16

I have the 'database' file similar to yours, but in the 'index' I commented out the 'env' code.

image

Is working if my models are passed like this: image

but if I do it like this:

import { Models } from 'sequelize';

doesn't work, so I think the package doesn't support ESM.

osvaldokalvaitir avatar Aug 10 '20 22:08 osvaldokalvaitir