Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current architecture does not generate migration files #34

Closed
pauloladimeji opened this issue Apr 26, 2019 · 5 comments
Closed

current architecture does not generate migration files #34

pauloladimeji opened this issue Apr 26, 2019 · 5 comments

Comments

@pauloladimeji
Copy link

first off, thanks for this boilerplate! helped me in many ways.

using sequelize-cli automatically generates models and migration files. since this boilerplate doesn't make use of sequelize-cli, models and their associations need to be defined manually.

i'm considering integrating sequelize-cli myself, but i don't know how much it will mess with the file dependencies using the current architecture?

are there any plans to upgrade to using sequelize-cli?

@aichbauer
Copy link
Owner

@pauloladimeji Sorry for the late response...

Thank you 😀 I am glad that I could help you...

I never really worked with sequelize-cli... Could you provide some information on how we had to change our current architecture? How would the file system look like? What would be the best way to integrate sequelize-cli in your opinion?

@ace3
Copy link
Contributor

ace3 commented May 24, 2019

hello, i am using this boilerplate with sequelize-cli

i'm just init the sequelize in the project.

then create this file .sequelizerc on root directory

and change the code inside into

`const path = require('path');

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

then the cli working as expected.

notes:
i am using sequelize-cli only for making migration,seeds.

@pauloladimeji
Copy link
Author

Thanks! @aichbauer and @ace3 ... I am also using a setup similar to @ace3's ...

migration and seeds are why I use the cli as well...

@cyberiums
Copy link

Has anyone tried using sequelize-auto-migrations?
I am facing this issue: sequelize/sequelize#7840
The babel or typescript doesn't work for this repo as it is in non build javascript.
Below is my models/index.js

'use strict';

const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'production';
const config = require(__dirname + '/../config/config.json')[env];
const modelpath = __dirname +"/../api/models/"
const db = {};

let sequelize;
if (config.use_env_variable) {
  sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
  sequelize = new Sequelize(config.database, config.username, config.password, config);
}

fs
  .readdirSync(modelpath) //(__dirname)
  .filter(file => {
    return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
  })
  .forEach(file => {
    //let model = sequelize.import(path.join(modelpath,file));   //(__dirname, file));
    let model = require(path.join(modelpath, file));
    db[model.name] = model;
  });

Object.keys(db).forEach(modelName => {
  db[modelName] = sequelize.import(db[modelName]);
  //console.log(modelName, db[modelName].associate)
  if (db[modelName].associate) {
    db[modelName].associate(db);
  }
});

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

The error is


> node ./node_modules/sequelize-auto-migrations/bin/makemigration.js

Not overriding built-in method from model attribute: set
internal/validators.js:125
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type function
    at validateString (internal/validators.js:125:11)
    at Object.normalize (path.js:1112:5)


@Fabiomad85
Copy link

Same error here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants