typescript-express-starter
typescript-express-starter copied to clipboard
how to add a new migration and run migration?
on the users model, the user model has already been created so I want to add a new column to the user model how can I do that?
I am using PostgreSQL as DB.
with a normal sequelize i would create a migration file and then run sequelize db:migrate
to add a column on the existing table but with this set up when I run sequelize db:migrate
it does ask me to run sequelize init
which will create a new configuration
can anyone please respond to this question?
Use npx sequelize db:migrate
here's how I did it
src/config/sequelize-cli.js
const { config } = require('dotenv');
config({ path: `.env.${process.env.NODE_ENV || 'development'}.local` });
const { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } = process.env;
module.exports = {
username: DB_USER,
password: DB_PASSWORD,
database: DB_DATABASE,
port: DB_PORT,
host: DB_HOST,
dialect: 'mysql',
migrationStorageTableName: 'sequelize_migrations',
seederStorageTableName: 'sequelize_seeds',
};
.sequelizerc
const path = require('path');
module.exports = {
'config': path.resolve('src', 'config', 'sequelize-cli.js'),
'models-path': path.resolve('src', 'models'),
'seeders-path': path.resolve('src', 'seeders'),
'migrations-path': path.resolve('src', 'migrations'),
};
Now I can run npx sequelize db:migrate
or any commands without probs.