From 2a8febf88f09c86ed84f596045b934abdb220fd8 Mon Sep 17 00:00:00 2001 From: Miguel Martinez Trivino Date: Tue, 26 Nov 2024 19:35:22 +0100 Subject: [PATCH] add support to drop db constraints (#1598) Signed-off-by: Miguel Martinez --- app/controlplane/Makefile | 5 ++++- app/controlplane/atlas.hcl | 8 ++++++++ .../pkg/data/ent/migrate/migrations/20241126164629.sql | 3 +++ .../pkg/data/ent/migrate/migrations/20241126182209.sql | 3 +++ .../pkg/data/ent/migrate/migrations/atlas.sum | 4 +++- 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 app/controlplane/atlas.hcl create mode 100644 app/controlplane/pkg/data/ent/migrate/migrations/20241126164629.sql create mode 100644 app/controlplane/pkg/data/ent/migrate/migrations/20241126182209.sql diff --git a/app/controlplane/Makefile b/app/controlplane/Makefile index 8ff8477c1..bb2326048 100644 --- a/app/controlplane/Makefile +++ b/app/controlplane/Makefile @@ -36,7 +36,10 @@ migration_apply: check-atlas-tool migration_hash .PHONY: migration_sync # sync migration files with the current ent schema migration_sync: check-atlas-tool migration_hash - atlas migrate diff --dir ${local_migrations_dir} --to "ent://pkg/data/ent/schema" --dev-url "docker://postgres/15/test?search_path=public" + atlas migrate diff --dir ${local_migrations_dir} --to "ent://pkg/data/ent/schema" --dev-url "docker://postgres/15/test?search_path=public" --config file://atlas.hcl --env dev + +migration_lint: check-atlas-tool migration_hash + atlas migrate lint --dir ${local_migrations_dir} --dev-url "docker://postgres/15/test?search_path=public" --latest 1 --config file://atlas.hcl --env dev .PHONY: migration_new # generate an empty migration file diff --git a/app/controlplane/atlas.hcl b/app/controlplane/atlas.hcl new file mode 100644 index 000000000..71d083c47 --- /dev/null +++ b/app/controlplane/atlas.hcl @@ -0,0 +1,8 @@ +# do not add automatically foreign keys to the generated migrations +env "dev" { + diff { + skip { + add_foreign_key = true + } + } +} \ No newline at end of file diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/20241126164629.sql b/app/controlplane/pkg/data/ent/migrate/migrations/20241126164629.sql new file mode 100644 index 000000000..e677c8d15 --- /dev/null +++ b/app/controlplane/pkg/data/ent/migrate/migrations/20241126164629.sql @@ -0,0 +1,3 @@ +-- remove constraints for performance reasons +ALTER TABLE public.workflow_run_cas_backends DROP CONSTRAINT workflow_run_cas_backends_workflow_run_id; +ALTER TABLE public.workflow_run_cas_backends DROP CONSTRAINT workflow_run_cas_backends_cas_backend_id; \ No newline at end of file diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/20241126182209.sql b/app/controlplane/pkg/data/ent/migrate/migrations/20241126182209.sql new file mode 100644 index 000000000..d5a622641 --- /dev/null +++ b/app/controlplane/pkg/data/ent/migrate/migrations/20241126182209.sql @@ -0,0 +1,3 @@ +-- remove for performance reasons +ALTER TABLE cas_mappings DROP CONSTRAINT cas_mappings_cas_backends_cas_backend; +ALTER TABLE cas_mappings DROP CONSTRAINT cas_mappings_organizations_organization; \ No newline at end of file diff --git a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum index 9a5a528e2..0125613c8 100644 --- a/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum +++ b/app/controlplane/pkg/data/ent/migrate/migrations/atlas.sum @@ -1,4 +1,4 @@ -h1:J//lNzTG1omhRdZO5iV295VWI2N70PBO9u1SqN2Pxj0= +h1:cd7peHu3MdqEo1c6vGrDGeDjSLGEFrPqrrEiSMDZJp0= 20230706165452_init-schema.sql h1:VvqbNFEQnCvUVyj2iDYVQQxDM0+sSXqocpt/5H64k8M= 20230710111950-cas-backend.sql h1:A8iBuSzZIEbdsv9ipBtscZQuaBp3V5/VMw7eZH6GX+g= 20230712094107-cas-backends-workflow-runs.sql h1:a5rzxpVGyd56nLRSsKrmCFc9sebg65RWzLghKHh5xvI= @@ -67,3 +67,5 @@ h1:J//lNzTG1omhRdZO5iV295VWI2N70PBO9u1SqN2Pxj0= 20241122101039.sql h1:RMk8MDWj/RhbVKX9ERHEI96tFFPuMEwNZMk65FanOvM= 20241123161902.sql h1:Nm0Szr+lGbXWCE6KS8aIsd2mz2GadWOuF36o2uHaT70= 20241123163942.sql h1:s+ImKf84B5s3Hp9Q7ILTcbNkQFIveZapu8fSe3X0eLY= +20241126164629.sql h1:TrYF9F2RmBUVVB/9a3XFlintq94b2/BaJLYjv80TXOQ= +20241126182209.sql h1:01eeRbQxKYsjhEvafp1fL4kYJx4NoidwjcxWbWLlNak=