diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2021-09-01 14:02:49 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2021-09-29 13:31:13 +0300 |
commit | 2bbec66c9d738b0df435f3aab801747408929ed0 (patch) | |
tree | 33ad3c36838c936484e9ee324c2702558a36287d /internal | |
parent | 80b9699ea44b716e74edf32130a6a3966cb59cae (diff) |
Link existing database record via repository ID
Praefect generates a repository ID to uniquely identify a repository.
While new records that get created are already being linked via the
repository ID, historical records in the database are still not linked
via the repository ID. In order to update the queries to join the records
via the repository ID, all of the relevant records need to be linked via
the repository ID. This commit adds a migration that links the records
in 'storage_repositories' and 'repository_assignments' to the 'repositories'
table's records via the ID.
Replication jobs are not included in the migration as they are not long lived
and they can be rescheduled.
Changelog: other
Diffstat (limited to 'internal')
-rw-r--r-- | internal/praefect/datastore/migrations/20210906145021_link_repository_id.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/praefect/datastore/migrations/20210906145021_link_repository_id.go b/internal/praefect/datastore/migrations/20210906145021_link_repository_id.go new file mode 100644 index 000000000..08c9663bd --- /dev/null +++ b/internal/praefect/datastore/migrations/20210906145021_link_repository_id.go @@ -0,0 +1,28 @@ +package migrations + +import migrate "github.com/rubenv/sql-migrate" + +func init() { + m := &migrate.Migration{ + Id: "20210906145021_link_repository_id", + Up: []string{ + ` +UPDATE storage_repositories +SET repository_id = repositories.repository_id +FROM repositories +WHERE storage_repositories.virtual_storage = repositories.virtual_storage +AND storage_repositories.relative_path = repositories.relative_path + `, + ` +UPDATE repository_assignments +SET repository_id = repositories.repository_id +FROM repositories +WHERE repository_assignments.virtual_storage = repositories.virtual_storage +AND repository_assignments.relative_path = repositories.relative_path + `, + }, + Down: []string{}, + } + + allMigrations = append(allMigrations, m) +} |