From 6a401d4a1e7494dcc3738b771581b2df0703caf9 Mon Sep 17 00:00:00 2001 From: Ryan Li Date: Thu, 22 Oct 2020 17:26:37 +0000 Subject: [PATCH] use unique index and separate database migration Signed-off-by: Ryan Li --- db/migration/202009171251-init-database.go | 3 --- db/migration/202010221010-add-unique-index.go | 12 ++++++++++++ db/migration/migration.go | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 db/migration/202010221010-add-unique-index.go diff --git a/db/migration/202009171251-init-database.go b/db/migration/202009171251-init-database.go index 93f984c16..c37aa4552 100644 --- a/db/migration/202009171251-init-database.go +++ b/db/migration/202009171251-init-database.go @@ -77,9 +77,6 @@ CREATE TABLE IF NOT EXISTS workflow_worker_map ( , worker_id UUID NOT NULL ); -ALTER TABLE workflow_worker_map DROP CONSTRAINT IF EXISTS workflow_worker_pkey; -ALTER TABLE workflow_worker_map ADD CONSTRAINT workflow_worker_pkey PRIMARY KEY (workflow_id, worker_id); - CREATE TABLE IF NOT EXISTS workflow_data ( workflow_id UUID NOT NULL , version INT diff --git a/db/migration/202010221010-add-unique-index.go b/db/migration/202010221010-add-unique-index.go new file mode 100644 index 000000000..4938288ab --- /dev/null +++ b/db/migration/202010221010-add-unique-index.go @@ -0,0 +1,12 @@ +package migration + +import migrate "github.com/rubenv/sql-migrate" + +func Get202010221010() *migrate.Migration { + return &migrate.Migration{ + Id: "202010221010-add-unique-index", + Up: []string{` +CREATE UNIQUE INDEX IF NOT EXISTS uidx_workflow_worker_map ON workflow_worker_map (workflow_id, worker_id); +`}, + } +} diff --git a/db/migration/migration.go b/db/migration/migration.go index 2ba774ace..f8a9a35bb 100644 --- a/db/migration/migration.go +++ b/db/migration/migration.go @@ -6,6 +6,7 @@ func GetMigrations() *migrate.MemoryMigrationSource { return &migrate.MemoryMigrationSource{ Migrations: []*migrate.Migration{ Get202009171251(), + Get202010221010(), }, } }