typescript-express-starter icon indicating copy to clipboard operation
typescript-express-starter copied to clipboard

how to add a new migration and run migration?

Open reaganscofield opened this issue 3 years ago • 2 comments

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

reaganscofield avatar Feb 15 '22 05:02 reaganscofield

can anyone please respond to this question?

reaganscofield avatar Mar 10 '22 17:03 reaganscofield

Use npx sequelize db:migrate

RA9 avatar Mar 15 '22 21:03 RA9

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.

jbalatero avatar Dec 03 '22 03:12 jbalatero