-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Playlist: Add create+update timestamps to the database #76295
Conversation
@@ -82,7 +82,6 @@ func (*OSSMigrations) AddMigration(mg *Migrator) { | |||
accesscontrol.AddManagedPermissionsMigration(mg, accesscontrol.ManagedPermissionsMigrationID) | |||
accesscontrol.AddManagedFolderAlertActionsMigration(mg) | |||
accesscontrol.AddActionNameMigrator(mg) | |||
addPlaylistUIDMigration(mg) |
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.
note: this does not remove the migration -- the same migrations are now added in addPlaylistMigrations
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 know this doesn't remove the migration, but we must not change the migrations list! It is additive only - that's set out in our contribution guidelines and changing past migrations can cause unexpected behavior in existing instances: https://github.com/grafana/grafana/blob/main/contribute/backend/database.md#migrations
|
||
func addPlaylistUIDMigration(mg *Migrator) { |
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.
^^ this was split as a different function before, but now all migrations added from the same entry point
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.
But this also changes the order of the migrations, doesn't it? What's the benefit of merging it into one function?
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.
removed the cleanup -- the only reason i did it was to reuse the same table structure created in playlistV2()
but does not really matter, we can create a new one for every migration
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 don't think we can change existing migrations the way this PR does, but I'll get a second opinion on that. Otherwise, this looks (and works) ok to me!
🤔 Not directly related, but has anyone suggested we add a provisioning source field to all of our kinds, to differentiate between records saved via k8s, the UI, terraform, etc?
@@ -82,7 +82,6 @@ func (*OSSMigrations) AddMigration(mg *Migrator) { | |||
accesscontrol.AddManagedPermissionsMigration(mg, accesscontrol.ManagedPermissionsMigrationID) | |||
accesscontrol.AddManagedFolderAlertActionsMigration(mg) | |||
accesscontrol.AddActionNameMigrator(mg) | |||
addPlaylistUIDMigration(mg) |
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 know this doesn't remove the migration, but we must not change the migrations list! It is additive only - that's set out in our contribution guidelines and changing past migrations can cause unexpected behavior in existing instances: https://github.com/grafana/grafana/blob/main/contribute/backend/database.md#migrations
} | ||
// Add columns used for kubernetes dual write synchronization | ||
mg.AddMigration("Add playlist column created_at", NewAddColumnMigration(playlistV2, &Column{ | ||
Name: "created_at", Type: DB_BigInt, Nullable: false, Default: "0", |
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.
Shouldn't this be DATETIME
SQL type (same about updated_at
)?
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.
with DATETIME, you can't apply a default to an existing structure :( so it can not be a required field, and that leads to needing pointers 🤮
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'm not saying this as an argument in either direction, but I poked through the code and we're more likely to use an int64 than DATETIME in other tables, too 🤷🏻
removed the migration cleanup -- does not really matter, so no issue with it |
yes -- entity api has an origin field to help with this. In k8s it will be stored as an annotation on any resource. I don't think it is worth adding to the existing tables though. |
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.
👍🏻 LGTM, thanks for addressing the migration concerns!
What is this feature?
This adds created+updated epoc columns to the playlist database
Why do we need this feature?
The k8s api service needs something to track when a resource changes
Who is this feature for?
This is to help move k8s development forward.
After running the playlist table will look like:
![image](https://private-user-images.githubusercontent.com/705951/274031712-c6df0b97-81f3-4ea6-86e6-f87332f8436a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxODg3NTIsIm5iZiI6MTcyMjE4ODQ1MiwicGF0aCI6Ii83MDU5NTEvMjc0MDMxNzEyLWM2ZGYwYjk3LTgxZjMtNGVhNi04NmU2LWY4NzMzMmY4NDM2YS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwNzI4JTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDcyOFQxNzQwNTJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0zNWFiZjU0OTRiZTYxMzg2NWVmM2U3NGIxZTI2NTU5M2U5ZTAyMGI4ZTIyMjE4MjM4NDhlOTEzOWQzMmUzZDMyJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.lXHCLHPjeCwCKP8V-l0Q038ATGCr9ooBoU3LMjiexXE)
Extracted from #75709