From c08064b3020b3df5757f1815bf8151e090b17867 Mon Sep 17 00:00:00 2001 From: Robert Lechte Date: Wed, 13 Jan 2021 11:50:40 +1100 Subject: [PATCH] better deferrable handling --- pyproject.toml | 2 +- tests/FIXTURES/constraints/a.sql | 9 +++++++ tests/FIXTURES/constraints/additions.sql | 0 tests/FIXTURES/constraints/b.sql | 13 ++++++++++ tests/FIXTURES/constraints/expected.sql | 33 ++++++++++++++++++++++++ tests/FIXTURES/constraints/expected2.sql | 0 tests/test_migra.py | 1 + 7 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tests/FIXTURES/constraints/a.sql create mode 100644 tests/FIXTURES/constraints/additions.sql create mode 100644 tests/FIXTURES/constraints/b.sql create mode 100644 tests/FIXTURES/constraints/expected.sql create mode 100644 tests/FIXTURES/constraints/expected2.sql diff --git a/pyproject.toml b/pyproject.toml index 27e4b9b..19d6b0b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ python = "*" sqlbag = "*" six = "*" # schemainspect = {path="../schemainspect"} -schemainspect = ">=0.1.1603009162" +schemainspect = ">=0.1.1610498640" psycopg2-binary = { version="*", optional = true } [tool.poetry.dev-dependencies] diff --git a/tests/FIXTURES/constraints/a.sql b/tests/FIXTURES/constraints/a.sql new file mode 100644 index 0000000..dd362d6 --- /dev/null +++ b/tests/FIXTURES/constraints/a.sql @@ -0,0 +1,9 @@ +create table t1(a int); + +create table b(bb int primary key); + +create table t2(a int primary key, bb int references b(bb), price numeric, constraint x check (price > 0)); + +create table c(cc int unique); + +create unique index on t1(a); \ No newline at end of file diff --git a/tests/FIXTURES/constraints/additions.sql b/tests/FIXTURES/constraints/additions.sql new file mode 100644 index 0000000..e69de29 diff --git a/tests/FIXTURES/constraints/b.sql b/tests/FIXTURES/constraints/b.sql new file mode 100644 index 0000000..b3a310b --- /dev/null +++ b/tests/FIXTURES/constraints/b.sql @@ -0,0 +1,13 @@ +create table b(bb int primary key); + +create table t2(a int, bb int references b(bb) DEFERRABLE INITIALLY deferred); + +create table t1(a int primary key, price numeric, constraint x check (price > 0)); + +create table c(cc int unique); + +CREATE UNIQUE INDEX c_pkey ON public.c USING btree (cc); + +alter table "public"."c" add constraint "c_pkey" PRIMARY KEY using index "c_pkey" deferrable INITIALLY deferred; + +create unique index on t2(a); \ No newline at end of file diff --git a/tests/FIXTURES/constraints/expected.sql b/tests/FIXTURES/constraints/expected.sql new file mode 100644 index 0000000..9510e48 --- /dev/null +++ b/tests/FIXTURES/constraints/expected.sql @@ -0,0 +1,33 @@ +alter table "public"."t2" drop constraint "x"; + +alter table "public"."t2" drop constraint "t2_bb_fkey"; + +alter table "public"."t2" drop constraint "t2_pkey"; + +drop index if exists "public"."t1_a_idx"; + +drop index if exists "public"."t2_pkey"; + +alter table "public"."c" alter column "cc" set not null; + +alter table "public"."t1" add column "price" numeric; + +alter table "public"."t1" alter column "a" set not null; + +alter table "public"."t2" drop column "price"; + +alter table "public"."t2" alter column "a" drop not null; + +CREATE UNIQUE INDEX c_pkey ON public.c USING btree (cc); + +CREATE UNIQUE INDEX t1_pkey ON public.t1 USING btree (a); + +CREATE UNIQUE INDEX t2_a_idx ON public.t2 USING btree (a); + +alter table "public"."c" add constraint "c_pkey" PRIMARY KEY using index "c_pkey" DEFERRABLE INITIALLY DEFERRED; + +alter table "public"."t1" add constraint "t1_pkey" PRIMARY KEY using index "t1_pkey"; + +alter table "public"."t1" add constraint "x" CHECK ((price > (0)::numeric)); + +alter table "public"."t2" add constraint "t2_bb_fkey" FOREIGN KEY (bb) REFERENCES b(bb) DEFERRABLE INITIALLY DEFERRED; \ No newline at end of file diff --git a/tests/FIXTURES/constraints/expected2.sql b/tests/FIXTURES/constraints/expected2.sql new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_migra.py b/tests/test_migra.py index 165b886..94bb11d 100644 --- a/tests/test_migra.py +++ b/tests/test_migra.py @@ -78,6 +78,7 @@ dependencies dependencies2 dependencies3 dependencies4 +constraints """.split() # fixtures = [(_, ) for _ in fixtures]