mirror of
https://github.com/djrobstep/migra.git
synced 2024-09-11 05:45:51 +03:00
Merge 4b7b75e581
into da6671acae
This commit is contained in:
commit
83a4523419
@ -3,6 +3,8 @@ from __future__ import unicode_literals
|
|||||||
from collections import OrderedDict as od
|
from collections import OrderedDict as od
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
from networkx import lexicographical_topological_sort, DiGraph
|
||||||
|
|
||||||
import schemainspect
|
import schemainspect
|
||||||
|
|
||||||
from .statements import Statements
|
from .statements import Statements
|
||||||
@ -21,6 +23,7 @@ THINGS = [
|
|||||||
"collations",
|
"collations",
|
||||||
"rlspolicies",
|
"rlspolicies",
|
||||||
"triggers",
|
"triggers",
|
||||||
|
"comments",
|
||||||
]
|
]
|
||||||
PK = "PRIMARY KEY"
|
PK = "PRIMARY KEY"
|
||||||
|
|
||||||
@ -227,11 +230,23 @@ def get_table_changes(
|
|||||||
|
|
||||||
statements += enums_pre
|
statements += enums_pre
|
||||||
|
|
||||||
for t, v in added.items():
|
# topologial sort of tables using table.dependents
|
||||||
statements.append(v.create_statement)
|
# this is to ensure that tables are created in the correct order
|
||||||
if v.rowsecurity:
|
# so that foreign keys can be created
|
||||||
rls_alter = v.alter_rls_statement
|
|
||||||
statements.append(rls_alter)
|
G = DiGraph()
|
||||||
|
G.add_nodes_from(tables_target.keys())
|
||||||
|
for t, v in tables_target.items():
|
||||||
|
G.add_edges_from((t, d) for d in v.dependents)
|
||||||
|
|
||||||
|
tables_sorted = {k: tables_target[k] for k in lexicographical_topological_sort(G) if k in tables_target}
|
||||||
|
|
||||||
|
for t, v in tables_sorted.items():
|
||||||
|
if t in added:
|
||||||
|
statements.append(v.create_statement)
|
||||||
|
if v.rowsecurity:
|
||||||
|
rls_alter = v.alter_rls_statement
|
||||||
|
statements.append(rls_alter)
|
||||||
|
|
||||||
statements += enums_post
|
statements += enums_post
|
||||||
|
|
||||||
@ -365,7 +380,6 @@ def get_selectable_differences(
|
|||||||
not_replaceable = set()
|
not_replaceable = set()
|
||||||
|
|
||||||
if add_dependents_for_modified:
|
if add_dependents_for_modified:
|
||||||
|
|
||||||
for k, m in changed_all.items():
|
for k, m in changed_all.items():
|
||||||
old = selectables_from[k]
|
old = selectables_from[k]
|
||||||
|
|
||||||
@ -478,7 +492,7 @@ def get_selectable_changes(
|
|||||||
statements = Statements()
|
statements = Statements()
|
||||||
|
|
||||||
def functions(d):
|
def functions(d):
|
||||||
return {k: v for k, v in d.items() if v.relationtype == "f"}
|
return {k: v for k, v in d.items() if v.relationtype in ("f", "a")}
|
||||||
|
|
||||||
if not tables_only:
|
if not tables_only:
|
||||||
if not creations_only:
|
if not creations_only:
|
||||||
@ -656,6 +670,15 @@ class Changes(object):
|
|||||||
modifications=False,
|
modifications=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def comments(self):
|
||||||
|
return partial(
|
||||||
|
statements_for_changes,
|
||||||
|
self.i_from.comments,
|
||||||
|
self.i_target.comments,
|
||||||
|
modifications=False,
|
||||||
|
)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
if name in THINGS:
|
if name in THINGS:
|
||||||
return partial(
|
return partial(
|
||||||
|
@ -85,6 +85,7 @@ class Migration(object):
|
|||||||
self.add(self.changes.extensions(drops_only=True))
|
self.add(self.changes.extensions(drops_only=True))
|
||||||
|
|
||||||
def add_all_changes(self, privileges=False):
|
def add_all_changes(self, privileges=False):
|
||||||
|
self.add(self.changes.comments(drops_only=True))
|
||||||
self.add(self.changes.schemas(creations_only=True))
|
self.add(self.changes.schemas(creations_only=True))
|
||||||
|
|
||||||
self.add(self.changes.extensions(creations_only=True, modifications=False))
|
self.add(self.changes.extensions(creations_only=True, modifications=False))
|
||||||
@ -122,6 +123,7 @@ class Migration(object):
|
|||||||
self.add(self.changes.triggers(creations_only=True))
|
self.add(self.changes.triggers(creations_only=True))
|
||||||
self.add(self.changes.collations(drops_only=True))
|
self.add(self.changes.collations(drops_only=True))
|
||||||
self.add(self.changes.schemas(drops_only=True))
|
self.add(self.changes.schemas(drops_only=True))
|
||||||
|
self.add(self.changes.comments(creations_only=True))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def sql(self):
|
def sql(self):
|
||||||
|
939
poetry.lock
generated
939
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@ -10,12 +10,13 @@ repository = "https://github.com/djrobstep/migra"
|
|||||||
homepage = "https://databaseci.com/docs/migra"
|
homepage = "https://databaseci.com/docs/migra"
|
||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.7,<4"
|
python = ">=3.8,<4"
|
||||||
sqlbag = "*"
|
sqlbag = "*"
|
||||||
six = "*"
|
six = "*"
|
||||||
# schemainspect = {path="../schemainspect", develop=true}
|
#schemainspect = { path = "../schemainspect", develop = true }
|
||||||
schemainspect = ">=3.1.1663480743"
|
schemainspect = { git = "https://github.com/joshainglis/schemainspect.git", rev = "eeda5c18d26fce006a826cfe63f8683b4490a321" }
|
||||||
psycopg2-binary = { version="*", optional = true }
|
psycopg2-binary = { version="*", optional = true }
|
||||||
|
networkx = "^3.1"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
sqlbag = "*"
|
sqlbag = "*"
|
||||||
|
Loading…
Reference in New Issue
Block a user