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

Sequelize CLI in 2021 #941

Closed
papb opened this issue Apr 5, 2021 · 11 comments
Closed

Sequelize CLI in 2021 #941

papb opened this issue Apr 5, 2021 · 11 comments

Comments

@papb
Copy link
Member

papb commented Apr 5, 2021

Hello everyone!

I will be doing a large overhaul of the Sequelize CLI this month. Stay tuned!

@papb papb pinned this issue Apr 5, 2021
@StanislavTemchenko
Copy link

StanislavTemchenko commented Apr 7, 2021

Please, add typescript support of migrations and seeds

@nassimerrahoui
Copy link

nassimerrahoui commented Apr 19, 2021

Hello,

I don't know if i'm in the right place to post this question, sorry if it's not.

I use Sequelize Migrations to handle database versioning and migrations are managed by SequelizeMeta table.
This table only contains the filename of migration files that have been applied.

At this moment, is it possible to add more information to SequelizeMeta table like a description of migrations changes (createTable, addConstraint, addColumn, ...) ?

The idea behind this is to have more information like databasechangelog table from liquibase.

@ThomasBerne
Copy link

Typescript implementation would be awesome!

@kunwar97
Copy link

kunwar97 commented May 11, 2021

You can currently use typescript in migrations & seeders. But you need to first compile it to javascript. Here is the example

import { QueryInterface, SequelizeStatic } from "sequelize";
import { Helpers } from "../util/helpers.util";
import { DischargePointType } from "../enums/discharge-point-type.enum";

export = {
  up  : (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
    return queryInterface.createTable("states", {
      id                                : {
        allowNull    : false,
        autoIncrement: true,
        primaryKey   : true,
        type         : Sequelize.BIGINT
      },
      title                             : {
        type     : Sequelize.STRING,
        allowNull: false,
      },
      state_code                        : {
        type     : Sequelize.STRING,
        allowNull: false,
      },
      discharge_point_type              : {
        type        : Sequelize.ENUM,
        allowNull   : false,
        values      : Helpers.iterateEnum(DischargePointType),
        defaultValue: DischargePointType.SIMPLE
      },
      createdAt                         : {
        allowNull: true,
        type     : Sequelize.DATE
      },
      updatedAt                         : {
        allowNull: true,
        type     : Sequelize.DATE,
      },
      deletedAt                         : {
        allowNull: true,
        type     : Sequelize.DATE
      }
    });
  },
  down: (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
    return queryInterface.dropTable("states");
  }
};

Need to change migrations & seeders path in .sequelizerc to point to dist folder

var path = require('path')

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

So before running migration first you need to run npm run build or tsc, whatever your configuration is to build the code.

But yes native support will be the best solution.

@andrejleitner
Copy link

Is this happening? It would be nice to solve this one: #915 (comment)

@pirumu
Copy link

pirumu commented Oct 4, 2021

I'm still waiting

@1valdis
Copy link

1valdis commented Dec 12, 2021

It's almost 2022. How's the overhaul going?

@WikiRik WikiRik unpinned this issue Dec 13, 2021
@WikiRik
Copy link
Member

WikiRik commented Dec 13, 2021

Unfortunately @papb did not have the time anymore for the overhaul. Therefore I will close this issue

@WikiRik WikiRik closed this as completed Dec 13, 2021
@AnthonyLzq
Copy link

You can currently use typescript in migrations & seeders. But you need to first compile it to javascript. Here is the example

import { QueryInterface, SequelizeStatic } from "sequelize";
import { Helpers } from "../util/helpers.util";
import { DischargePointType } from "../enums/discharge-point-type.enum";

export = {
  up  : (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
    return queryInterface.createTable("states", {
      id                                : {
        allowNull    : false,
        autoIncrement: true,
        primaryKey   : true,
        type         : Sequelize.BIGINT
      },
      title                             : {
        type     : Sequelize.STRING,
        allowNull: false,
      },
      state_code                        : {
        type     : Sequelize.STRING,
        allowNull: false,
      },
      discharge_point_type              : {
        type        : Sequelize.ENUM,
        allowNull   : false,
        values      : Helpers.iterateEnum(DischargePointType),
        defaultValue: DischargePointType.SIMPLE
      },
      createdAt                         : {
        allowNull: true,
        type     : Sequelize.DATE
      },
      updatedAt                         : {
        allowNull: true,
        type     : Sequelize.DATE,
      },
      deletedAt                         : {
        allowNull: true,
        type     : Sequelize.DATE
      }
    });
  },
  down: (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
    return queryInterface.dropTable("states");
  }
};

Need to change migrations & seeders path in .sequelizerc to point to dist folder

var path = require('path')

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

So before running migration first you need to run npm run build or tsc, whatever your configuration is to build the code.

But yes native support will be the best solution.

Sir, how did you generate your migrations in TS?

@kunwar97
Copy link

@AnthonyLzq The sequelize-cli migration generate command creates migration in javascript, so you can't use that.

You can either create it manually or you can write a custom script to generate typescript migration.

@slidenerd
Copy link

You can currently use typescript in migrations & seeders. But you need to first compile it to javascript. Here is the example

import { QueryInterface, SequelizeStatic } from "sequelize";
import { Helpers } from "../util/helpers.util";
import { DischargePointType } from "../enums/discharge-point-type.enum";

export = {
  up  : (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
    return queryInterface.createTable("states", {
      id                                : {
        allowNull    : false,
        autoIncrement: true,
        primaryKey   : true,
        type         : Sequelize.BIGINT
      },
      title                             : {
        type     : Sequelize.STRING,
        allowNull: false,
      },
      state_code                        : {
        type     : Sequelize.STRING,
        allowNull: false,
      },
      discharge_point_type              : {
        type        : Sequelize.ENUM,
        allowNull   : false,
        values      : Helpers.iterateEnum(DischargePointType),
        defaultValue: DischargePointType.SIMPLE
      },
      createdAt                         : {
        allowNull: true,
        type     : Sequelize.DATE
      },
      updatedAt                         : {
        allowNull: true,
        type     : Sequelize.DATE,
      },
      deletedAt                         : {
        allowNull: true,
        type     : Sequelize.DATE
      }
    });
  },
  down: (queryInterface: QueryInterface, Sequelize: SequelizeStatic) => {
    return queryInterface.dropTable("states");
  }
};

Need to change migrations & seeders path in .sequelizerc to point to dist folder

var path = require('path')

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

So before running migration first you need to run npm run build or tsc, whatever your configuration is to build the code.

But yes native support will be the best solution.

For some reason this does not read dot env variables from transpiled js

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