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

backend: Add migration down support #604

Merged
merged 3 commits into from
May 30, 2022
Merged

backend: Add migration down support #604

merged 3 commits into from
May 30, 2022

Conversation

yolossn
Copy link
Contributor

@yolossn yolossn commented May 2, 2022

No description provided.

@yolossn yolossn requested a review from joaquimrocha May 2, 2022 06:55
@yolossn yolossn marked this pull request as draft May 2, 2022 06:57
@yolossn yolossn marked this pull request as ready for review May 2, 2022 06:57
@yolossn
Copy link
Contributor Author

yolossn commented May 2, 2022

The migrate-down flag should be used to remove the last migrations before reverting to an old version of Nebraska. One question still remains, how will the admin know how many migrations should be reverted ? Should we start adding the migrations introduced along with the releases going on ? @joaquimrocha thoughts ?

@joaquimrocha
Copy link
Collaborator

The migrate-down command should be used to remove the last migrations before reverting to an old version of Nebraska. One question still remains, how will the admin know how many migrations should be reverted ? Should we start adding the migrations introduced along with the releases going on ? @joaquimrocha thoughts ?

I think maybe we can an argument support to migrate-down, so users can do: --migrate-down=004 (exclusive, i.e. down to 004 which will be the last migration applied applied).

Users can use git to get the last migration for a past version:
git show 2.4.0:./backend/pkg/api/db/migrations | tail -n1

Alternatively we could add a command called db-migrate with the following options:
nebraska db-migrate --down-to=004: this migrations down till a migration starting with 004 (this one is not migrated down, i.e. it's exclusive)
nebraska db-migrate --show: this lists the current migrations for the current version.

(but this command would only be available in new versions, so maybe it's not so useful when users have git)

WDYT?

@yolossn
Copy link
Contributor Author

yolossn commented May 13, 2022

Makes sense to use the migration id for migrate down, I will add the documentation for the same.

@yolossn
Copy link
Contributor Author

yolossn commented May 20, 2022

Added docs for migrating to an older version of Nebraska.

@illume
Copy link
Contributor

illume commented May 23, 2022

A test for verifying migrations down work would be useful.

@yolossn
Copy link
Contributor Author

yolossn commented May 24, 2022

Added test 👍🏽

@illume
Copy link
Contributor

illume commented May 24, 2022

Added test 👍🏽

Awesome. Thanks!

Copy link
Collaborator

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

Found an issue in the docs.
BTW, --migrate-down-to sounds a bit complicated and is unrelated to DBs. Should we rename it as --migrate-db-to and support migrating up as well? (maybe in the beginning we can just support migrating down, but it's important that the command name makes sense)


> git show <NEBRASKA-VERSION>:./backend/pkg/api/db/migrations | tail -n1

For example to find the migrations that were introduced as part of `2.4.0` release clone the Nebraska repo and run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this article is a bit confusing. The command associated with this phrase doesn't necessarily show the newly added files in this folder for this tag, it just lists the contents of that dir, for that tag (so it is the same result for 2.4.1).

It should instead say that if users want to migrate to a version, like 2.4.0, they should run the command you wrote (gets them the last migration considered in 2.4.0) and run the --migrate-down-to 0013.

@yolossn
Copy link
Contributor Author

yolossn commented May 25, 2022

--migrate-down-to sounds a bit complicated and is unrelated to DBs.

Does rollback-db-to make sense ?

Sorry I misunderstood the git show part from your previous comment, Ill update the docs accordingly.

yolossn added 2 commits May 25, 2022 13:51
this patch adds support to revert migrations using the
--migrate-down flag.

Signed-off-by: Santhosh Nagaraj S <[email protected]>
this patch fixes the errors in migrate down queries.

Signed-off-by: Santhosh Nagaraj S <[email protected]>
Copy link
Collaborator

@joaquimrocha joaquimrocha left a comment

Choose a reason for hiding this comment

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

Left a comment about the command's name. Also, I don't think the docs were updated.

backend/pkg/config/config.go Show resolved Hide resolved
this patch adds documentation for migrating to
a older version of Nebraska.

Signed-off-by: Santhosh Nagaraj S <[email protected]>
@joaquimrocha joaquimrocha merged commit e4f2e06 into main May 30, 2022
@joaquimrocha joaquimrocha deleted the migrate_down branch May 30, 2022 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deployment: Downgrading Nebraska to an older version doesn't remove the migrations.
3 participants