GithubHelp home page GithubHelp logo

sequelize / cli Goto Github PK

View Code? Open in Web Editor NEW
2.5K 39.0 528.0 2.36 MB

The Sequelize CLI

License: MIT License

JavaScript 99.75% TypeScript 0.18% Shell 0.07%
sequelize javascript migrations seeders cli hacktoberfest

cli's Introduction

sequelize/cli npm version CI

The Sequelize Command Line Interface (CLI)

Table of Contents

Installation

Make sure you have Sequelize installed. Then install the Sequelize CLI to be used in your project with

npm install --save-dev sequelize-cli

And then you should be able to run the CLI with

npx sequelize --help

Usage

Sequelize CLI [Node: 10.21.0, CLI: 6.0.0, ORM: 6.1.0]

sequelize <command>

Commands:
  sequelize db:migrate                        Run pending migrations
  sequelize db:migrate:schema:timestamps:add  Update migration table to have timestamps
  sequelize db:migrate:status                 List the status of all migrations
  sequelize db:migrate:undo                   Reverts a migration
  sequelize db:migrate:undo:all               Revert all migrations ran
  sequelize db:seed                           Run specified seeder
  sequelize db:seed:undo                      Deletes data from the database
  sequelize db:seed:all                       Run every seeder
  sequelize db:seed:undo:all                  Deletes data from the database
  sequelize db:create                         Create database specified by configuration
  sequelize db:drop                           Drop database specified by configuration
  sequelize init                              Initializes project
  sequelize init:config                       Initializes configuration
  sequelize init:migrations                   Initializes migrations
  sequelize init:models                       Initializes models
  sequelize init:seeders                      Initializes seeders
  sequelize migration:generate                Generates a new migration file      [aliases: migration:create]
  sequelize model:generate                    Generates a model and its migration [aliases: model:create]
  sequelize seed:generate                     Generates a new seed file           [aliases: seed:create]

Options:
  --version  Show version number                                                  [boolean]
  --help     Show help                                                            [boolean]

Please specify a command

Contributing

All contributions are accepted as a PR.

  • You can file issues by submitting a PR (with test) as a test case.
  • Implement new feature by submitting a PR
  • Improve documentation by submitting PR to Sequelize

Please read the contributing guidelines.

Documentation

cli's People

Contributors

a60814billy avatar alubbe avatar americas avatar cogpie avatar dependabot[bot] avatar dpickett avatar ephys avatar etroynov avatar fossamagna avatar greenkeeper[bot] avatar greenkeeperio-bot avatar grillorafael avatar janmeier avatar johanneswuerbach avatar karlhorky avatar mattrunyon avatar mkly avatar papb avatar pavelpolyakov avatar projjol avatar ray0427 avatar remarkablemark avatar renovate[bot] avatar rochet2 avatar rutaihwa avatar salomao-rodrigues avatar sdepold avatar sushantdhiman avatar wikirik avatar zvizvi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cli's Issues

config file in production

Hi
I'm wondering how can I run migrations on a production environment without using the config.json file. I don't want to write my credentials there in plain text.

Thanks
Marcos

Using sequelize-cli with Heroku

I recently upgraded my sequelize from 2.0.0-dev11 to 2.0.0-dev12 and, as part of that, I added in sequelize-cli. Everything is working locally fine, but when I tried to replicate that on Heroku, I ran into issues running when trying to migrate:

Running `node_modules/.bin/sequelize db:migrate -env staging` attached to terminal... up, run.5140
Sequelize [CLI: v0.2.4, ORM: v2.0.0-dev12]
[03:39:53] CLI version 3.6.2
[03:39:53] Local version 3.6.2

I assume I am missing some new or modified configuration I need to do for Heroku, but am at loss for what it might be. Any suggestions?

Unable to install sequelize-cli

When trying to install sequlize-cli i get an error

sudo npm install --start sequelize-cli
npm ERR! error rolling back Error: Refusing to delete: /Users/lwilliams/Sites/api/node_modules/.bin/sequelize not in /Users/lwilliams/Sites/api/node_modules/sequelize-cli

Debug log as follows

