douglas-treadwell / sequelize-cli-typescript

The Sequelize CLI
MIT License
48 stars 21 forks source link

.sequelizerc migrations-path does not work #3

Open daniq87 opened 6 years ago

daniq87 commented 6 years ago

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

artoodeeto commented 4 years ago

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')
}
brunocangs commented 4 years ago

@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

diegoulloao commented 4 years ago

@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?

akpankit commented 4 years ago

@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",
dipakchavda2912 commented 2 years ago

@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