better deferrable handling

This commit is contained in:
Robert Lechte 2021-01-13 11:50:40 +11:00
parent a0b580eb14
commit c08064b302
7 changed files with 57 additions and 1 deletions

View File

@ -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]

View File

@ -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);

View File

View File

@ -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);

View File

@ -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;

View File

View File

@ -78,6 +78,7 @@ dependencies
dependencies2
dependencies3
dependencies4
constraints
""".split()
# fixtures = [(_, ) for _ in fixtures]