mirror of
https://github.com/djrobstep/migra.git
synced 2024-09-11 13:56:05 +03:00
inheritance tests
This commit is contained in:
parent
2ba2f3209c
commit
44bf8575f7
@ -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
|
||||
|
||||
|
@ -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]
|
||||
|
1
tests/FIXTURES/inherit/a.sql
Normal file
1
tests/FIXTURES/inherit/a.sql
Normal file
@ -0,0 +1 @@
|
||||
create table t(id int);
|
0
tests/FIXTURES/inherit/additions.sql
Normal file
0
tests/FIXTURES/inherit/additions.sql
Normal file
20
tests/FIXTURES/inherit/b.sql
Normal file
20
tests/FIXTURES/inherit/b.sql
Normal 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)
|
||||
;
|
49
tests/FIXTURES/inherit/expected.sql
Normal file
49
tests/FIXTURES/inherit/expected.sql
Normal 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));
|
0
tests/FIXTURES/inherit/expected2.sql
Normal file
0
tests/FIXTURES/inherit/expected2.sql
Normal 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)
|
||||
|
Loading…
Reference in New Issue
Block a user