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

docs(migrations): added advanced skeleton example #10190

Merged
merged 1 commit into from Nov 22, 2018
Merged

docs(migrations): added advanced skeleton example #10190

merged 1 commit into from Nov 22, 2018

Conversation

@s1moe2
Copy link
Contributor

@s1moe2 s1moe2 commented Nov 22, 2018

Description of change

Added an example of a more advanced migration skeleton

Copy link
Contributor

@sushantdhiman sushantdhiman left a comment

While this actually wont ensure complete rollback (SequelizeMeta entry wont be rolled back) but this effectively demonstrate how to use transactions so I will accept this

@codecov
Copy link

@codecov codecov bot commented Nov 22, 2018

Codecov Report

Merging #10190 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #10190   +/-   ##
=======================================
  Coverage   96.34%   96.34%           
=======================================
  Files          63       63           
  Lines        9420     9420           
=======================================
  Hits         9076     9076           
  Misses        344      344

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 946fb72...e8667b0. Read the comment docs.

@sushantdhiman sushantdhiman merged commit f2cafcc into sequelize:master Nov 22, 2018
4 checks passed
4 checks passed
codecov/patch Coverage not affected when comparing 946fb72...e8667b0
Details
codecov/project 96.34% remains the same compared to 946fb72
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@s1moe2
Copy link
Contributor Author

@s1moe2 s1moe2 commented Nov 22, 2018

@sunshinewyin Thank you for looking into this PR and for your feedback.
Can you point me to an example that covers the rollback of the metadata table?
I tested this scenario and it only writes to SequelizeMeta after the transaction commits, meaning the metadata is never compromised if any if the alterTable fails (in this scenario, ofc).

module.exports = {
  up: (queryInterface, Sequelize) => {
      return queryInterface.sequelize.transaction((t) => {
          return Promise.all([
              queryInterface.addColumn('Users', 'petName', {
                  type: Sequelize.STRING
              }, { transaction: t }),
              queryInterface.addColumn('UserWRONGNAME', 'favoriteColor', {
                  type: Sequelize.STRING,
              }, { transaction: t })
          ])
      })
  },
   down: (queryInterface, Sequelize) => {
      return queryInterface.sequelize.transaction((t) => {
          return Promise.all([
              queryInterface.removeColumn('User', 'petName', { transaction: t }),
              queryInterface.removeColumn('User', 'favoriteColor', { transaction: t })
          ])
      })
  }
};
$$$ sequelize db:migrate

Sequelize CLI [Node: 10.13.0, CLI: 5.3.0, ORM: 4.41.2]

Loaded configuration file "src/config/config.js".
Using environment "development".
== 20181122123012-test-migration: migrating =======

ERROR: relation "public.UserWRONGNAME" does not exist


$$$ psql -U postgres -d tests
psql (10.5)
Type "help" for help.

tests=# select * from "SequelizeMeta" ;
                  name
-----------------------------------------
 20180703164148-create-user.js
 20180704091522-create-company.js
 20180704091831-create-employee.js
 20180704092003-create-skill.js
 20180704092256-create-employee-skill.js
 20180723183134-create-session.js
(6 rows)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants