Giter VIP home page Giter VIP logo

sequelize-model-example's Introduction

  1. I initialize sequelize in my new project
➜ npx sequelize-cli init

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

Created "config/config.json"
Successfully created models folder at "/Users/rusinov/projects/oss/sequelize-model-example/models".
Successfully created migrations folder at "/Users/rusinov/projects/oss/sequelize-model-example/migrations".
Successfully created seeders folder at "/Users/rusinov/projects/oss/sequelize-model-example/seeders".
  1. I create my first model with two columns: "firstName" and "lastName"
➜ npx sequelize-cli model:generate --name ExampleModel --attributes firstName:string,lastName:string
Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

New model was created at /Users/rusinov/projects/oss/sequelize-model-example/models/examplemodel.js .
New migration was created at /Users/rusinov/projects/oss/sequelize-model-example/migrations/20191010182858-ExampleModel.js .
  1. I create database
➜ npx sequelize-cli db:create

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

Loaded configuration file "config/config.json".
Using environment "development".
(node:34753) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
Database database_development created.
  1. Then run migrations
➜ npx sequelize-cli db:migrate

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

Loaded configuration file "config/config.json".
Using environment "development".
(node:34844) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
== 20191010182858-create-example-model: migrating =======
== 20191010182858-create-example-model: migrated (0.021s)
  1. After a while I need new column -"email" on my table, so I try to regenerate model with model:generate command, after getting the error about --force flag I retry it and get my new model and migration created
➜ npx sequelize-cli model:generate --name ExampleModel --attributes firstName:string,lastName:string,email:string

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]


ERROR: The file /Users/rusinov/projects/oss/sequelize-model-example/models/examplemodel.js already exists. Run command with --force to overwrite it.

➜ npx sequelize-cli model:generate --name ExampleModel --attributes firstName:string,lastName:string,email:string --force

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

New model was created at /Users/rusinov/projects/oss/sequelize-model-example/models/examplemodel.js .
New migration was created at /Users/rusinov/projects/oss/sequelize-model-example/migrations/20191010183123-ExampleModel.js .
  1. Then I undo migrations in my db
➜ npx sequelize-cli db:migrate:undo:all

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

Loaded configuration file "config/config.json".
Using environment "development".
(node:35286) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
== 20191010182858-create-example-model: reverting =======
== 20191010182858-create-example-model: reverted (0.017s)
  1. And do migrations again
npx sequelize-cli db:migrate

Sequelize CLI [Node: 10.15.1, CLI: 5.5.1, ORM: 5.19.5]

Loaded configuration file "config/config.json".
Using environment "development".
(node:35377) [SEQUELIZE0004] DeprecationWarning: A boolean value was passed to options.operatorsAliases. This is a no-op with v5 and should be removed.
== 20191010182858-create-example-model: migrating =======
== 20191010182858-create-example-model: migrated (0.022s)

== 20191010183123-create-example-model: migrating =======
== 20191010183123-create-example-model: migrated (0.006s)

Here is what I have in SequelizeMeta table after that:

name
-----
20191010182858-create-example-model.js
20191010183123-create-example-model.js

Model and latter migration both have "email" declared, but "email" column is not present in table "ExampleModels"

Note that I use the postgres db. Dont know if that matters, tho.

sequelize-model-example's People

Contributors

rusinovanton avatar

Stargazers

 avatar

Watchers

 avatar

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.