mirror of
https://github.com/djrobstep/migra.git
synced 2024-10-26 07:00:54 +03:00
function deps
This commit is contained in:
parent
2dbb9ac16f
commit
95db7c0a4f
@ -14,7 +14,7 @@ addons:
|
||||
postgresql: "9.6"
|
||||
|
||||
# command to install dependencies
|
||||
install: make pipupgrade
|
||||
install: make pip
|
||||
|
||||
# command to run tests
|
||||
script: make test
|
||||
|
@ -24,11 +24,19 @@ def statements_for_changes(
|
||||
creations_only=False,
|
||||
drops_only=False,
|
||||
modifications=True,
|
||||
dependency_ordering=False):
|
||||
dependency_ordering=False,
|
||||
add_dependents_for_modified=False):
|
||||
|
||||
added, removed, modified, _ = \
|
||||
added, removed, modified, unmodified = \
|
||||
differences(things_from, things_target)
|
||||
|
||||
if add_dependents_for_modified:
|
||||
for k, m in list(modified.items()):
|
||||
for d in m.dependents_all:
|
||||
if d in unmodified:
|
||||
modified[d] = unmodified.pop(d)
|
||||
modified = od(sorted(modified.items()))
|
||||
|
||||
statements = Statements()
|
||||
|
||||
if not creations_only:
|
||||
@ -212,7 +220,11 @@ class Changes(object):
|
||||
avf = od(sorted(avf))
|
||||
bvf = od(sorted(bvf))
|
||||
|
||||
return partial(statements_for_changes, avf, bvf)
|
||||
return partial(
|
||||
statements_for_changes,
|
||||
avf,
|
||||
bvf,
|
||||
add_dependents_for_modified=True)
|
||||
elif name in THINGS:
|
||||
return partial(
|
||||
statements_for_changes,
|
||||
|
@ -7,6 +7,9 @@ from .statements import Statements
|
||||
|
||||
|
||||
class Migration(object):
|
||||
"""
|
||||
The main class of migra
|
||||
"""
|
||||
def __init__(self, x_from, x_target):
|
||||
self.statements = Statements()
|
||||
self.changes = Changes(None, None)
|
||||
|
@ -3,7 +3,8 @@ from __future__ import unicode_literals
|
||||
from collections import OrderedDict as od
|
||||
|
||||
|
||||
def differences(a, b):
|
||||
def differences(a, b, add_dependencies_for_modifications=True):
|
||||
|
||||
a_keys = set(a.keys())
|
||||
b_keys = set(b.keys())
|
||||
|
||||
|
@ -6,6 +6,10 @@ create view bbb_view2 as select name from aaa_view1;
|
||||
|
||||
create view ccc_view3 as select name from bbb_view2;
|
||||
|
||||
create view ddd_changed as select name from basetable;
|
||||
|
||||
create view ddd_unchanged as select name from ddd_changed;
|
||||
|
||||
create or replace function "public"."depends_on_bbb_view2"(t text)
|
||||
returns TABLE(x text) as
|
||||
$$ select * from bbb_view2 $$
|
||||
|
@ -1 +1,5 @@
|
||||
create table basetable(id serial primary key, name text);
|
||||
|
||||
create view ddd_changed as select name, 'x' as x from basetable;
|
||||
|
||||
create view ddd_unchanged as select name from ddd_changed;
|
||||
|
@ -1,15 +1,19 @@
|
||||
alter table "public"."basetable" drop constraint "basetable_pkey";
|
||||
|
||||
drop index if exists "public"."basetable_pkey";
|
||||
|
||||
drop view if exists "public"."ccc_view3" cascade;
|
||||
|
||||
drop function if exists "public"."depends_on_bbb_view2"(t text) cascade;
|
||||
|
||||
drop view if exists "public"."ddd_unchanged" cascade;
|
||||
|
||||
drop view if exists "public"."bbb_view2" cascade;
|
||||
|
||||
drop view if exists "public"."ddd_changed" cascade;
|
||||
|
||||
drop view if exists "public"."aaa_view1" cascade;
|
||||
|
||||
drop table "public"."basetable";
|
||||
create view "public"."ddd_changed" as SELECT basetable.name,
|
||||
'x' AS x
|
||||
FROM basetable;
|
||||
|
||||
drop sequence if exists "public"."basetable_id_seq";
|
||||
|
||||
create view "public"."ddd_unchanged" as SELECT ddd_changed.name
|
||||
FROM ddd_changed;
|
||||
|
@ -1,21 +1,25 @@
|
||||
alter table "public"."basetable" drop constraint "basetable_pkey";
|
||||
|
||||
drop index if exists "public"."basetable_pkey";
|
||||
|
||||
drop view if exists "public"."ccc_view3" cascade;
|
||||
|
||||
drop view if exists "public"."ddd" cascade;
|
||||
|
||||
drop function if exists "public"."depends_on_bbb_view2"(t text) cascade;
|
||||
|
||||
drop view if exists "public"."eee" cascade;
|
||||
|
||||
drop function if exists "public"."fff"(t text) cascade;
|
||||
|
||||
drop view if exists "public"."ddd_unchanged" cascade;
|
||||
|
||||
drop view if exists "public"."bbb_view2" cascade;
|
||||
|
||||
drop view if exists "public"."ddd" cascade;
|
||||
|
||||
drop view if exists "public"."ddd_changed" cascade;
|
||||
|
||||
drop view if exists "public"."aaa_view1" cascade;
|
||||
|
||||
drop table "public"."basetable";
|
||||
create view "public"."ddd_changed" as SELECT basetable.name,
|
||||
'x' AS x
|
||||
FROM basetable;
|
||||
|
||||
drop sequence if exists "public"."basetable_id_seq";
|
||||
|
||||
create view "public"."ddd_unchanged" as SELECT ddd_changed.name
|
||||
FROM ddd_changed;
|
||||
|
@ -87,7 +87,8 @@ def do_fixture_test(fixture_name):
|
||||
m.add_sql(ADDITIONS)
|
||||
m.apply()
|
||||
m.add_all_changes()
|
||||
|
||||
print('x')
|
||||
print(m.sql.strip())
|
||||
assert m.sql.strip() == EXPECTED2 # sql generated OK
|
||||
m.apply()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user