Skip to content

Pass a model to queryInterface.createTable #521

@Tyron199

Description

@Tyron199

I have a folder with all my model definitions like this:
(Generated by sequelize-auto)

//items.js
  const Sequelize = require('sequelize');
  module.exports = function (sequelize, DataTypes) {
      return sequelize.define('items', {
          id: {
              autoIncrement: true,
              type: DataTypes.INTEGER,
              allowNull: false,
              primaryKey: true
          }
      })
  }

Would it be possible to require that model instance and then pass that to queryInterface.createTable instead of having to copy the definition.

Something like this

//00_init.js
const DataTypes = require("sequelize").DataTypes;
const sequelize = new Sequelize(conf.db.main_db, null, null, {});

const items = require("./items")(sequelize,DataTypes);
asynx function up({context: queryInterface}){
await  await queryInterface.createTable(items)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions