Arnas Pecelis
Arnas Pecelis

Reputation: 149

sequelize migrations after models were created

I'm searching for method to create migrations and create database from models that was already on app since pull from github. I'm using AWS so I need to run migrations build command on app build and connect it with AWS RDS. What I did so far - created .sequelizerc with the following contents

const path = require('path');

module.exports = {
  'config': path.resolve('lib', './app.database.js'),
  'models-path': path.resolve('lib', './models'),
  'seeders-path': path.resolve('lib', './seeders'),
  'migrations-path': path.resolve('lib', './migrations')
}

and have all models stored in /lib/models/ folder with the following structure for example

module.exports = (sequelize, DataTypes) => {
const Init = sequelize.define('Init', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
    },
    name: DataTypes.STRING,
    version: DataTypes.STRING,
}, {
    tableName: 'oc_init',
    timestamps: false
});

return Init;
};

need to mention that some of the models already has prototypes itself with additional libraries in use, such a bcrypt etc.

So after app build I'm trying to run node_modules/.bin/sequelize db:migrate and the following error appears

No migrations were executed, database schema was already up to date.

but as I check the remote database (amazon RDS) I can only see SequelizeMeta table created. What I'm doing wrong? How to create migrations on my local machine so I could migrate data on AWS?

Upvotes: 2

Views: 1558

Answers (1)

Arnas Pecelis
Arnas Pecelis

Reputation: 149

The solution was to create migrations for each model by myself describing its contents and run sequelize db:migrate. It appears there are no methods to create migration files from already created models.

Upvotes: 2

Related Questions