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 1 commit into from Nov 22, 2018

docs(migrations): added advanced skeleton example #10190

merged 1 commit into from Nov 22, 2018


Copy link

@s1moe2 s1moe2 commented Nov 22, 2018

Description of change

Added an example of a more advanced migration skeleton

Copy link

@sushantdhiman sushantdhiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link

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
Copy link
Contributor Author

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" ;
(6 rows)

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

Successfully merging this pull request may close these issues.

None yet

2 participants