From d2c0d45a24718ef4c2dc985e23eb2a2332dc02c3 Mon Sep 17 00:00:00 2001 From: Sonali Wale <86949270+sonali523@users.noreply.github.com> Date: Wed, 5 Jan 2022 21:54:06 +0530 Subject: [PATCH] Database script for migration tables (#6500) * Script added for migration tables Signed-off-by: sonali wale * Insert scripts added for migration type and status Signed-off-by: sonali wale * Server id column added in migration table Signed-off-by: sonali wale * Index added on server_id column in migration table Signed-off-by: sonali wale --- .../migration/sql/07_migration.down.sql | 8 +++++ .../migration/sql/07_migration.up.sql | 36 +++++++++++++++++++ .../storage/postgres/migration/sql/README.md | 1 + 3 files changed, 45 insertions(+) create mode 100644 components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql create mode 100644 components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql diff --git a/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql new file mode 100644 index 00000000000..e14d9c12fcb --- /dev/null +++ b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.down.sql @@ -0,0 +1,8 @@ +-- drop table migration +DROP TABLE IF EXISTS migration; + +-- drop table migration_type +DROP TABLE IF EXISTS migration_type; + +-- drop table migration_status +DROP TABLE IF EXISTS migration_status; diff --git a/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql new file mode 100644 index 00000000000..eeda0041384 --- /dev/null +++ b/components/infra-proxy-service/storage/postgres/migration/sql/07_migration.up.sql @@ -0,0 +1,36 @@ +--create table migration_type +CREATE TABLE IF NOT EXISTS migration_type ( + id TEXT PRIMARY KEY, + type TEXT NOT NULL DEFAULT '' +); + +--create table migration_status +CREATE TABLE IF NOT EXISTS migration_status ( + id TEXT PRIMARY KEY, + status_message TEXT NOT NULL DEFAULT 'In Progress' +); + +--create table migration +CREATE TABLE IF NOT EXISTS migration ( + id TEXT PRIMARY KEY, + type_id TEXT NOT NULL references migration_type(id) ON DELETE RESTRICT, + status_id TEXT NOT NULL references migration_status(id) ON DELETE RESTRICT, + server_id TEXT NOT NULL references servers(id) ON DELETE RESTRICT, + total_succeeded int, + total_skipped int, + total_failed int, + created_at TIMESTAMPTZ NOT NULL, + updated_at TIMESTAMPTZ NOT NULL +); +CREATE INDEX IF NOT EXISTS migration_server_id_index ON migration (server_id); + +-- Insert rows into migration_type +INSERT INTO migration_type (id,type) +VALUES (md5(RANDOM()::TEXT),'user'), + (md5(RANDOM()::TEXT),'org'); + +-- Insert rows into migration_status +INSERT INTO migration_status(id,status_message) +VALUES (md5(RANDOM()::TEXT),'In Progress'), + (md5(RANDOM()::TEXT),'Completed'), + (md5(RANDOM()::TEXT),'Failed'); diff --git a/components/infra-proxy-service/storage/postgres/migration/sql/README.md b/components/infra-proxy-service/storage/postgres/migration/sql/README.md index 238cc79e8ec..0ab00e0d30b 100644 --- a/components/infra-proxy-service/storage/postgres/migration/sql/README.md +++ b/components/infra-proxy-service/storage/postgres/migration/sql/README.md @@ -7,3 +7,4 @@ - [`04_convert_table_to_human_readable_ids.up.sql`](04_convert_table_to_human_readable_ids.up.sql) - [`05_remove_orgs_pkey.up.sql`](05_remove_orgs_pkey.up.sql) - [`06_user_management.up.sql`](06_user_management.up.sql) +- [`07_migration.up.sql`](07_migration.up.sql)