From 7876aae0209d394f57440d1576f0498b87038d52 Mon Sep 17 00:00:00 2001 From: Vadim Gedz Date: Thu, 6 Feb 2025 18:16:33 +0200 Subject: [PATCH] chore(postgres): indexes adjustment and struct cleanup --- cmd/argo-watcher/config/config.go | 5 ----- db/migrations/000004_optimize_indexes.down.sql | 9 +++++++++ db/migrations/000004_optimize_indexes.up.sql | 6 ++++++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 db/migrations/000004_optimize_indexes.down.sql create mode 100644 db/migrations/000004_optimize_indexes.up.sql diff --git a/cmd/argo-watcher/config/config.go b/cmd/argo-watcher/config/config.go index e8243ce8..e2240ee1 100644 --- a/cmd/argo-watcher/config/config.go +++ b/cmd/argo-watcher/config/config.go @@ -17,11 +17,6 @@ type KeycloakConfig struct { } type DatabaseConfig struct { - Host string `env:"DB_HOST"` - Port string `env:"DB_PORT" envDefault:"5432"` - Name string `env:"DB_NAME"` - User string `env:"DB_USER"` - Password string `env:"DB_PASSWORD"` SSLMode string `env:"DB_SSL_MODE" envDefault:"disable"` TimeZone string `env:"DB_TIMEZONE" envDefault:"UTC"` DSN string `env:"DB_DSN,expand" envDefault:"host=${DB_HOST} port=${DB_PORT} user=${DB_USER} password=${DB_PASSWORD} dbname=${DB_NAME} sslmode=${DB_SSL_MODE} TimeZone=${DB_TIMEZONE}"` diff --git a/db/migrations/000004_optimize_indexes.down.sql b/db/migrations/000004_optimize_indexes.down.sql new file mode 100644 index 00000000..6b431833 --- /dev/null +++ b/db/migrations/000004_optimize_indexes.down.sql @@ -0,0 +1,9 @@ +-- Restore the old index on `created` +CREATE INDEX IF NOT EXISTS tasks_idx_created ON tasks (created); + +-- Restore the index on `status` +CREATE INDEX IF NOT EXISTS "idx_tasks_status" ON "tasks" ("status"); + +-- Drop the newly created indexes +DROP INDEX IF EXISTS idx_tasks_created_app; +DROP INDEX IF EXISTS idx_tasks_id; diff --git a/db/migrations/000004_optimize_indexes.up.sql b/db/migrations/000004_optimize_indexes.up.sql new file mode 100644 index 00000000..3b575262 --- /dev/null +++ b/db/migrations/000004_optimize_indexes.up.sql @@ -0,0 +1,6 @@ +CREATE INDEX IF NOT EXISTS idx_tasks_created_app ON tasks (created DESC, app); +CREATE UNIQUE INDEX IF NOT EXISTS idx_tasks_id ON tasks (id); + +-- Drop indexes that are no longer needed +DROP INDEX IF EXISTS tasks_idx_created; +DROP INDEX IF EXISTS idx_tasks_status;