Cli: Change models and migrations folder

Created on 23 Aug 2014  ·  18Comments  ·  Source: sequelize/cli

Is there a way to change it?

Most helpful comment

It should be possible to declare the path to a json file and to specify the path to it via

sequelize --options-path=path/options.json

in this file you can define the options you want to enable all the time. so something like

{
  "migrations-path": "path/to/migrations"
}

All 18 comments

yes:

from the implementation:

      "--migrations-path": "The path to the migrations folder. " + clc.blueBright("Default: migrations"),
      "--models-path": "The path to the models folder." + clc.blueBright("Default: models")

so you just have to add those flags.

Is there a way to create a .sequelizerc to define where is the options path, models, path and migrations path? I think it is a good enhacement

That should be possible as well. gimme a second

Just to explain: I have two persons using the project and it will be a pain in the ass to set those paths every command I run.

Thanks!

It should be possible to declare the path to a json file and to specify the path to it via

sequelize --options-path=path/options.json

in this file you can define the options you want to enable all the time. so something like

{
  "migrations-path": "path/to/migrations"
}

There is no default file that gets checked though. Feel free to provide a PR for that! The code in question is this: https://github.com/sequelize/cli/blob/master/bin/sequelize#L27-41

I'll check it out. Thanks!

you are welcome!

Was looking for this ! Good ! Maybe should be in the doc nope ? :)

A first start would be an improved README.md. Want to provide a PR?

I'm still in the learning curve of sequelize, I don't feel confortable enough now for that, but, by time running, I'm improving a memo so when it becomes strong enough I can give it a try, will keep you up to date :)

This is still very much desirable. Any news on being able to provide a default set of options?

Looking for a solution here too.

I have to use --options-path=path/options.json in any command that I try? I can't set it as default or something like that?

@caioflores now you can have a .sequelizerc file at the root :

var path = require('path')

module.exports = {
  'config': path.resolve('path', 'options.json'),
}

That's great !

Migration path won't work when we provide migrations-path key in configuration file:

When i run migration i get the following message, Keep in mind that i have provided "migrations-path" to a different path (See complete database.json at the end of this comment)

./node_modules/sequelize-cli/bin/sequelize  migration:create

Sequelize [Node: 8.3.0, CLI: 2.8.0, ORM: 4.4.10]

Successfully created migrations folder at "/Users/XAM/liimex/koajsapp/migrations".
Loaded configuration file "config/database.json".
Using environment "development".
New migration was created at /Users/XAM/liimex/koajsapp/migrations/20170814152035-unnamed-migration.js .

So the following property in config/database.json is ignored.

...
 "migrations-path": "./database/migrations"
...

However, It does work via cli argument, as shown below:

./node_modules/sequelize-cli/bin/sequelize --migrations-path ./database/migrations migration:create

Sequelize [Node: 8.3.0, CLI: 2.8.0, ORM: 4.4.10]

Successfully created migrations folder at "/Users/XAM/liimex/koajsapp/database/migrations".
Loaded configuration file "config/database.json".
Using environment "development".
New migration was created at /Users/XAM/liimex/koajsapp/database/migrations/20170814151846-unnamed-migration.js .

My .sequelizerc file is

const path = require('path')

module.exports = {
  'config': path.join('config', 'database.json'),
}

And My config/database.json file is

{
  "development": {
    "dialect": "sqlite",
    "storage": "database/db.sqlite",
    "migrations-path": "./database/migrations"
  },
  "production": {
    "dialect": "sqlite",
    "storage": "database/production-db.sqlite",
    "migrations-path": "./database/migrations"
  }
}

(Change models and migrations folder):

What I did is 👍

package.json

  "devDependencies": {
    "sequelize-cli": "^4.1.1",
  },

  "scripts": {
    "sequelize": "sequelize --options-path=database/options.js",
  },


database/option.js

const path = require('path');
module.exports =  {

  config: path.join(__dirname, 'config.json'),
  'migrations-path': path.join(__dirname, 'migrations'),
  'seeders-path': path.join(__dirname, 'seeders'),
  'models-path': path.join(__dirname, 'model'),
}


npm run sequelize init:migrations 

then the migrations folder will created in database folder.

mind:

--options-path=database/options.js
this is important。

more info https://www.jianshu.com/p/93b19699659a

yes:

from the implementation:

      "--migrations-path": "The path to the migrations folder. " + clc.blueBright("Default: migrations"),
      "--models-path": "The path to the models folder." + clc.blueBright("Default: models")

so you just have to add those flags.

@sdepold where are all these options listed? I can't seem to find them on the sequelize github..

Was this page helpful?
0 / 5 - 0 ratings