npm run sequelize db:migrate:all
Created
July 17, 2017 11:30
-
-
Save andrewmunro/030f0bf62453239c495b0347c8cd1247 to your computer and use it in GitHub Desktop.
Sequelize cli with ES6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"presets": ["es2015"], | |
"plugins": [ | |
"add-module-exports" | |
], | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// migrations/config/babelHook.js | |
require('babel-core/register'); | |
module.exports = require('./config'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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' | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
Experiencing the same issue after requiring @babe/core in my package.json
Here's the error output:
Loaded configuration file "server/config/babelHook.js".
Using environment "development".
sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators node_modules/sequelize/lib/sequelize.js:242:13
== 20190218092918-create-menu: migrating =======
ERROR: Unexpected token export
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] sequelize: `sequelize $* "db:migrate"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] sequelize script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/techcellent/.npm/_logs/2019-02-18T13_50_12_190Z-debug.log
and here's my package.json file:
"name": ".....",
"version": "1.0.0",
"description": "....",
"main": "index.js",
"sequelize": {
"require": [
"@babel/register"
]
},
"scripts": {
"start": "nodemon --exec babel-node index.js",
"test": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-lcov ./node_modules/.bin/mocha --exit --timeout 10000 --reporter spec --compilers js:@babel/register ./test/*.js",
"coveralls": "nyc npm test && nyc report --reporter=text-lcov | coveralls",
"sequelize": "sequelize $*"
},
.......
No example of a migration
Needs Typescript definitions
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
this doesn't actually work for me with
import
andexport
statements. i'm trying the following:./node_modules/.bin/sequelize
via./node_modules/.bin/babel-node
relevant npm run commands:
my sequelize config:
the tests:
once the first import or export statements gets processed they all fail with something like the above.