sequelize-cli-typescript icon indicating copy to clipboard operation
sequelize-cli-typescript copied to clipboard

.sequelizerc migrations-path does not work

Open daniq87 opened this issue 7 years ago • 5 comments

What you are doing?

node_modules/.bin/sequelize model:generate --name User --attributes username:string

My .sequelizesrc file looks like: module.exports = { 'config': "config/local-development.json", 'options-path': "src/build/ports/database/migrations", 'models-path': "src/models" }

What do you expect to happen?

I wanted to generate the migration in the source specified in the options-path in my .sequelizesrc file. But its generate the migration in my-project/migrations

What is actually happening?

It generates the model in the correct path but the migration in the wrong place. New model was created at /Users/dquintana/dev/buzz-microservices/channel-ota/src/models/user.ts . New migration was created at /Users/dquintana/dev/buzz-microservices/channel-ota/migrations/20180210094213-User.ts

I've tried put in the .sequelizesrc: migrations-path instead of options-path but I get an error: Unknown argument: migrations-path

Dialect: mysql / __Sequelize CLI version: 3.2.0-c __Sequelize version: 4.31.2

daniq87 avatar Feb 10 '18 09:02 daniq87

I have the same issue too. any fix for this bro? @daniq87

const path = require('path');

module.exports = {
  'config': path.resolve('config', 'config.js'),
  'models-path': path.resolve('src', 'models'),
  'seeders-path': path.resolve('db', 'seeders'),
  'migrations-path': path.resolve('db', 'migrations')
}

artoodeeto avatar Nov 24 '19 01:11 artoodeeto

@artoodeeto @daniq87 from the docs you can see that

It's usually the case that the compiled JavaScript code will be put in a different directory than the source TypeScript code, so whereas sequelize-cli had one migrations-path setting, sequelize-cli-typescript has two: migrations-source-path and migrations-compiled-path, which default to /migrations and /migrations/compiled respectively.

That means your config needs to have migrations-compiled-path and migrations-source-path fields, and not migrations-path

brunocangs avatar Feb 14 '20 13:02 brunocangs

@artoodeeto @daniq87 from the docs you can see that

It's usually the case that the compiled JavaScript code will be put in a different directory than the source TypeScript code, so whereas sequelize-cli had one migrations-path setting, sequelize-cli-typescript has two: migrations-source-path and migrations-compiled-path, which default to /migrations and /migrations/compiled respectively.

That means your config needs to have migrations-compiled-path and migrations-source-path fields, and not migrations-path

Anyways that not works :( Same problem.

Any news about?

diegoulloao avatar Feb 15 '20 19:02 diegoulloao

@diegoulloao There are two ways to fix this

  1. follow the comment here https://github.com/douglas-treadwell/sequelize-cli-typescript/issues/1#issuecomment-476101550 that worked for me. It creates migration in correct location.

  2. Not an ideal solution but it works, Make sure your config object in .rc file should be similar to below:

const path = require('path');
const sequelizeCliConfig = {
  config: dbConfig,
  'models-path': path.resolve('src', 'infrastructure', 'database', 'models'),
  'migrations-source-path': path.resolve('src', 'infrastructure', 'database', 'migrations'),
  'migrations-compiled-path': path.resolve('dist', 'infrastructure', 'database', 'migrations'), 
  'seeders-source-path': path.resolve('src', 'infrastructure', 'database', 'seeders'),
  'seeders-compiled-path': path.resolve('dist', 'infrastructure', 'database', 'seeders'),
};

'migrations-compiled-path': option must be provided, it does not matter where you store the compile files but it should be part of config object. That was the only way the CLI was working without errors. Also when running CLI commands if you see pattern don't match warnings for .map files you can configure your tsconfig.json to not output .map files just for migration folder or you can just delete the .map files from migration folder before running migration command.

So migrate command in package.json will pretty much look like below

"migrate": "rm -rf dist/seeders/*.js.map && rm -rf dist/migrations/*.js.map && sequelize db:migrate",

akpankit avatar Mar 05 '20 16:03 akpankit

@akpankit I am pretty sure there are something missing during a configuration. I have followed the same way. But in the documentation not a single place I have found that how do I create a new migration with this configuration. When I tried to create a new migration it throws below error.

Unknown arguments: migrations-source-path, migrationsSourcePath, migrations-compiled-path, migrationsCompiledPath, seeders-source-path, seedersSourcePath, seeders-compiled-path, seedersCompiledPath

Following is my configuration of .sequezelirc

const path = require('path');

module.exports = {
  config: path.resolve("dist", "config", "db.config.js"),
  "models-path": path.resolve("src", "orm", "models"),
  'migrations-source-path': path.resolve('src', 'orm', 'migrations'),
  'migrations-compiled-path': path.resolve('dist', 'orm', 'migrations'), 
  'seeders-source-path': path.resolve('src', 'orm', 'seeders'),
  'seeders-compiled-path': path.resolve('dist', 'orm', 'seeders'),
};

What is wrong with that. I am running following command.

sequelize migration:generate --name=sys-user

dipakchavda2912 avatar Aug 28 '22 18:08 dipakchavda2912