-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[DEVOPS-1537 & DEVOPS-1519] Update dbo.Migrations table to support own migration schema #3212
[DEVOPS-1537 & DEVOPS-1519] Update dbo.Migrations table to support own migration schema #3212
Conversation
New Issues
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still a work in progress? I added a few comments as I am interested in this change but ... I don't see any differences from what's already available.
|
||
namespace Bit.Migrator; | ||
|
||
public static class RerunableSqlTableJournalExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ I'd call this just SqlTableJournalExtensions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
||
namespace Bit.Migrator; | ||
|
||
public class RerunableSqlTableJournal : TableJournal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎨 I think it's fine to have this class in the extensions class, as it's only used there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done.
|
||
namespace Bit.Migrator; | ||
|
||
public class RerunableSqlTableJournal : TableJournal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 I see https://github.com/DbUp/DbUp/blob/master/src/dbup-sqlserver/SqlTableJournal.cs -- should that be used instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me give a little background on this. We want to support transition migrations as rerunnable and mark this fact in the migrations database. We split this implementation in two steps:
- Reflect the current functionality in our own code (and passing it to the DbUp), to then :
- Extend "RerunableSqlTableJournal" class to support marking a script as rerunnable - adding a column in the Migrations table, fill and check value when adding and getting the values from this table.
This PR is about the first point. This class is basically the same implementation as you posted, but we want to test the existing migration process with our own code, to then extended it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so it was split up. I realize that's not how the tasks are written, but I don't feel it's needed to review this functionality clone unless some value is being created; I think the two items above should be one change. I would think you could still use SqlTableJournal
and override potentially just one method to add what you're describing.
If you want to be able to run something many times over, DbUp provides NullJournal
as well -- could that be used instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had this conversation with the DevOps team if we want/need to journal those migrations that must be run multiple times. We concluded that we do want to track which migrations have been run, but at the same time mark them as rerunnable to run multiple times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per my inline comment.
This reverts commit df15fa9.
…dbo.Migrations-table-to-support-repeatable-migrations
Hey @withinfocus 👋 I just finished testing the whole utility. It's working as intended, so the PR is ready for review 😊 |
util/Migrator/DbMigrator.cs
Outdated
@@ -24,6 +24,8 @@ public DbMigrator(string connectionString, ILogger<DbMigrator> logger) | |||
} | |||
|
|||
public bool MigrateMsSqlDatabaseWithRetries(bool enableLogging = true, | |||
bool rerunable = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎨 Hate to do this since it's in so many places, but two Ns for "rerunnable". I suggest we go with a less obscure English word and use "repeatable".
@@ -0,0 +1,3 @@ | |||
ALTER TABLE dbo.Migration | |||
ADD Rerunable bit NOT NULL DEFAULT 0 | |||
GO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⛏️ Newline.
@@ -2,6 +2,7 @@ | |||
|
|||
<ItemGroup> | |||
<EmbeddedResource Include="DbScripts\**\*.sql" /> | |||
<EmbeddedResource Include="DbScripts_data_migration\**\*.sql" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Is the _data_migration
in docs somewhere, or a recommendation? DbDataMigrationScripts
or DbDataMigrations
is cleaner to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've got another card to rename this folder: https://bitwarden.atlassian.net/browse/DEVOPS-1520
|
||
namespace Bit.Migrator; | ||
|
||
public static class SqlTableJournalExtensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Did you ever look into my comment about using NullJournal
? Now that the implementation is here, what is the purpose of tracking scripts that you always want to run? If you have a folder for some that can always run, that's a use case for a different journal otherwise you'd keep using the one already in place. What am I missing in the requirements?
I started top down and left a few comments but the last one is the key and worth stepping back for a moment. |
After talking about it, we decided to not track the Transition migrations that have been applied to the database until they are applied from the migrations directory. I'm closing the PR but not deleting the branch for further reference. |
Pull request was closed
Type of change
Objective
In the Migrator project create our own custom journaling, so that we can add migration scripts as repeatable in the migrations table.
Code changes
Before you submit
dotnet format --verify-no-changes
) (required)