Coder Social home page Coder Social logo

Comments (5)

pasztorpisti avatar pasztorpisti commented on June 13, 2024 1

I had the same issue and looked at the code but I wasn't sure how to fix it or whether it is possible to fix it without changing the public interface of the library. In my opinion migrations should be executed from the CI/CD pipeline as a commandline tool and not by a service at startup (by using the migration tool as a library). I find the latter to be an antipattern and it makes changing/refactoring the code more difficult (because of the exported public stuff).

In my opinion what you need to perform migrations is only a goto <target> command. The up and down commands can be translated to goto latest and goto latest-1 respectively.

If we assume that we have a goto <target> command then it should do the following:

  1. Migrations that are newer than <target> and have been up-migrated have to be reverted by down-migrating them in descending order.
  2. The <target> migration along with the older migrations have to be up-migrated in ascending order (only those that haven't yet been applied).

Based on the above algorithm if we have a situation like this:

[X] 0001.sql
[ ] 0002.sql
[X] 0003.sql
[ ] 0004.sql
[X] 0005.sql
[X] 0006.sql
[X] 0007.sql
[ ] 0008.sql

... and we perform a goto 0005.sql then it should result in the following operations:

  1. down-migrate 0007.sql
  2. down-migrate 0006.sql
  3. up-migrate 0002.sql
  4. up-migrate 0004.sql

Result:

[X] 0001.sql
[X] 0002.sql
[X] 0003.sql
[X] 0004.sql
[X] 0005.sql
[ ] 0006.sql
[ ] 0007.sql
[ ] 0008.sql

However, I think if you have unapplied migrations that are older than some applied migrations then you already have a problem that should be resolved manually - which means that the goto <target> command should fail in the above situation instead of doing both down- and up- migrations.

You can easily end up with gaps in the range of your applied migrations by working on several branches and merging them.

from sql-migrate.

rubenv avatar rubenv commented on June 13, 2024

@pasztorpisti Cool to see you build your own tool, but please name it something else. Right now it's going to lead to a ton of confusion and it makes it impossible to have both installed at the same time (not to mention broken builds).

from sql-migrate.

pasztorpisti avatar pasztorpisti commented on June 13, 2024

@rubenv For now I think it's better if I keep the tool private for myself (less hassle for many reasons). I'll have to think about a name and need free time to change the references everywhere (CI, docker hub) if I decide to make the change. I'm a barbarian who names things by simply joins keywords so "migrate" and "sql-migrate" are pretty obvious choices.

from sql-migrate.

rangzen avatar rangzen commented on June 13, 2024

Same problem.
When you go down and a previous up query is not done, it is added to the migrations (with this up query, see the call to catchup). The problem is that the direction of the migration is always down, so when you do the switch dir { of applyMigrations:508, you go to the down part, so the query is executed (probably a create), but the id is deleted (but not existing anyway) instead of being inserted (as an up query).

from sql-migrate.

rangzen avatar rangzen commented on June 13, 2024

Proposed PR #235

from sql-migrate.

Related Issues (20)

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.