From 09d2fee06ebbd934e5c51f0ef5d9d6ce2ce5233a Mon Sep 17 00:00:00 2001 From: Vistaar Juneja Date: Fri, 4 Aug 2023 10:43:44 +0100 Subject: [PATCH] move db migrations to different folder --- internal/router/api.go | 3 +- .../ci_migrations.sql} | 31 +++++++++++++++++++ .../sqlite/0020_create_table_pipelines.up.sql | 30 ------------------ 3 files changed, 32 insertions(+), 32 deletions(-) rename internal/store/database/migrate/{sqlite/0021_create_table_executions.up.sql => ci/ci_migrations.sql} (58%) delete mode 100644 internal/store/database/migrate/sqlite/0020_create_table_pipelines.up.sql diff --git a/internal/router/api.go b/internal/router/api.go index e88d79777..41e455ab9 100644 --- a/internal/router/api.go +++ b/internal/router/api.go @@ -283,7 +283,6 @@ func setupPipelines(r chi.Router, pipelineCtrl *pipeline.Controller, executionCt r.Get("/", handlerpipeline.HandleFind(pipelineCtrl)) r.Patch("/", handlerpipeline.HandleUpdate(pipelineCtrl)) r.Delete("/", handlerpipeline.HandleDelete(pipelineCtrl)) - // TODO: setup executions here setupExecutions(r, executionCtrl) }) }) @@ -291,7 +290,7 @@ func setupPipelines(r chi.Router, pipelineCtrl *pipeline.Controller, executionCt func setupExecutions(r chi.Router, executionCtrl *execution.Controller) { r.Route("/executions", func(r chi.Router) { - r.Post("/") + }) } diff --git a/internal/store/database/migrate/sqlite/0021_create_table_executions.up.sql b/internal/store/database/migrate/ci/ci_migrations.sql similarity index 58% rename from internal/store/database/migrate/sqlite/0021_create_table_executions.up.sql rename to internal/store/database/migrate/ci/ci_migrations.sql index 466b193d3..a46c210f7 100644 --- a/internal/store/database/migrate/sqlite/0021_create_table_executions.up.sql +++ b/internal/store/database/migrate/ci/ci_migrations.sql @@ -1,3 +1,34 @@ +CREATE TABLE IF NOT EXISTS pipelines ( + pipeline_id INTEGER PRIMARY KEY AUTOINCREMENT, + pipeline_description TEXT, + pipeline_parent_id INTEGER NOT NULL, + pipeline_uid TEXT NOT NULL, + pipeline_seq INTEGER NOT NULL DEFAULT 0, + pipeline_repo_id INTEGER, + pipeline_repo_type TEXT NOT NULL, + pipeline_repo_name TEXT, + pipeline_default_branch TEXT, + pipeline_config_path TEXT, + pipeline_created INTEGER, + pipeline_updated INTEGER, + pipeline_version INTEGER, + + -- Ensure unique combination of UID and ParentID + UNIQUE (pipeline_parent_id, pipeline_uid), + + -- Foreign key to spaces table + CONSTRAINT fk_pipeline_parent_id FOREIGN KEY (pipeline_parent_id) + REFERENCES spaces (space_id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE CASCADE + + -- Foreign key to repositories table + CONSTRAINT fk_pipeline_repo_id FOREIGN KEY (pipeline_repo_id) + REFERENCES repositories (repo_id) MATCH SIMPLE + ON UPDATE NO ACTION + ON DELETE CASCADE +); + CREATE TABLE IF NOT EXISTS executions ( execution_id INTEGER PRIMARY KEY AUTOINCREMENT, execution_pipeline_id INTEGER NOT NULL, diff --git a/internal/store/database/migrate/sqlite/0020_create_table_pipelines.up.sql b/internal/store/database/migrate/sqlite/0020_create_table_pipelines.up.sql deleted file mode 100644 index d5324e18a..000000000 --- a/internal/store/database/migrate/sqlite/0020_create_table_pipelines.up.sql +++ /dev/null @@ -1,30 +0,0 @@ -CREATE TABLE IF NOT EXISTS pipelines ( - pipeline_id INTEGER PRIMARY KEY AUTOINCREMENT, - pipeline_description TEXT, - pipeline_parent_id INTEGER NOT NULL, - pipeline_uid TEXT NOT NULL, - pipeline_seq INTEGER NOT NULL DEFAULT 0, - pipeline_repo_id INTEGER, - pipeline_repo_type TEXT NOT NULL, - pipeline_repo_name TEXT, - pipeline_default_branch TEXT, - pipeline_config_path TEXT, - pipeline_created INTEGER, - pipeline_updated INTEGER, - pipeline_version INTEGER, - - -- Ensure unique combination of UID and ParentID - UNIQUE (pipeline_parent_id, pipeline_uid), - - -- Foreign key to spaces table - CONSTRAINT fk_pipeline_parent_id FOREIGN KEY (pipeline_parent_id) - REFERENCES spaces (space_id) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE CASCADE - - -- Foreign key to repositories table - CONSTRAINT fk_pipeline_repo_id FOREIGN KEY (pipeline_repo_id) - REFERENCES repositories (repo_id) MATCH SIMPLE - ON UPDATE NO ACTION - ON DELETE CASCADE -); \ No newline at end of file