Skip to content

Instantly share code, notes, and snippets.

@andrewmunro
Created July 17, 2017 11:30
Show Gist options
  • Save andrewmunro/030f0bf62453239c495b0347c8cd1247 to your computer and use it in GitHub Desktop.
Save andrewmunro/030f0bf62453239c495b0347c8cd1247 to your computer and use it in GitHub Desktop.
Sequelize cli with ES6
{
"presets": ["es2015"],
"plugins": [
"add-module-exports"
],
}
const path = require('path');
module.exports = {
'config': path.resolve('migrations/config/babelHook.js'),
'migrations-path': path.resolve('migrations'),
'seeders-path': path.resolve('migrations/seeders'),
'models-path': path.resolve('migrations/models')
};
// migrations/config/babelHook.js
require('babel-core/register');
module.exports = require('./config');
// migrations/config/config.js
import config from 'my/app/config';
const env = process.env.NODE_ENV || 'development';
export default {
[env]: {
url: config.mysql.migrate,
dialect: 'mysql',
migrationStorageTableName: 'SequelizeMeta'
}
};

npm run sequelize db:migrate:all

// migrations/models/model.js
import sequelize from 'sequelize';
const model = sequelize.define('foo', {
createdAt: {
type: this.sequelize.DATE,
allowNull: false,
},
updatedAt: {
type: this.sequelize.DATE,
allowNull: true,
},
});
export default model;
{
"name": "seqelize-with-es6",
"description": "Example of sequelize cli running with es6 models",
"version": "0.0.1",
"main": "index.js",
"contributors": [],
"scripts": {
"sequelize": "sequelize $*"
},
"dependencies": {
"sequelize": "^3.30.4"
},
"devDependencies": {
"babel-core": "^6.24.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-es2015": "^6.24.0",
"sequelize-cli": "^2.7.0"
}
}
@YavorK
Copy link

YavorK commented Dec 18, 2019

EcmaScript in migrations worked for me only with this file (and installing the packages in it)
https://gist.github.com/YavorK/816041feed5113986cfeb8fc304eb5df

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment