inheritance tests

This commit is contained in:
Robert Lechte 2019-12-18 22:54:43 +11:00
parent 2ba2f3209c
commit 44bf8575f7
8 changed files with 79 additions and 3 deletions

View File

@ -1,8 +1,9 @@
from __future__ import unicode_literals
from schemainspect import DBInspector, get_inspector
from sqlbag import raw_execute
from schemainspect import DBInspector, get_inspector
from .changes import Changes
from .statements import Statements

View File

@ -13,7 +13,7 @@ homepage = "https://migra.djrobstep.com/"
python = "*"
sqlbag = "*"
six = "*"
schemainspect = ">=0.1.1575949847"
schemainspect = ">=0.1.1576669988"
psycopg2-binary = { version="*", optional = true }
[tool.poetry.dev-dependencies]

View File

@ -0,0 +1 @@
create table t(id int);

View File

View File

@ -0,0 +1,20 @@
CREATE TABLE entity_bindings (
id BIGSERIAL,
entity_type TEXT NOT NULL,
entity_id BIGINT NOT NULL
);
CREATE TABLE entity_bindings_A (
CONSTRAINT "entity_type must be A" CHECK("entity_type" = 'A'),
UNIQUE("entity_id", "entity_type")
) INHERITS (entity_bindings)
;
CREATE TABLE entity_bindings_B (
CONSTRAINT "entity_type must be B" CHECK("entity_type" = 'B'),
UNIQUE("entity_id", "entity_type")
) INHERITS (entity_bindings)
;
CREATE TABLE entity_bindings_C (
CONSTRAINT "entity_type must be C" CHECK("entity_type" = 'C'),
UNIQUE("entity_id", "entity_type")
) INHERITS (entity_bindings)
;

View File

@ -0,0 +1,49 @@
create sequence "public"."entity_bindings_id_seq";
drop table "public"."t";
create table "public"."entity_bindings" (
"id" bigint not null default nextval('entity_bindings_id_seq'::regclass),
"entity_type" text not null,
"entity_id" bigint not null
);
create table "public"."entity_bindings_a" (
"id" bigint not null default nextval('entity_bindings_id_seq'::regclass),
"entity_type" text not null,
"entity_id" bigint not null
) inherits ("public"."entity_bindings");
create table "public"."entity_bindings_b" (
"id" bigint not null default nextval('entity_bindings_id_seq'::regclass),
"entity_type" text not null,
"entity_id" bigint not null
) inherits ("public"."entity_bindings");
create table "public"."entity_bindings_c" (
"id" bigint not null default nextval('entity_bindings_id_seq'::regclass),
"entity_type" text not null,
"entity_id" bigint not null
) inherits ("public"."entity_bindings");
CREATE UNIQUE INDEX entity_bindings_a_entity_id_entity_type_key ON public.entity_bindings_a USING btree (entity_id, entity_type);
CREATE UNIQUE INDEX entity_bindings_b_entity_id_entity_type_key ON public.entity_bindings_b USING btree (entity_id, entity_type);
CREATE UNIQUE INDEX entity_bindings_c_entity_id_entity_type_key ON public.entity_bindings_c USING btree (entity_id, entity_type);
alter table "public"."entity_bindings_a" add constraint "entity_bindings_a_entity_id_entity_type_key" UNIQUE using index "entity_bindings_a_entity_id_entity_type_key";
alter table "public"."entity_bindings_a" add constraint "entity_type must be A" CHECK ((entity_type = 'A'::text));
alter table "public"."entity_bindings_b" add constraint "entity_bindings_b_entity_id_entity_type_key" UNIQUE using index "entity_bindings_b_entity_id_entity_type_key";
alter table "public"."entity_bindings_b" add constraint "entity_type must be B" CHECK ((entity_type = 'B'::text));
alter table "public"."entity_bindings_c" add constraint "entity_bindings_c_entity_id_entity_type_key" UNIQUE using index "entity_bindings_c_entity_id_entity_type_key";
alter table "public"."entity_bindings_c" add constraint "entity_type must be C" CHECK ((entity_type = 'C'::text));

View File

View File

@ -3,11 +3,11 @@ from __future__ import unicode_literals
import io
from pytest import raises
from schemainspect import get_inspector
from sqlbag import S, load_sql_from_file, temporary_database
from migra import Migration, Statements, UnsafeMigrationException
from migra.command import parse_args, run
from schemainspect import get_inspector
SQL = """select 1;
@ -49,6 +49,11 @@ def test_partitioning():
do_fixture_test(FIXTURE_NAME)
def test_inherit():
for FIXTURE_NAME in ["inherit"]:
do_fixture_test(FIXTURE_NAME)
def test_collations():
for FIXTURE_NAME in ["collations"]:
do_fixture_test(FIXTURE_NAME)