improved enum deps

This commit is contained in:
Robert Lechte 2020-07-24 16:11:21 +10:00
parent 320365f779
commit 86506ee3b5
8 changed files with 49 additions and 3 deletions

View File

@ -280,6 +280,8 @@ def get_selectable_differences(
other_from, other_target
)
_, _, modified_enums, _ = differences(enums_from, enums_target)
changed_all = {}
changed_all.update(modified_tables)
changed_all.update(modified_other)
@ -291,12 +293,16 @@ def get_selectable_differences(
not_replaceable = set()
if add_dependents_for_modified:
for k, m in changed_all.items():
old = selectables_from[k]
if k in modified_all and m.can_replace(old):
if not m.is_table:
replaceable.add(k)
changed_enums = [_ for _ in m.dependent_on if _ in modified_enums]
if not changed_enums:
replaceable.add(k)
continue
for d in m.dependents_all:

View File

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

View File

@ -0,0 +1,7 @@
create type e as enum('a', 'b', 'c');
create table t(id integer primary key, category e);
create view v as select * from t;
create view v2 as select *, 'b'::e from t;

View File

View File

@ -0,0 +1,7 @@
create type e as enum('a', 'b', 'c', 'd');
create table t(id integer primary key, category e);
create view v as select * from t;
create view v2 as select *, 'b'::e from t;

View File

@ -0,0 +1,21 @@
drop view if exists "public"."v";
drop view if exists "public"."v2";
alter type "public"."e" rename to "e__old_version_to_be_dropped";
create type "public"."e" as enum ('a', 'b', 'c', 'd');
alter table "public"."t" alter column category type "public"."e" using category::text::"public"."e";
drop type "public"."e__old_version_to_be_dropped";
create or replace view "public"."v" as SELECT t.id,
t.category
FROM t;
create or replace view "public"."v2" as SELECT t.id,
t.category,
'b'::e AS e
FROM t;

View File

View File

@ -89,6 +89,11 @@ def test_enumdefaults():
do_fixture_test(FIXTURE_NAME, with_privileges=True)
def test_enumdeps():
for FIXTURE_NAME in ["enumdeps"]:
do_fixture_test(FIXTURE_NAME, with_privileges=True)
def test_sequences():
for FIXTURE_NAME in ["seq"]:
do_fixture_test(FIXTURE_NAME, with_privileges=True)