From 065889fd566f7df6c1d6f70041f045b8bef71239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Eduardo=20Jer=C3=A9z=20Gir=C3=B3n?= Date: Sun, 4 Aug 2024 18:54:56 -0600 Subject: [PATCH] Add restorations table to the database migrations --- .../20240805000451_add_restorations_table.sql | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 internal/database/migrations/20240805000451_add_restorations_table.sql diff --git a/internal/database/migrations/20240805000451_add_restorations_table.sql b/internal/database/migrations/20240805000451_add_restorations_table.sql new file mode 100644 index 0000000..4f18117 --- /dev/null +++ b/internal/database/migrations/20240805000451_add_restorations_table.sql @@ -0,0 +1,28 @@ +-- +goose Up +-- +goose StatementBegin +CREATE TABLE IF NOT EXISTS restorations ( + id UUID NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY, + execution_id UUID NOT NULL REFERENCES executions(id) ON DELETE CASCADE, + database_id UUID REFERENCES databases(id) ON DELETE CASCADE, + + status TEXT NOT NULL CHECK ( + status IN ('running', 'success', 'failed') + ) DEFAULT 'running', + message TEXT, + + started_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), + updated_at TIMESTAMPTZ, + finished_at TIMESTAMPTZ +); + +CREATE TRIGGER restorations_change_updated_at +BEFORE UPDATE ON restorations FOR EACH ROW EXECUTE FUNCTION change_updated_at(); + +CREATE INDEX IF NOT EXISTS +idx_restorations_execution_id ON restorations(execution_id); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TABLE IF EXISTS restorations; +-- +goose StatementEnd