0 info it worked if it ends with ok
1 verbose cli [ 'node',
1 verbose cli '/usr/local/bin/npm',
1 verbose cli 'install',
1 verbose cli '--start',
1 verbose cli 'sequelize-cli' ]
2 info using [email protected]
3 info using [email protected]
4 verbose readDependencies using package.json deps
5 verbose cache add [ 'sequelize-cli', null ]
6 verbose cache add name=undefined spec="sequelize-cli" args=["sequelize-cli",null]
7 verbose parsed url { protocol: null,
7 verbose parsed url slashes: null,
7 verbose parsed url auth: null,
7 verbose parsed url host: null,
7 verbose parsed url port: null,
7 verbose parsed url hostname: null,
7 verbose parsed url hash: null,
7 verbose parsed url search: null,
7 verbose parsed url query: null,
7 verbose parsed url pathname: 'sequelize-cli',
7 verbose parsed url path: 'sequelize-cli',
7 verbose parsed url href: 'sequelize-cli' }
8 silly lockFile bb1125fd-sequelize-cli sequelize-cli
9 verbose lock sequelize-cli /Users/lwilliams/.npm/bb1125fd-sequelize-cli.lock
10 silly lockFile bb1125fd-sequelize-cli sequelize-cli
11 silly lockFile bb1125fd-sequelize-cli sequelize-cli
12 verbose addNamed [ 'sequelize-cli', '' ]
13 verbose addNamed [ null, '' ]
14 silly lockFile f819e9f1-sequelize-cli sequelize-cli@
15 verbose lock sequelize-cli@ /Users/lwilliams/.npm/f819e9f1-sequelize-cli.lock
16 silly addNameRange { name: 'sequelize-cli', range: '
', hasData: false }
17 verbose url raw sequelize-cli
18 verbose url resolving [ 'https://registry.npmjs.org/', './sequelize-cli' ]
19 verbose url resolved https://registry.npmjs.org/sequelize-cli
20 info trying registry request attempt 1 at 10:24:31
21 verbose etag "9YKBSHMBSK3598SO9EF5FBM2C"
22 http GET https://registry.npmjs.org/sequelize-cli
23 http 304 https://registry.npmjs.org/sequelize-cli
24 silly registry.get cb [ 304,
24 silly registry.get { date: 'Wed, 09 Jul 2014 17:24:33 GMT',
24 silly registry.get server: 'Apache',
24 silly registry.get via: '1.1 varnish',
24 silly registry.get 'last-modified': 'Wed, 09 Jul 2014 17:24:33 GMT',
24 silly registry.get 'cache-control': 'max-age=30',
24 silly registry.get etag: '"9YKBSHMBSK3598SO9EF5FBM2C"',
24 silly registry.get 'x-served-by': 'cache-lax1435-LAX',
24 silly registry.get 'x-cache': 'MISS',
24 silly registry.get 'x-cache-hits': '0',
24 silly registry.get 'x-timer': 'S1404926673.498962,VS0,VE71',
24 silly registry.get vary: 'Accept',
24 silly registry.get 'content-length': '0',
24 silly registry.get 'keep-alive': 'timeout=10, max=50',
24 silly registry.get connection: 'Keep-Alive' } ]
25 verbose etag sequelize-cli from cache
26 silly addNameRange number 2 { name: 'sequelize-cli', range: '', hasData: true }
27 silly addNameRange versions [ 'sequelize-cli',
27 silly addNameRange [ '0.0.1',
27 silly addNameRange '0.0.2',
27 silly addNameRange '0.0.3',
27 silly addNameRange '0.0.4',
27 silly addNameRange '0.1.0',
27 silly addNameRange '0.1.1',
27 silly addNameRange '0.2.0',
27 silly addNameRange '0.2.1',
27 silly addNameRange '0.2.2' ] ]
28 verbose addNamed [ 'sequelize-cli', '0.2.2' ]
29 verbose addNamed [ '0.2.2', '0.2.2' ]
30 silly lockFile c726734f-sequelize-cli-0-2-2 [email protected]
31 verbose lock [email protected] /Users/lwilliams/.npm/c726734f-sequelize-cli-0-2-2.lock
32 silly lockFile c726734f-sequelize-cli-0-2-2 [email protected]
33 silly lockFile c726734f-sequelize-cli-0-2-2 [email protected]
34 silly lockFile f819e9f1-sequelize-cli sequelize-cli@
35 silly lockFile f819e9f1-sequelize-cli sequelize-cli@
36 silly resolved [ { name: 'sequelize-cli',
36 silly resolved version: '0.2.2',
36 silly resolved description: 'The sequelize CLI.',
36 silly resolved main: 'index.js',
36 silly resolved dependencies:
36 silly resolved { 'cli-color': '~0.3.2',
36 silly resolved 'fs-extra': '^0.9.1',
36 silly resolved gulp: '~3.6.2',
36 silly resolved 'gulp-help': '~0.1.6',
36 silly resolved lodash: '~2.4.1',
36 silly resolved moment: '~2.6.0',
36 silly resolved sequelize: '
',
36 silly resolved 'underscore.string': '^2.3.3',
36 silly resolved yargs: '~1.2.1' },
36 silly resolved devDependencies:
36 silly resolved { 'coffee-script': '~1.7.1',
36 silly resolved 'expect.js': '~0.3.1',
36 silly resolved mariasql: '~0.1.20',
36 silly resolved mocha: '~1.20.1',
36 silly resolved mysql: '~2.1.1',
36 silly resolved pg: '~3.0.3',
36 silly resolved sqlite3: '~2.2.3',
36 silly resolved through2: '^0.5.1' },
36 silly resolved scripts: { test: 'mocha test/*.test.js' },
36 silly resolved repository: { type: 'git', url: 'git://github.com/sequelize/cli.git' },
36 silly resolved keywords: [ 'sequelize', 'cli' ],
36 silly resolved author: { name: 'Sascha Depold' },
36 silly resolved license: 'MIT',
36 silly resolved bugs: { url: 'https://github.com/sequelize/cli/issues' },
36 silly resolved homepage: 'https://github.com/sequelize/cli',
36 silly resolved bin: { sequelize: 'bin/sequelize' },
36 silly resolved _id: '[email protected]',
36 silly resolved _shasum: '27bceb7fc5825e0117f77eefd3e71e018e5d8c15',
36 silly resolved _from: 'sequelize-cli@',
36 silly resolved _npmVersion: '1.4.9',
36 silly resolved _npmUser: { name: 'sdepold', email: '[email protected]' },
36 silly resolved maintainers: [ [Object] ],
36 silly resolved dist:
36 silly resolved { shasum: '27bceb7fc5825e0117f77eefd3e71e018e5d8c15',
36 silly resolved tarball: 'http://registry.npmjs.org/sequelize-cli/-/sequelize-cli-0.2.2.tgz' },
36 silly resolved directories: {},
36 silly resolved _resolved: 'https://registry.npmjs.org/sequelize-cli/-/sequelize-cli-0.2.2.tgz',
36 silly resolved readme: 'ERROR: No README data found!' } ]
37 info install [email protected] into /Users/lwilliams/Sites/api
38 info installOne [email protected]
39 info /Users/lwilliams/Sites/api/node_modules/sequelize-cli unbuild
40 info preuninstall [email protected]
41 info uninstall [email protected]
42 verbose true,/Users/lwilliams/Sites/api/node_modules,/Users/lwilliams/Sites/api/node_modules unbuild [email protected]
43 verbose /Users/lwilliams/Sites/api/node_modules/.bin,[object Object] binRoot
44 info /Users/lwilliams/Sites/api/node_modules/sequelize-cli unbuild
45 info preuninstall [email protected]
46 info uninstall [email protected]
47 verbose true,/Users/lwilliams/Sites/api/node_modules,/Users/lwilliams/Sites/api/node_modules unbuild [email protected]
48 verbose /Users/lwilliams/Sites/api/node_modules/.bin,[object Object] binRoot
49 error error rolling back Error: Refusing to delete: /Users/lwilliams/Sites/api/node_modules/.bin/sequelize not in /Users/lwilliams/Sites/api/node_modules/sequelize-cli
49 error error rolling back at clobberFail (/usr/local/lib/node_modules/npm/lib/utils/gently-rm.js:57:12)
49 error error rolling back at next (/usr/local/lib/node_modules/npm/lib/utils/gently-rm.js:43:14)
49 error error rolling back at /usr/local/lib/node_modules/npm/lib/utils/gently-rm.js:52:12
49 error error rolling back at Object.oncomplete (fs.js:107:15)
49 error error rolling back [email protected] { [Error: Refusing to delete: /Users/lwilliams/Sites/api/node_modules/.bin/sequelize not in /Users/lwilliams/Sites/api/node_modules/sequelize-cli]
49 error error rolling back code: 'EEXIST',
49 error error rolling back path: '/Users/lwilliams/Sites/api/node_modules/.bin/sequelize' }
50 error Refusing to delete: /Users/lwilliams/Sites/api/node_modules/.bin/sequelize not in /Users/lwilliams/Sites/api/node_modules/sequelize-cli
File exists: /Users/lwilliams/Sites/api/node_modules/.bin/sequelize
Move it away, and try again.
51 error System Darwin 10.8.0
52 error command "node" "/usr/local/bin/npm" "install" "--start" "sequelize-cli"
53 error cwd /Users/lwilliams/Sites/api
54 error node -v v0.10.29
55 error npm -v 1.4.14
56 error path /Users/lwilliams/Sites/api/node_modules/.bin/sequelize
57 error code EEXIST
58 verbose exit [ 1, true ]

use_env_variable rejects valid postgres urls

The url parsing around lib/tasks/db.js:33 rejects urls has a couple of problems:

  1. it rejects some valid urls, for example urls without username/password
  2. it fails with a strange message when a URL is rejected:
[10:03:30] Starting 'db:migrate'...
[10:03:30] 'db:migrate' errored after 483 ฮผs Cannot read property '6' of null

It seems like it might be better to use the node built-in url module instead of a regular expression for parsing.

What does Sequelize-cli expect of me to get in classMethods.associate()?

Hi, guys, thank you for awesome tool! The docs are quite poor now, so hope you'll clarify me generated model structure. I've generated new user model:

module.exports = function(sequelize, DataTypes) {
    var User = sequelize.define("User", {
        username: DataTypes.STRING,
        hash: DataTypes.STRING(1024),
        salt: DataTypes.STRING(64)
    }, {
        classMethods: {
            associate: function(models) {
                // associations can be defined here
            }
        }
    });

What does Sequelize-cli expect of me to get in classMethods.associate()? Should I define my associations here like:

associate: function(models) {
    User
        .hasOne(models.Book,{
            as : "FavouriteBook"
        })
    User
        .hasMany(models.Book,{
            as : "BooksIReadNow"
        })
    ...
}

Or is it for custom association methods? A brief example is highly appreciated.

Thank you!

Config via environment variables?

It seems, the only way to set db connection parameters is to specify config.json file. But, in some cases you don't need to handle environment in app yourself. So, I'm interested is there any way to set connection parameters explicitly via environment variables. Something like that:

.sequelizerc:

var path = require('path')
module.exports = {
  'config': {
    host: process.env.DB0_HOST,
    port: process.env.DB0_PORT,
    database: process.env.DB0_NAME,
    username: process.env.DB0_USERNAME,
    password: process.env.DB0_PASSWORD,
    dialect: "postgres"
  },
  'migrations-path': path.resolve('coffee/server', 'migrations'),
  'models-path': path.resolve('coffee/server', 'models'),
  'coffee': true
}

Thanks :)

no tasks were found [win 8.1 64]

I've been trying to set up the sequelize-cli but to no avail. As a note, the "old" cli that comes with [email protected] works.

These steps

mkdir tmp
cd .\tmp
npm install sequelize sequelize-cli mysql
.\node_modules\.bin\sequelize init

yield

Sequelize [Node: 0.11.13, CLI: 1.0.2, ORM: 2.0.0-rc7]

[14:56:47] Using sequelizefile C:\GitHub\tmp\node_modules\sequelize-cli\lib\sequelizefile.js
[14:56:47] Task 'init' was not defined in your sequelizefile but you tried to run it.
[14:56:47] Please check the documentation for proper sequelizefile formatting.

I do not have a global installation of this or the previous cli. No tasks, not even the default task, are found and can be run.

This bug applies to 1.0.2, 1.0.0 and 0.3.3.

Allow .sequelizerc to export configuration object

My application's configuration is read from environment variables by a config module. I don't want to duplicate part of the configuration just to use sequelize-cli. Is it possible (or could it be) to allow .sequelizerc to export a configuration object instead of just a path to a JSON file. This would be tremendously helpful.

Rails like migration generation

The CLI should support rails like migration generation รก la:

sequelize migration:create --name=create-products

Which generates a new migration with a corresponding scaffold:

module.exports = {
  up: function(migration, DataTypes, done) {
    migration.createTable(
      'products',
      {
        // @todo implement
      }
    );
    done();
  },

  down: function(migration, DataTypes, done) {
    migration.dropTable('products');
    done();
  }
}

Fork scaffolding logic into yeoman generator

Let assume that all migration logic are moved to a separate package to easily create grunt/gulp plugins (#5). But there is also need help with generation configs/models/migrations etc. For example, there is a generate script in the RoR world. Scaffolding is out of the tasks related logic there. Most of js developers already use task runner, some part of them is using yeoman generators. Having a third different tool that combines task related and scaffolding logic can make things slightly confusing.

For example, generator could provide the following (assume it named generator sequelize):

  • this will ask where to store configs, models, migrations and create a structure based on answers:
yo sequelize
  • this will create config at the specified location:
yo sequelize:config

and so on. What does you think about that?

Binary overwritten by sequelize

Installing both sequelize-cli and sequelize causes the sequelize-cli to be overwritten.

Perhaps the cli binary could be called "sequelize-cli" instead to prevent this confusion.

(Issue also submitted to main sequelize project sequelize/sequelize#2376)

Difference between this and migrator repo

What is the difference between this and sequelize-migrator repo. I can see activities/commits in later but not here since last month.
Is this project being abondoned in favour of sequelize-migrator? if so, so i should move to sequelize-migrator

--migrations-path not working

..even if it points to default [project]/migrations folder.

sequelize db:migrate

works fine, but

sequelize --migrations-path migrations db:migrate

and

sequelize --migrations-path ./migrations db:migrate

and

sequelize --migrations-path ./migrations/ db:migrate

generates an error:

Sequelize [CLI: v0.2.2, ORM: v1.7.9]

Loaded configuration file "...".
Using environment "development".
[17:29:44] Using sequelizefile [project]/node_modules/sequelize-cli/sequelizefile.js
[17:29:44] Starting 'db:migrate'...
[17:29:44] Finished 'db:migrate' after 8.52 ms
Running migrations...
20140711164439-tst.js

module.js:340
    throw err;
    ^
Error: Cannot find module 'migrations/20140711164439-tst.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at module.exports.Object.defineProperty.get ([project]/node_modules/sequelize/lib/migration.js:62:14)
    at null.<anonymous> ([project]/node_modules/sequelize/lib/migration.js:72:11)
    at null.<anonymous> ([project]/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
    at processImmediate [as _immediateCallback] (timers.js:336:15)

Sequelize-cli in windows

Hi, I find something strange when using in windows.
Typing 'sequelize' in command line will return an error:

path_to_your\sequelize-cli\node_modules\.bin\gulp:2
basedir=`dirname "$0"`
              ^
SyntaxError: Unexpected token ILLEGAL

I change bin/sequelize eighth line from

gulp = path.resolve(__dirname, โ€˜..โ€™, โ€˜node_modulesโ€™, โ€˜.binโ€™, โ€˜gulpโ€™)
to
gulp = path.resolve(__dirname, โ€˜..โ€™, โ€˜node_modulesโ€™, โ€˜gulpโ€™, โ€˜binโ€™, โ€˜gulp.jsโ€™)

And it can work.
However, the original version is work fine in linux.

More detail: https://medium.com/@jackklpan/eef878734478

Thanks!

sequelize CLI vs umzug

Sequelize 2.0.0-rc4, sequelize-cli 1.0.1

When using the sequelize-cli db:migrate command I get a warning that the migration engine is depreciated and will be removed in favour of umzug. From what I understand the main focus of sequelize CLI is migrations, and upon reading the brief documentation of uzmug in the readme I don't understand how to use it instead of sequelize cli.

Sequelize methods still seems to work in migrations (e.g. migration.createTable('posts', { \* column definitions *\ } ))

  1. Will these be removed for new uzmug methods?

Migrator is no longer availble from the migration object (e.g. migration.migrator.sequelize.query('ALTER TABLE posts SET DEFAULT mongo_dB_object_id()'))
2. How do I run raw queries in migration?

SequelizeMeta is attemping to sync on each migration run

It seems that SequelizeMeta syncs between each migration run, is this expected?
IMHO, if there isn't a propose, this is a bottleneck.

logging:

...
Executing (default): CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , PRIMARY KEY (`name`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `SequelizeMeta`
Executing (default): INSERT INTO `SequelizeMeta` (`name`) VALUES ('20140929124851-hash-security-answers.js');
Executing (default): CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , PRIMARY KEY (`name`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `SequelizeMeta`
Executing (default): SELECT `name` FROM `SequelizeMeta` AS `SequelizeMeta`;
Executing (default): ALTER TABLE `User` ADD `middle_name` VARCHAR(20);
Executing (default): CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , PRIMARY KEY (`name`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `SequelizeMeta`
Executing (default): INSERT INTO `SequelizeMeta` (`name`) VALUES ('20141014150529-user-middle-name.js');
Executing (default): CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , PRIMARY KEY (`name`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `SequelizeMeta`
Executing (default): SELECT `name` FROM `SequelizeMeta` AS `SequelizeMeta`;
Executing (default): SHOW INDEX FROM `User`
Executing (default): DROP INDEX search ON `User`
Executing (default): CREATE FULLTEXT INDEX `search` ON `User` (`first_name`, `middle_name`, `last_name`, `nick_name`, `full_name`)
Executing (default): CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , PRIMARY KEY (`name`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `SequelizeMeta`
Executing (default): INSERT INTO `SequelizeMeta` (`name`) VALUES ('20141016122521-index-user-search.js');
Executing (default): CREATE TABLE IF NOT EXISTS `SequelizeMeta` (`name` VARCHAR(255) NOT NULL UNIQUE , PRIMARY KEY (`name`)) ENGINE=InnoDB;
Executing (default): SHOW INDEX FROM `SequelizeMeta`
Executing (default): SELECT `name` FROM `SequelizeMeta` AS `SequelizeMeta`;
...

Missing sequelizefile.js

migration:create and model:create are using sequelizefile.js for their template, which does not exist. Is it supposed to be there or are we supposed to create our own?

Allow manually specifying which migrations to run

Right now when I run db:migrate or db:migrate:undo it either tries to do run all migrations or undo all migrations.

It might be nice to have a --to [time] flag on both ways that will stop running migrations past that time.

Set tables associations in migrations

Hi. I can't seem to find a documentation on how to create tables associations inside migrations.
I can call .hasMany('table name') if I'm declaring table programmatically, but how to do this inside a migration?
Thanks.

migration:create/model:create do not take id, createdAt, updatedAt into account

When sequelize-cli creates a model based off --attributes, the model itself is created in the default way, which contain an implied id, createdAt, and updatedAt. However the migration file that is created does not reflect this and doesn't contain the default attributes. Because createTable doesn't do this either when a migration is run a table without the standard attributes is created, which is then incompatible with the model.

Add db:create and db:drop tasks

I come from a Rails background and think it'd be pretty convenient to have sequelize db:create and sequelize db:drop as part of the cli.

Since I only use Postgres I wrote two scripts to achieve this and published it under sequelize-migration-pg-extras.

If you could give some advice on how to go about adding native support, I'd be willing to try writing a PR.

TypeError: Object #<Object> has no method 'split' during migration

I'm just now getting this error on a production machine while running migrations. It's confusing because

  1. It just started happening.
  2. I have the same version of node, sequelize-cli, and sequelize on both the production machine and my development machine, and things work fine on development.
  3. The migrations haven't changed since the last successful run.

Oddly enough, the line there makes it seem like it's just generating help information and has nothing to do with my code (wouldn't be surprised if I'm wrong, here).

The server checks out sequelize and sequelize-cli from npm during each deploy, so it's up-to-date with npm at the time of this writing. Will investigate further and see if I can find anything.

deploy@data:/var/www/bitcoinindex.es/current# ./node_modules/.bin/sequelize db:migrate --coffee --env production

Sequelize [Node: 0.10.33, CLI: 1.0.7, ORM: 2.0.0-rc8, mysql: *]

Loaded configuration file 'config/config.json'.
Using environment 'production'.

/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/lib/tasks/model.js:46
          }).split("\n")
             ^
TypeError: Object #<Object> has no method 'split'
  at module.exports.model:create.descriptions.long (/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/lib/tasks/model.js:46:14)
  at Object.<anonymous> (/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/lib/tasks/model.js:63:9)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at /var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/lib/gulpfile.js:19:12
  at Array.map (native)
  at Object.<anonymous> (/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/lib/gulpfile.js:18:4)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Module.require (module.js:364:17)
  at require (module.js:380:17)
  at Liftoff.handleArguments (/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/node_modules/gulp/bin/gulp.js:70:18)
  at Liftoff.launch (/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/node_modules/gulp/node_modules/liftoff/index.js:144:6)
  at Object.<anonymous> (/var/www/bitcoinindex.es/releases/20150131212405/node_modules/sequelize-cli/node_modules/gulp/bin/gulp.js:26:5)
  at Module._compile (module.js:456:26)
  at Object.Module._extensions..js (module.js:474:10)
  at Module.load (module.js:356:32)
  at Function.Module._load (module.js:312:12)
  at Function.Module.runMain (module.js:497:10)
  at startup (node.js:119:16)
  at node.js:906:3

After doing some digging, it looks like split is being called on an object, not an array, which is why it's failing. Here's what the object looks like:

{ 
  code: '\'use strict\'\n\nmodule.exports = (sequelize, DataTypes) ->\n  User = sequelize.define(\'User\', {\n    first_name: DataTypes.STRING\n    last_name: DataTypes.STRING\n    bio: DataTypes.TEXT\n  }, classMethods: associate: (models) ->\n    # associations can be defined here\n    return\n  )\n  User\n',
  ast: 
   { type: 'Program',
     body: [ [Object], [Object] ],
     range: [ 0, 339 ],
     loc: { start: [Object], end: [Object] },
     comments: [ [Object] ] },
  map: 
   { _file: null,
     _sourceRoot: null,
     _skipValidation: false,
     _sources: { _array: [Object], _set: [Object] },
     _names: { _array: [], _set: {} },
     _mappings: { _array: [Object], _sorted: true, _last: [Object] },
     _sourcesContents: null },
  warnings: [] 
}

This should be an easy fix. If I have time I'll submit a PR.

Inconsistent init behavior?

So this just happened...

d:\myapp\myapp>node_modules\.bin\sequelize init

Sequelize [Node: 0.10.34, CLI: 1.0.6, ORM: 2.0.0-rc8]

Created 'config\config.json'
Successfully created migrations folder at 'd:\myapp\myapp\migrations'.
Successfully created models folder at 'd:\myapp\myapp\models'.
Loaded configuration file 'config\config.json'.
Using environment 'development'.
The file d:\myapp\myapp\models\index.js already exists. Run 'sequelize init --force'to overwrite it.

d:\myapp\myapp>node_modules\.bin\sequelize init --farce

Sequelize [Node: 0.10.34, CLI: 1.0.6, ORM: 2.0.0-rc8, mysql: ^2.5.4]

Loaded configuration file 'config\config.json'.

d:\myapp\myapp>

Now I'm not really sure what's going on. I passed --farce (notice the typo) but I don't get the warning about the --force argument to overwrite index.js this time. I also don't get any error about the unrecognized command line argument --farce.

Obviously, index.js wasn't overwritten by --farce, I understand that, but I feel like something could be done to improve this.

Error on init

I am running sequelize-cli v0.3.3. When I call node_modules/.bin/sequelize init I get the following error:

/home/postal/Dropbox/Area51/MyProj/node_modules/sequelize-cli/node_modules/gulp/node_modules/liftoff/index.js:141
    throw new Error('You must provide a callback function.');
          ^
Error: You must provide a callback function.
    at Liftoff.launch (/home/postal/Dropbox/Area51/MyProj/node_modules/sequelize-cli/node_modules/gulp/node_modules/liftoff/index.js:141:11)
    at Object.<anonymous> (/home/postal/Dropbox/Area51/MyProj/node_modules/sequelize-cli/node_modules/gulp/bin/gulp.js:26:5)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

init into other paths

Use case: user wants to put all sequelize-related files into a subdirectory, e.g. ./db/config.json

Currently this doesn't work:
sequelize init:config --options-path=./db

JSON the right format for config?

Is JSON the right format for the config? The only reason I ask is because I generally pull production config from ENV. You fine people have done a good job making this thing customizable so I wouldn't be surprised if you have something for this and I'm not seeing it.

Can't run CLI without mysql client

If I attempt to use the CLI without the mysql client dependency, it fails:

robmaceachern$ node_modules/.bin/sequelize db:migrate

/Users/robmaceachern/workspace/work/caravan/node_modules/sequelize/lib/sequelize.js:163
      throw new Error('The dialect ' + this.getDialect() + ' is not supported.
            ^
Error: The dialect mysql is not supported. (Error: Please install mysql package manually)
    at new module.exports.Sequelize (/Users/robmaceachern/workspace/work/caravan/node_modules/sequelize/lib/sequelize.js:163:13)
    at Object.<anonymous> (/Users/robmaceachern/workspace/work/caravan/node_modules/sequelize-cli/lib/helpers/migration-helper.js:5:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /Users/robmaceachern/workspace/work/caravan/node_modules/sequelize-cli/lib/helpers/index.js:12:54
    at Array.forEach (native)

The problem seems to be that migration-helper.js instantiates a Sequelize instance which is uses the mysql dialect as a default. It look it's just using the instance to map model names to table names.

Workaround: Adding "mysql": "^2.3.2", to my project package.json allows the CLI to run properly.

Unable to resolve storage 'sequelize' [on Win7 64-bit]

Hi,

I am using sequelize-cli to migrate new changes to my running solution. Basically, creating a workflow for pushing updates to my MySQL server hosting my test db. I have one migration file named 20141218140725-create-cafe-owner.js created using the CLI's migration:create command. I used the db:migrate command and it borked giving me this error:

D:\WampDeveloper\Websites\www.example.com\webroot\api_dev>sequelize db:migrate

Sequelize [Node: 0.10.21, CLI: 1.0.0, ORM: 2.0.0-dev9]

Loaded configuration file 'config\config.json'.
[17:24:19] Using sequelizefile ~\AppData\Roaming\npm\node_modules\sequelize-cli\lib\sequelizefile.js
[17:24:19] Starting 'db:migrate'...
[17:24:19] 'db:migrate' errored after 51 ms Unable to resolve the storage: sequelize

D:\WampDeveloper\Websites\www.example.com\webroot\api_dev>

Here's my migration file migrations/20141218140725-create-cafe-owner.js :

"use strict";
module.exports = {
  up: function(migration, DataTypes, done) {
    migration.createTable("CafeOwners", {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: DataTypes.INTEGER
      },
      email: {
        type: DataTypes.STRING(100)
      },
      password: {
        type: DataTypes.STRING(255)
      },
      lastLogin: {
        allowNull: true,
        type: DataTypes.DATE,
      },
      createdAt: {
        allowNull: false,
        type: DataTypes.DATE
      },
      updatedAt: {
        allowNull: false,
        type: DataTypes.DATE
      },
      deletedAt: {
        allowNull: true,
        type: DataTypes.DATE
      },
    }).done(done);
  },
  down: function(migration, DataTypes, done) {
    migration.dropTable("CafeOwners").done(done);
  }
};

For the sake of completeness, here's my config/config.json file as well:

{
  "development": {
    "username": "dbuser",
    "password": "test123",
    "database": "sequelize_test",
    "host": "127.0.0.1",
    "dialect": "mysql"
  },
  "test": {
    "username": "eratest",
    "password": "eratest",
    "database": "sequelize_test",
    "host": "127.0.0.1",
    "dialect": "mysql"
  },
  "production": {
    "username": "ha61gc4e",
    "password": "317e7da87327b3f149b8da90fc1d5746",
    "database": "erasmus",
    "host": "127.0.0.1",
    "dialect": "mysql"
  }
}

I tried to dig through the source, but I am still learning production JS and it seems quite complicated to follow where it's going wrong. After trying to look up this error on Google, I found something about the Sequelize_meta table, but could not find such a table in my database.

Can anyone guide me in the right direction to alleviate this problem?

EventEmitter deprecation warning

When running db:migrate, received below warnings but did successfully complete.

EventEmitter#success|ok is deprecated, please use promise-style instead.
EventEmitter#failure|fail|error is deprecated, please use promise-style instead.

Is underscored: true option supported?

I'm trying to generate model User with it's migration. My config looks like this:

{
    "development": {
        "host"     : "...",
        "database" : "...",
        "define"   : {
            "underscored": true
        },
        "dialect"  : "postgres",
        "port"     : "5432",
        ...
    },
    ...
}

From project root I launch:

node_modules/sequelize-cli/bin/sequelize model:generate --name User --attributes email:string,name:string,hash:string,salt:string

After this I get coffee/models/user.coffee:

"use strict"
module.exports = (sequelize, DataTypes) ->
  User = sequelize.define("User",
    email: DataTypes.STRING
    name: DataTypes.STRING
    hash: DataTypes.STRING
    salt: DataTypes.STRING
  ,
    classMethods:
      associate: (models) ->
  )

  # associations can be defined here
  User

And coffee/migrations/20150107142601-create-user.coffee:

"use strict"
module.exports =
  up: (migration, DataTypes, done) ->
    migration.createTable("Users",
      id:
        allowNull: false
        autoIncrement: true
        primaryKey: true
        type: DataTypes.INTEGER

      email:
        type: DataTypes.STRING

      name:
        type: DataTypes.STRING

      hash:
        type: DataTypes.STRING

      salt:
        type: DataTypes.STRING

      createdAt:
        allowNull: false
        type: DataTypes.DATE

      updatedAt:
        allowNull: false
        type: DataTypes.DATE
    ).done done
    return

  down: (migration, DataTypes, done) ->
    migration.dropTable("users").done done
    return

Is it supposed migration file to create fields createdAt and updatedAt despite underscored option set to true? It seems migration file should contain smth like:

created_at:
  allowNull: false
  type: DataTypes.DATE

updated_at:
  allowNull: false
  type: DataTypes.DATE

and model one:

...
hash: DataTypes.STRING
salt: DataTypes.STRING
createdAt:
  field: "created_at"
updatedAt:
  field: "updated_at"

Is underscored option not yet supported in cli or I'm just doing something wrong?

Thank you.

Some part of sequelize-cli cannot be used as a global (-g)

When installing sequelize-cli globally with npm i sequelize-cli -g (so you can actually run sequelize in the terminal) the parts of it which make actual database calls such as those in db:migrate cannot be used.

This is because these db calls require a database client library (sqlite3, mysql, pg, mariasql) to be installed. Normally sequelize expects that the app installing sequelize would install that package so it would have access to it. However when sequelize-cli is global it doesn't have access to the local packages and so there are no database libraries.

There are 4 ways we could fix this:

A) Just install all the database libraries directly into sequelize-cli.
B) Add another command to sequelize-cli that allows npm i to be called to install individual database libraries into the global sequelize-cli.
C) Resolve database libraries from cwd instead of from the global package (there are libraries that can do this; however since sequelize itself is responsible for requiring the packages this may requiring hacking around in either sequelize-cli or sequelize).
D) Drop sequelize from sequelize-cli and instead resolve it from cwd, where it will have access to the locally installed database libraries.

Fork gulp tasks into gulp-sequelize and reintegrate.

Since gulp has already been introduced as a dependency of the CLI binary, and most of the binary's functionality is based on a set of gulp tasks, I propose the creation of a separate gulp-sequelize project that implements these tasks in a way that conforms to gulp best practices.

After this has been completed, it should be relatively trivial to reintegrate with this standalone binary by simply making gulp-sequelize a package dependency and interacting with its tasks programmatically (as the binary already does).

The advantage of this is that it provides a set of functional tasks to developers who already have an existing gulp-based workflow while simplifying the development of the standalone binary.

Error: Cannot find module 'sqlite3' when using --url

When trying to run sequelize db:migrate --url sqlite:///path/to/database.db I get:


Sequelize [CLI: v0.2.4, ORM: v1.7.9]

Parsed url sqlite:///path/to/database.db
[12:05:25] Using sequelizefile /usr/local/lib/node_modules/sequelize-cli/sequelizefile.js
[12:05:25] Starting 'db:migrate'...
[12:05:25] Finished 'db:migrate' after 26 ms

module.js:340
    throw err;
    ^
Error: Cannot find module 'sqlite3'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at new module.exports.ConnectorManager (/usr/local/lib/node_modules/sequelize-cli/node_modules/sequelize/lib/dialects/sqlite/connector-manager.js:13:17)
    at TransactionManager.getConnectorManager (/usr/local/lib/node_modules/sequelize-cli/node_modules/sequelize/lib/transaction-manager.js:33:36)
    at TransactionManager.query (/usr/local/lib/node_modules/sequelize-cli/node_modules/sequelize/lib/transaction-manager.js:52:15)
    at module.exports.Sequelize.query (/usr/local/lib/node_modules/sequelize-cli/node_modules/sequelize/lib/sequelize.js:330:36)
    at null.fct (/usr/local/lib/node_modules/sequelize-cli/node_modules/sequelize/lib/sequelize.js:410:10)
    at null.<anonymous> (/usr/local/lib/node_modules/sequelize-cli/node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)

sqlite3 is installed in my own project, but sequelize-cli doesn't have it and can't migrate my databases.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.