umf-access 0.1.0.dev8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- umf_access/__init__.py +109 -0
- umf_access/adoption.py +41 -0
- umf_access/build/__init__.py +2 -0
- umf_access/build/approximate.py +34 -0
- umf_access/build/catalog.py +1626 -0
- umf_access/build/commands.py +394 -0
- umf_access/build/pg_privileges.py +1544 -0
- umf_access/build/privileges.py +134 -0
- umf_access/build/search.py +365 -0
- umf_access/build/unity_search.py +104 -0
- umf_access/bulk.py +227 -0
- umf_access/canonical.py +23 -0
- umf_access/capture.py +410 -0
- umf_access/catalog.py +325 -0
- umf_access/codec_support.py +427 -0
- umf_access/commands.py +93 -0
- umf_access/delta_read.py +758 -0
- umf_access/dsl/__init__.py +148 -0
- umf_access/dsl/_context.py +36 -0
- umf_access/dsl/_expressions.py +625 -0
- umf_access/dsl/_joined.py +4 -0
- umf_access/dsl/_nodes.py +207 -0
- umf_access/dsl/_query.py +5559 -0
- umf_access/dsl/_selection.py +143 -0
- umf_access/dsl/navigation.py +302 -0
- umf_access/dsl/render.py +516 -0
- umf_access/dsl/search.py +343 -0
- umf_access/engine_catalog.py +563 -0
- umf_access/generated_core.py +5 -0
- umf_access/lifecycle/__init__.py +46 -0
- umf_access/lifecycle/_darwin_process_observer.c +306 -0
- umf_access/lifecycle/approval.py +366 -0
- umf_access/lifecycle/backfills.py +79 -0
- umf_access/lifecycle/catalog.py +289 -0
- umf_access/lifecycle/cli.py +231 -0
- umf_access/lifecycle/concurrent.py +196 -0
- umf_access/lifecycle/conversion_policy.py +188 -0
- umf_access/lifecycle/correspondence.py +203 -0
- umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
- umf_access/lifecycle/generation_authority_session.py +125 -0
- umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
- umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
- umf_access/lifecycle/generation_ingress.py +185 -0
- umf_access/lifecycle/generation_root_registry.py +138 -0
- umf_access/lifecycle/head.py +250 -0
- umf_access/lifecycle/head_view.py +81 -0
- umf_access/lifecycle/host.py +1183 -0
- umf_access/lifecycle/ingress_custody.py +750 -0
- umf_access/lifecycle/ingress_local_postgres.py +7990 -0
- umf_access/lifecycle/ingress_store.py +1488 -0
- umf_access/lifecycle/ledger.py +276 -0
- umf_access/lifecycle/ledger_schema.py +116 -0
- umf_access/lifecycle/mixed.py +593 -0
- umf_access/lifecycle/outcome_schema.py +136 -0
- umf_access/lifecycle/owner_approval_core.py +1810 -0
- umf_access/lifecycle/owner_authority.py +472 -0
- umf_access/lifecycle/owner_bootstrap.py +2077 -0
- umf_access/lifecycle/owner_wire.py +161 -0
- umf_access/lifecycle/phase_fence.py +52 -0
- umf_access/lifecycle/phase_policy.py +422 -0
- umf_access/lifecycle/privileges.py +145 -0
- umf_access/lifecycle/probe.py +39 -0
- umf_access/lifecycle/progress.py +497 -0
- umf_access/lifecycle/roles.py +96 -0
- umf_access/lifecycle/row_originals.py +1712 -0
- umf_access/lifecycle/row_originals_creation.py +759 -0
- umf_access/lifecycle/row_originals_receipt.py +413 -0
- umf_access/lifecycle/seeds.py +99 -0
- umf_access/lifecycle/sql_containment.py +358 -0
- umf_access/lifecycle/sql_containment_cli.py +33 -0
- umf_access/lifecycle/sql_containment_parser.py +20 -0
- umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
- umf_access/lifecycle/table_boundary.py +22 -0
- umf_access/lifecycle/target_custody_codec.py +788 -0
- umf_access/lifecycle/witness.py +72 -0
- umf_access/managed_actions.py +271 -0
- umf_access/managed_bulk.py +353 -0
- umf_access/managed_delta.py +150 -0
- umf_access/managed_support.py +166 -0
- umf_access/manifest_commands.py +278 -0
- umf_access/native_actions.py +1007 -0
- umf_access/native_program.py +570 -0
- umf_access/pages.py +125 -0
- umf_access/postgres_bulk.py +509 -0
- umf_access/postgres_read.py +1230 -0
- umf_access/postgres_search.py +639 -0
- umf_access/protocols.py +665 -0
- umf_access/py.typed +0 -0
- umf_access/related_keys.py +233 -0
- umf_access/reviewed.py +706 -0
- umf_access/search_catalog.py +122 -0
- umf_access/targets.py +312 -0
- umf_access/types.py +220 -0
- umf_access/unified/__init__.py +187 -0
- umf_access/unified/_binding.py +654 -0
- umf_access/unified/head_session.py +144 -0
- umf_access/unified/native_binding.py +143 -0
- umf_access/unified/operation_values.py +173 -0
- umf_access/unified/outcome_values.py +76 -0
- umf_access/unified/session_async.py +161 -0
- umf_access/unified/session_binding.py +108 -0
- umf_access/unified/session_policy.py +152 -0
- umf_access/unified/session_psycopg2.py +70 -0
- umf_access/unified/session_sqlalchemy.py +161 -0
- umf_access/unified/session_sync.py +148 -0
- umf_access/unified/table_reads.py +314 -0
- umf_access/unified/table_writes.py +193 -0
- umf_access/unity_search.py +312 -0
- umf_access/values.py +280 -0
- umf_access/verification.py +64 -0
- umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
- umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
- umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
- umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Durable, source-bound runner for ordered mixed transactional phases."""
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import hashlib
|
|
6
|
+
import json
|
|
7
|
+
import re
|
|
8
|
+
|
|
9
|
+
from .approval import APPROVAL_PROFILE, _verify_approval_relation
|
|
10
|
+
from .catalog import CatalogError, _all, _execute, _installation, _one, _q
|
|
11
|
+
from .concurrent import _index_state
|
|
12
|
+
from .head_view import HEAD
|
|
13
|
+
from .ledger import (
|
|
14
|
+
_authorize_new_effects,
|
|
15
|
+
_finalize_phased_migration,
|
|
16
|
+
_history_rows,
|
|
17
|
+
_verified_plan,
|
|
18
|
+
_verify_installed,
|
|
19
|
+
)
|
|
20
|
+
from .ledger_schema import HISTORY, _verify_history_schema
|
|
21
|
+
from .outcome_schema import OUTCOMES, _verify_outcomes
|
|
22
|
+
from .phase_fence import _head_grants, _verify_phase_head
|
|
23
|
+
from .privileges import _EXTERNAL
|
|
24
|
+
from .progress import (
|
|
25
|
+
PROGRESS,
|
|
26
|
+
_assert_progress_binding,
|
|
27
|
+
_delete_progress,
|
|
28
|
+
_drop_progress,
|
|
29
|
+
_phase_digest,
|
|
30
|
+
_progress_rows,
|
|
31
|
+
_verified_phases,
|
|
32
|
+
_verify_progress_schema,
|
|
33
|
+
_write_progress,
|
|
34
|
+
)
|
|
35
|
+
from .roles import verify_native_role_scope
|
|
36
|
+
from .table_boundary import TABLE_BOUNDARY
|
|
37
|
+
from .witness import _capture_witness
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _phase_steps(plan, phase):
|
|
41
|
+
by_id = {step['id']: step for step in plan['steps']}
|
|
42
|
+
return [by_id[step_id] for step_id in phase['steps']]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _phase_hash(plan, phase):
|
|
46
|
+
return _phase_digest(phase, _phase_steps(plan, phase))
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _source_at_phase_prefix(plan, phase_index):
|
|
50
|
+
"""Select the source image represented by a durable G11 phase prefix."""
|
|
51
|
+
if plan.get('options', {}).get('version') == 'umf.table-migration-options/0.6':
|
|
52
|
+
if phase_index == 0:
|
|
53
|
+
source = plan.get('previous')
|
|
54
|
+
if type(source) is not dict:
|
|
55
|
+
raise CatalogError('mixed-phase-profile')
|
|
56
|
+
return source
|
|
57
|
+
if phase_index == 1 and len(plan.get('phases', [])) == 1:
|
|
58
|
+
return plan['next']
|
|
59
|
+
raise CatalogError('mixed-phase-profile')
|
|
60
|
+
return plan['next']
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _verify_phase_source_boundary(connection, plan, person_roles, source, *,
|
|
64
|
+
progress_required=True):
|
|
65
|
+
"""Verify a source-bound catalog side under the phase locks."""
|
|
66
|
+
_verify_native_source_boundary(
|
|
67
|
+
connection, source, plan.get('approvalProfile'), person_roles,
|
|
68
|
+
progress_required=progress_required)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _verify_mixed_prefix(connection, plan, receipt):
|
|
72
|
+
"""Verify the source-derived completed phase prefix before any resume work.
|
|
73
|
+
|
|
74
|
+
The first receipt is admitted only after full predecessor verification. Each
|
|
75
|
+
later receipt commits atomically with its exact source-regenerated phase;
|
|
76
|
+
equality to its captured native witness detects any intervening drift.
|
|
77
|
+
"""
|
|
78
|
+
phases = _verified_phases(plan)
|
|
79
|
+
index = receipt['phaseIndex']
|
|
80
|
+
if type(index) is not int or not 0 <= index <= len(phases):
|
|
81
|
+
raise CatalogError('progress-state-mismatch')
|
|
82
|
+
completed = [step_id for phase in phases[:index] for step_id in phase['steps']]
|
|
83
|
+
if receipt['completedSteps'] != completed:
|
|
84
|
+
raise CatalogError('progress-phase-mismatch')
|
|
85
|
+
if receipt['state'] == 'intent':
|
|
86
|
+
if index >= len(phases) or phases[index]['kind'] != 'concurrent-index' or receipt['phaseDigest'] != _phase_hash(plan, phases[index]):
|
|
87
|
+
raise CatalogError('progress-phase-mismatch')
|
|
88
|
+
elif receipt['state'] in ('ready','complete'):
|
|
89
|
+
expected = _phase_hash(plan, phases[index-1]) if index else hashlib.sha256(b'').hexdigest()
|
|
90
|
+
if receipt['phaseDigest'] != expected:
|
|
91
|
+
raise CatalogError('progress-phase-mismatch')
|
|
92
|
+
else:
|
|
93
|
+
raise CatalogError('progress-state-mismatch')
|
|
94
|
+
current_witness = _capture_witness(connection,
|
|
95
|
+
_source_at_phase_prefix(plan, index))
|
|
96
|
+
expected_witness = (_without_concurrent_effect(current_witness, plan, phases[index])
|
|
97
|
+
if receipt['state'] == 'intent' else current_witness)
|
|
98
|
+
if type(receipt['prefixWitness']) is not dict or expected_witness != receipt['prefixWitness']:
|
|
99
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
100
|
+
bundle = _source_at_phase_prefix(plan, index)
|
|
101
|
+
# The fixed metadata relation set is explicit. App relations may only be
|
|
102
|
+
# names in the source image represented by this durable phase prefix.
|
|
103
|
+
_verify_source_metadata_inventory(connection, bundle,
|
|
104
|
+
plan.get('approvalProfile'))
|
|
105
|
+
if plan.get('approvalProfile') == APPROVAL_PROFILE:
|
|
106
|
+
_verify_approval_relation(connection, bundle)
|
|
107
|
+
_verify_history_schema(connection, bundle)
|
|
108
|
+
_verify_progress_schema(connection, bundle)
|
|
109
|
+
_verify_outcomes(connection, bundle)
|
|
110
|
+
_verify_phase_head(connection, bundle)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _verify_mixed_metadata_inventory(connection, plan, *, progress_required=True):
|
|
114
|
+
return _verify_source_metadata_inventory(
|
|
115
|
+
connection, plan['next'], plan.get('approvalProfile'),
|
|
116
|
+
progress_required=progress_required)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _verify_source_metadata_inventory(connection, bundle, approval_profile, *,
|
|
120
|
+
progress_required=True):
|
|
121
|
+
schema = bundle['configuration']['schema']
|
|
122
|
+
rows = _all(connection, "SELECT c.relname,c.relkind FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE n.nspname=%s AND c.relkind IN ('r','p','v','m','S','f') ORDER BY c.relname", (schema,))
|
|
123
|
+
fixed = {HISTORY:'r', OUTCOMES:'r', HEAD:'v'}
|
|
124
|
+
if progress_required:
|
|
125
|
+
fixed[PROGRESS] = 'r'
|
|
126
|
+
if approval_profile == APPROVAL_PROFILE:
|
|
127
|
+
fixed[APPROVAL_PROFILE['relation']] = 'r'
|
|
128
|
+
actual_fixed = {name:kind for name,kind in rows if name in fixed}
|
|
129
|
+
if actual_fixed != fixed:
|
|
130
|
+
raise CatalogError('progress-inventory-mismatch')
|
|
131
|
+
app_names = {table['name'] for table in bundle['expectedCatalog']['tables']}
|
|
132
|
+
if any(name not in app_names and name not in fixed for name, _ in rows):
|
|
133
|
+
raise CatalogError('progress-inventory-mismatch')
|
|
134
|
+
if approval_profile == APPROVAL_PROFILE:
|
|
135
|
+
_verify_approval_relation(connection, bundle)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _without_concurrent_effect(witness, plan, phase):
|
|
139
|
+
"""Remove only the selected source index from a prefix snapshot."""
|
|
140
|
+
result = json.loads(json.dumps(witness))
|
|
141
|
+
bundle = plan['next']
|
|
142
|
+
for step in _phase_steps(plan, phase):
|
|
143
|
+
parts = step['sourcePath'].split('/')
|
|
144
|
+
if len(parts) < 9 or parts[5] != 'tables':
|
|
145
|
+
raise CatalogError('mixed-phase-profile')
|
|
146
|
+
table = bundle['expectedCatalog']['tables'][int(parts[6])]
|
|
147
|
+
index = table['indexes'][int(parts[8])]
|
|
148
|
+
for item in result['tables']:
|
|
149
|
+
if item['id'] == table['id']:
|
|
150
|
+
item['indexes'] = [row for row in item['indexes'] if row[0] != index['name']]
|
|
151
|
+
break
|
|
152
|
+
return result
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _verify_index_shape(connection, bundle, step):
|
|
156
|
+
"""Require the exact valid native index selected by the source step."""
|
|
157
|
+
from uuid import uuid4
|
|
158
|
+
|
|
159
|
+
parts = step['sourcePath'].split('/')
|
|
160
|
+
table = bundle['expectedCatalog']['tables'][int(parts[6])]
|
|
161
|
+
index = table['indexes'][int(parts[8])]
|
|
162
|
+
actual = _index_state(connection, bundle['configuration']['schema'], table['name'], index['name'])
|
|
163
|
+
if actual is None:
|
|
164
|
+
return False
|
|
165
|
+
if actual[6] is not True:
|
|
166
|
+
raise CatalogError('invalid-index-repair-required')
|
|
167
|
+
schema = bundle['configuration']['schema']
|
|
168
|
+
temporary = 'umf_verify_'+uuid4().hex
|
|
169
|
+
relation = _q(schema)+'.'+_q(temporary)
|
|
170
|
+
columns = [c['definitionSql'] for c in bundle['expectedCatalog']['columns'] if c['table'] == table['id']]
|
|
171
|
+
_execute(connection, 'CREATE TABLE '+relation+' ('+', '.join(columns)+')')
|
|
172
|
+
name = 'umf_verify_'+uuid4().hex
|
|
173
|
+
expected = next(item for item in bundle['expectedCatalog']['indexes'] if item['table'] == table['id'] and item['id'] == index['id'])
|
|
174
|
+
_execute(connection, 'CREATE '+('UNIQUE ' if index['unique'] else '')+'INDEX '+_q(name)+' ON '+relation+' '+expected['definitionSql'])
|
|
175
|
+
from .catalog import _index_shapes
|
|
176
|
+
reference = _index_shapes(connection, schema, temporary, {})[name]
|
|
177
|
+
_execute(connection, 'DROP TABLE '+relation)
|
|
178
|
+
if any(left != right for i, (left, right) in enumerate(zip(actual, reference, strict=True)) if i not in (6,7,8)):
|
|
179
|
+
raise CatalogError('index-shape-mismatch')
|
|
180
|
+
return True
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def _lock_phase_tables(connection, plan):
|
|
184
|
+
bundle = plan['next']
|
|
185
|
+
schema = bundle['configuration']['schema']
|
|
186
|
+
for table in bundle['expectedCatalog']['tables']:
|
|
187
|
+
exists = _one(connection, "SELECT EXISTS(SELECT FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE n.nspname=%s AND c.relname=%s AND c.relkind='r')",
|
|
188
|
+
(schema, table['name']))
|
|
189
|
+
if exists == (True,):
|
|
190
|
+
_execute(connection, 'LOCK TABLE '+_q(schema)+'.'+_q(table['name'])+' IN ACCESS EXCLUSIVE MODE')
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _verify_phase_execution_boundary(connection, plan, person_roles, *,
|
|
194
|
+
progress_required=True):
|
|
195
|
+
"""Recheck source-independent execution and authority boundaries under locks.
|
|
196
|
+
|
|
197
|
+
The phase witness binds the intentional partial source prefix. This check
|
|
198
|
+
independently rejects native triggers/rules, external incoming references,
|
|
199
|
+
changed schema ACLs, unexpected app relations, and newly widened role
|
|
200
|
+
authority before any next source-authored data or DDL effect can run.
|
|
201
|
+
"""
|
|
202
|
+
return _verify_native_source_boundary(
|
|
203
|
+
connection, plan['next'], plan.get('approvalProfile'), person_roles,
|
|
204
|
+
progress_required=progress_required)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def _verify_native_source_boundary(connection, bundle, approval_profile,
|
|
208
|
+
person_roles, *, progress_required=True):
|
|
209
|
+
"""Verify native boundaries against exactly one typed source bundle."""
|
|
210
|
+
schema = bundle['configuration']['schema']
|
|
211
|
+
cfg = bundle['configuration']
|
|
212
|
+
_verify_source_metadata_inventory(connection, bundle, approval_profile,
|
|
213
|
+
progress_required=progress_required)
|
|
214
|
+
_verify_history_schema(connection, bundle)
|
|
215
|
+
_verify_outcomes(connection, bundle)
|
|
216
|
+
if progress_required:
|
|
217
|
+
_verify_progress_schema(connection, bundle)
|
|
218
|
+
_verify_phase_head(connection, bundle)
|
|
219
|
+
relation_ids = []
|
|
220
|
+
for table in bundle['expectedCatalog']['tables']:
|
|
221
|
+
row = _one(connection, """SELECT c.oid,c.relkind,c.relam FROM pg_catalog.pg_class c
|
|
222
|
+
JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE n.nspname=%s AND c.relname=%s""",
|
|
223
|
+
(schema, table['name']))
|
|
224
|
+
heap = _one(connection, "SELECT oid FROM pg_catalog.pg_am WHERE amname='heap'")[0]
|
|
225
|
+
if row is None or row[1:] != ('r', heap):
|
|
226
|
+
raise CatalogError('phase-table-boundary-mismatch')
|
|
227
|
+
relation_ids.append(row[0])
|
|
228
|
+
owner_id = _one(connection, 'SELECT oid FROM pg_catalog.pg_roles WHERE rolname=%s', (cfg['ownerRole'],))[0]
|
|
229
|
+
for table in bundle['expectedCatalog']['tables']:
|
|
230
|
+
boundary = _one(connection, TABLE_BOUNDARY, (relation_ids, relation_ids, schema, table['name']))
|
|
231
|
+
if boundary != ('r','p',True,True,False,False,False,'d',owner_id,
|
|
232
|
+
_one(connection,"SELECT oid FROM pg_catalog.pg_am WHERE amname='heap'")[0],
|
|
233
|
+
False,8,False,False):
|
|
234
|
+
raise CatalogError('phase-table-boundary-mismatch')
|
|
235
|
+
schema_id = _one(connection, 'SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=%s', (schema,))[0]
|
|
236
|
+
actual_acl = _all(connection, """SELECT x.grantor,x.grantee,x.privilege_type,x.is_grantable
|
|
237
|
+
FROM pg_catalog.pg_namespace n,LATERAL pg_catalog.aclexplode(COALESCE(n.nspacl,pg_catalog.acldefault('n',n.nspowner))) x
|
|
238
|
+
WHERE n.oid=%s ORDER BY 1,2,3,4""", (schema_id,))
|
|
239
|
+
expected_acl = _all(connection, """SELECT grantor,grantee,privilege_type,is_grantable
|
|
240
|
+
FROM pg_catalog.aclexplode(pg_catalog.acldefault('n',%s::pg_catalog.oid))""", (owner_id,))
|
|
241
|
+
for key in ('personRole','batchRole'):
|
|
242
|
+
role_id = _one(connection, 'SELECT oid FROM pg_catalog.pg_roles WHERE rolname=%s', (cfg[key],))[0]
|
|
243
|
+
expected_acl.append((owner_id, role_id, 'USAGE', False))
|
|
244
|
+
if actual_acl != sorted(expected_acl):
|
|
245
|
+
raise CatalogError('phase-schema-privilege-mismatch')
|
|
246
|
+
verify_native_role_scope(connection, bundle, person_roles=person_roles)
|
|
247
|
+
for name in (cfg['ownerRole'],cfg['personRole'],cfg['batchRole']):
|
|
248
|
+
role_id = _one(connection, 'SELECT oid FROM pg_catalog.pg_roles WHERE rolname=%s', (name,))[0]
|
|
249
|
+
if _one(connection, _EXTERNAL,
|
|
250
|
+
(role_id,schema,role_id,schema,role_id,role_id,schema,role_id,role_id,role_id,role_id,role_id)) != (False,):
|
|
251
|
+
raise CatalogError('phase-external-authority-present')
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def _run_required_phase(connection, plan, phase, person_roles, *, statement_timeout_ms, lock_timeout_ms):
|
|
255
|
+
bundle = plan['next']
|
|
256
|
+
from .backfills import _apply_backfill
|
|
257
|
+
from .seeds import _apply_seeds
|
|
258
|
+
if phase['kind'] == 'backfill-tighten':
|
|
259
|
+
_verify_backfill_tighten_target(plan, phase)
|
|
260
|
+
elif phase['kind'] == 'backfill-add':
|
|
261
|
+
_verify_backfill_add_target(plan, phase)
|
|
262
|
+
with _installation(connection, bundle, statement_timeout_ms=statement_timeout_ms,
|
|
263
|
+
lock_timeout_ms=lock_timeout_ms):
|
|
264
|
+
for step in _phase_steps(plan, phase):
|
|
265
|
+
if step['transaction'] != 'required':
|
|
266
|
+
raise CatalogError('mixed-phase-profile')
|
|
267
|
+
if step['kind'] == 'backfill':
|
|
268
|
+
_apply_backfill(connection, plan, step)
|
|
269
|
+
elif step['kind'] == 'seed':
|
|
270
|
+
if step.get('operation') != 'apply-seeds' or step.get('seedSets') != plan['seedExecution'].get('sets'):
|
|
271
|
+
raise CatalogError('seed-execution-profile')
|
|
272
|
+
_apply_seeds(connection, plan, statement_timeout_ms=statement_timeout_ms,
|
|
273
|
+
lock_timeout_ms=lock_timeout_ms)
|
|
274
|
+
else:
|
|
275
|
+
_execute(connection, step['sql'])
|
|
276
|
+
witness = _capture_witness(connection, bundle)
|
|
277
|
+
return witness
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _verify_backfill_tighten_target(plan, phase):
|
|
281
|
+
"""Bind the paired data fill and NOT NULL step to one selected source Field."""
|
|
282
|
+
steps = _phase_steps(plan, phase)
|
|
283
|
+
if len(steps) != 2:
|
|
284
|
+
raise CatalogError('mixed-phase-profile')
|
|
285
|
+
backfill, tighten = steps
|
|
286
|
+
target = backfill.get('phaseTarget')
|
|
287
|
+
selection = {
|
|
288
|
+
'table': target['table'],
|
|
289
|
+
'column': {'module': target['field']['module'],
|
|
290
|
+
'element': target['field']['element']},
|
|
291
|
+
'operation': backfill.get('operation'),
|
|
292
|
+
}
|
|
293
|
+
options = plan.get('options', {})
|
|
294
|
+
backfills = options.get('backfills', [])
|
|
295
|
+
matches = [(index, item) for index, item in enumerate(backfills)
|
|
296
|
+
if item.get('table') == selection['table']
|
|
297
|
+
and item.get('column') == selection['column']
|
|
298
|
+
and item.get('operation') == selection['operation']]
|
|
299
|
+
columns = [item for item in plan['next']['expectedCatalog']['columns']
|
|
300
|
+
if item.get('table') == selection['table']
|
|
301
|
+
and item.get('field') == selection['column']]
|
|
302
|
+
if (len(matches) != 1 or len(columns) != 1
|
|
303
|
+
or columns[0].get('sourcePath') != tighten.get('sourcePath')
|
|
304
|
+
or columns[0].get('nullable') is not False
|
|
305
|
+
or backfill.get('sourcePath') != '/options/backfills/'+str(matches[0][0])):
|
|
306
|
+
raise CatalogError('mixed-phase-profile')
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
def _verify_backfill_add_target(plan, phase):
|
|
310
|
+
"""Bind the atomic add/fill/tighten correspondence to one new required Field."""
|
|
311
|
+
steps = _phase_steps(plan, phase)
|
|
312
|
+
options = plan.get('options', {})
|
|
313
|
+
if (plan.get('version') != 'umf.table-migration/0.4'
|
|
314
|
+
or options.get('version') != 'umf.table-migration-options/0.4'
|
|
315
|
+
or len(options.get('backfills', [])) != 1 or not steps):
|
|
316
|
+
raise CatalogError('mixed-phase-profile')
|
|
317
|
+
target = steps[0].get('phaseTarget')
|
|
318
|
+
if type(target) is not dict or set(target) != {'table','field'}:
|
|
319
|
+
raise CatalogError('mixed-phase-profile')
|
|
320
|
+
ref = {'module':target.get('field',{}).get('module'),
|
|
321
|
+
'element':target.get('field',{}).get('element')}
|
|
322
|
+
columns = [item for item in plan['next']['expectedCatalog']['columns']
|
|
323
|
+
if item.get('table') == target.get('table') and item.get('field') == ref]
|
|
324
|
+
old_columns = [item for item in plan['previous']['expectedCatalog']['columns']
|
|
325
|
+
if item.get('table') == target.get('table') and item.get('field') == ref]
|
|
326
|
+
by_role = {step.get('phaseOperation'): step for step in steps
|
|
327
|
+
if step.get('phaseOperation') != 'target-check'}
|
|
328
|
+
roles = [step.get('phaseOperation') for step in steps]
|
|
329
|
+
backfill_index = roles.index('backfill') if 'backfill' in roles else -1
|
|
330
|
+
default_index = roles.index('install-default') if 'install-default' in roles else -1
|
|
331
|
+
selection = options['backfills'][0]
|
|
332
|
+
target_checks = [step for step in steps if step.get('phaseOperation') == 'target-check']
|
|
333
|
+
domain_id = 'domain:' + ref['module'] + '.' + ref['element']
|
|
334
|
+
expected_checks = [item for item in plan['next']['expectedCatalog']['checks']
|
|
335
|
+
if item.get('table') == target.get('table') and item.get('id') == domain_id]
|
|
336
|
+
table = next((item for item in plan['next']['expectedCatalog']['tables']
|
|
337
|
+
if item.get('id') == target.get('table')), None)
|
|
338
|
+
expected_check_sql = ('ALTER TABLE ' + _q(plan['next']['configuration']['schema']) + '.'
|
|
339
|
+
+ _q(table['name']) + ' ADD ' + expected_checks[0]['definitionSql']
|
|
340
|
+
if table is not None and expected_checks else None)
|
|
341
|
+
if (selection.get('table') != target.get('table') or selection.get('column') != ref
|
|
342
|
+
or len(columns) != 1 or old_columns or columns[0].get('nullable') is not False
|
|
343
|
+
or steps[0].get('phaseOperation') != 'add-column'
|
|
344
|
+
or steps[0].get('kind') != 'table' or steps[0].get('transaction') != 'required'
|
|
345
|
+
or len(steps) < 3 or roles.count('backfill') != 1
|
|
346
|
+
or roles.count('tighten-not-null') != 1 or roles.count('install-default') > 1
|
|
347
|
+
or roles[-1] != 'tighten-not-null' or backfill_index < 1
|
|
348
|
+
or any(role != 'target-check' for role in roles[1:backfill_index])
|
|
349
|
+
or default_index != -1 and default_index < backfill_index
|
|
350
|
+
or any(role != 'install-default' for role in roles[backfill_index+1:-1])
|
|
351
|
+
or any(step.get('phaseTarget') != target or step.get('transaction') != 'required'
|
|
352
|
+
for step in steps)
|
|
353
|
+
or by_role.get('backfill', {}).get('kind') != 'backfill'
|
|
354
|
+
or by_role.get('backfill', {}).get('operation') != selection.get('operation')
|
|
355
|
+
or by_role.get('backfill', {}).get('sourcePath') != '/options/backfills/0'
|
|
356
|
+
or by_role.get('tighten-not-null', {}).get('sourcePath') != columns[0].get('sourcePath')
|
|
357
|
+
or steps[-1].get('phaseOperation') != 'tighten-not-null'
|
|
358
|
+
or len(target_checks) != len(expected_checks)
|
|
359
|
+
or any(step.get('sourcePath') != columns[0].get('sourcePath') + '/domain'
|
|
360
|
+
or step.get('sql') != expected_check_sql for step in target_checks)):
|
|
361
|
+
raise CatalogError('mixed-phase-profile')
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def apply_mixed_migration(connection, plan, *, approved_digest, expected_head, person_roles,
|
|
365
|
+
file_digest=None, stop_after_phase=None,
|
|
366
|
+
repair_invalid=False,
|
|
367
|
+
after_concurrent_effect_before_receipt=False,
|
|
368
|
+
after_phase_commit_unknown=False,
|
|
369
|
+
statement_timeout_ms=30_000, lock_timeout_ms=5_000):
|
|
370
|
+
"""Apply or resume a v0.2 mixed plan on a caller-supplied idle autocommit session.
|
|
371
|
+
|
|
372
|
+
The runner persists a fixed private progress row. Required phase effects and
|
|
373
|
+
their prefix witness commit atomically. Concurrent index intent commits
|
|
374
|
+
before dispatch and is reconciled against native validity and exact shape.
|
|
375
|
+
An interrupted head remains fenced until final history publication.
|
|
376
|
+
"""
|
|
377
|
+
from psycopg import Error as NativeError
|
|
378
|
+
|
|
379
|
+
source_plan = _verified_plan(plan)
|
|
380
|
+
phases = _verified_phases(source_plan)
|
|
381
|
+
if (source_plan['previous'] is None
|
|
382
|
+
or source_plan.get('options', {}).get('version') != 'umf.table-migration-options/0.2'
|
|
383
|
+
or approved_digest != source_plan['digest']):
|
|
384
|
+
raise CatalogError('mixed-phase-profile')
|
|
385
|
+
if file_digest is not None and (type(file_digest) is not str or not re.fullmatch('[a-f0-9]{64}', file_digest)):
|
|
386
|
+
raise CatalogError('migration-file-digest-conflict')
|
|
387
|
+
if stop_after_phase is not None and (type(stop_after_phase) is not int or stop_after_phase < 1):
|
|
388
|
+
raise ValueError('invalid recovery options')
|
|
389
|
+
if type(repair_invalid) is not bool or type(after_concurrent_effect_before_receipt) is not bool or type(after_phase_commit_unknown) is not bool:
|
|
390
|
+
raise ValueError('invalid recovery options')
|
|
391
|
+
if not connection.autocommit or int(connection.info.transaction_status) != 0:
|
|
392
|
+
raise CatalogError('idle-autocommit-required')
|
|
393
|
+
bundle = source_plan['next']
|
|
394
|
+
schema = bundle['configuration']['schema']
|
|
395
|
+
with connection.transaction(), _installation(connection, bundle,
|
|
396
|
+
statement_timeout_ms=statement_timeout_ms, lock_timeout_ms=lock_timeout_ms):
|
|
397
|
+
pass
|
|
398
|
+
lock = int.from_bytes(hashlib.sha256(('umf.table-lifecycle/0.1\0'+schema).encode()).digest()[:8], 'big', signed=True)
|
|
399
|
+
if _one(connection, 'SELECT pg_catalog.pg_try_advisory_lock(%s)', (lock,)) != (True,):
|
|
400
|
+
raise CatalogError('migration-busy')
|
|
401
|
+
previous_settings = None
|
|
402
|
+
publication_started = False
|
|
403
|
+
try:
|
|
404
|
+
previous_settings = _one(connection, "SELECT current_setting('statement_timeout'),current_setting('lock_timeout')")
|
|
405
|
+
_one(connection, "SELECT set_config('statement_timeout',%s,false),set_config('lock_timeout',%s,false)", (str(statement_timeout_ms),str(lock_timeout_ms)))
|
|
406
|
+
with connection.transaction():
|
|
407
|
+
if not _verify_history_schema(connection, bundle):
|
|
408
|
+
raise CatalogError('ledger-history-missing')
|
|
409
|
+
history = _history_rows(connection, schema)
|
|
410
|
+
if not history:
|
|
411
|
+
raise CatalogError('ledger-history-missing')
|
|
412
|
+
matches = [entry for entry in history if entry['plan']['id'] == source_plan['id']]
|
|
413
|
+
if matches:
|
|
414
|
+
match = matches[0]
|
|
415
|
+
prior_head = history[match['position']-2]['entryDigest'] if match['position'] > 1 else None
|
|
416
|
+
if (match['plan']['digest'] != source_plan['digest']
|
|
417
|
+
or match.get('fileDigest') != file_digest
|
|
418
|
+
or prior_head != expected_head):
|
|
419
|
+
raise CatalogError('ledger-digest-conflict')
|
|
420
|
+
if history[-1]['plan']['toBundleDigest'] != bundle['bundleDigest']:
|
|
421
|
+
raise CatalogError('installed-generation-mismatch')
|
|
422
|
+
_verify_installed(connection, history[-1], person_roles, statement_timeout_ms, lock_timeout_ms)
|
|
423
|
+
return {'status':'already-applied','migrationId':source_plan['id'],
|
|
424
|
+
'entryDigest':matches[0]['entryDigest'],'headDigest':history[-1]['entryDigest'],
|
|
425
|
+
'generation':len(history),'installedBundleDigest':bundle['bundleDigest'],
|
|
426
|
+
'commitResponsibility':'runner'}
|
|
427
|
+
if (history[-1]['entryDigest'] != expected_head
|
|
428
|
+
or source_plan['predecessor'] != {'id':history[-1]['plan']['id'],'digest':history[-1]['plan']['digest']}
|
|
429
|
+
or history[-1]['plan']['toBundleDigest'] != source_plan['fromBundleDigest']):
|
|
430
|
+
raise CatalogError('ledger-head-mismatch')
|
|
431
|
+
_authorize_new_effects(source_plan)
|
|
432
|
+
progress_exists = _verify_progress_schema(connection, bundle, create=False)
|
|
433
|
+
rows = _progress_rows(connection, schema) if progress_exists else []
|
|
434
|
+
if rows:
|
|
435
|
+
receipt = rows[0]
|
|
436
|
+
if receipt['fileDigest'] != file_digest:
|
|
437
|
+
raise CatalogError('migration-file-digest-conflict')
|
|
438
|
+
_assert_progress_binding(receipt, migration_id=source_plan['id'], plan_digest=source_plan['digest'],
|
|
439
|
+
expected_head=expected_head, file_digest=receipt['fileDigest'])
|
|
440
|
+
_verify_mixed_prefix(connection, source_plan, receipt)
|
|
441
|
+
else:
|
|
442
|
+
_verify_installed(connection, history[-1], person_roles, statement_timeout_ms, lock_timeout_ms)
|
|
443
|
+
if progress_exists:
|
|
444
|
+
raise CatalogError('progress-state-mismatch')
|
|
445
|
+
_verify_progress_schema(connection, bundle, create=True)
|
|
446
|
+
receipt = {'migrationId':source_plan['id'],'planDigest':source_plan['digest'],
|
|
447
|
+
'expectedHead':expected_head,'fileDigest':file_digest,'phaseIndex':0,
|
|
448
|
+
'state':'ready','phaseDigest':hashlib.sha256(b'').hexdigest(),
|
|
449
|
+
'completedSteps':[],'prefixWitness':_capture_witness(connection,bundle)}
|
|
450
|
+
_head_grants(connection, bundle, False)
|
|
451
|
+
_write_progress(connection, schema, receipt)
|
|
452
|
+
# Keep person/batch generation admission fenced across every return and failure.
|
|
453
|
+
with connection.transaction():
|
|
454
|
+
_verify_phase_head(connection, bundle)
|
|
455
|
+
_head_grants(connection, bundle, False)
|
|
456
|
+
while receipt['phaseIndex'] < len(phases):
|
|
457
|
+
index = receipt['phaseIndex']
|
|
458
|
+
phase = phases[index]
|
|
459
|
+
phase_hash = _phase_hash(source_plan, phase)
|
|
460
|
+
if receipt['state'] == 'intent':
|
|
461
|
+
if receipt['phaseDigest'] != phase_hash:
|
|
462
|
+
raise CatalogError('progress-phase-mismatch')
|
|
463
|
+
repair_step = None
|
|
464
|
+
with connection.transaction():
|
|
465
|
+
_lock_phase_tables(connection, source_plan)
|
|
466
|
+
_verify_phase_execution_boundary(connection, source_plan, person_roles)
|
|
467
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
468
|
+
current = _capture_witness(connection, bundle)
|
|
469
|
+
if _without_concurrent_effect(current, source_plan, phase) != receipt['prefixWitness']:
|
|
470
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
471
|
+
step = _phase_steps(source_plan, phase)[0]
|
|
472
|
+
parts = step['sourcePath'].split('/')
|
|
473
|
+
table = bundle['expectedCatalog']['tables'][int(parts[6])]
|
|
474
|
+
index_spec = table['indexes'][int(parts[8])]
|
|
475
|
+
actual = _index_state(connection, schema, table['name'], index_spec['name'])
|
|
476
|
+
if actual is not None and actual[6] is False:
|
|
477
|
+
from .concurrent import _check_invalid_shape
|
|
478
|
+
_check_invalid_shape(connection, bundle, table, index_spec, actual)
|
|
479
|
+
if not repair_invalid:
|
|
480
|
+
raise CatalogError('invalid-index-repair-required')
|
|
481
|
+
repair_step = step
|
|
482
|
+
elif _verify_index_shape(connection, bundle, step):
|
|
483
|
+
receipt = {**receipt,'phaseIndex':index+1,'state':'complete','phaseDigest':phase_hash,
|
|
484
|
+
'completedSteps':receipt['completedSteps']+phase['steps'],
|
|
485
|
+
'prefixWitness':_capture_witness(connection,bundle)}
|
|
486
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
487
|
+
_write_progress(connection, schema, receipt)
|
|
488
|
+
else:
|
|
489
|
+
previous_digest = _phase_hash(source_plan, phases[index-1]) if index else hashlib.sha256(b'').hexdigest()
|
|
490
|
+
receipt = {**receipt,'state':'ready','phaseDigest':previous_digest}
|
|
491
|
+
_write_progress(connection, schema, receipt)
|
|
492
|
+
if receipt['state'] == 'complete':
|
|
493
|
+
continue
|
|
494
|
+
if repair_step is not None:
|
|
495
|
+
_execute(connection,'DROP INDEX CONCURRENTLY '+_q(schema)+'.'+_q(index_spec['name']))
|
|
496
|
+
_execute(connection,repair_step['sql'])
|
|
497
|
+
if after_concurrent_effect_before_receipt:
|
|
498
|
+
raise CatalogError('migration-outcome-unknown-observe-progress')
|
|
499
|
+
with connection.transaction():
|
|
500
|
+
_lock_phase_tables(connection, source_plan)
|
|
501
|
+
_verify_phase_execution_boundary(connection, source_plan, person_roles)
|
|
502
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
503
|
+
current = _capture_witness(connection, bundle)
|
|
504
|
+
if _without_concurrent_effect(current, source_plan, phase) != receipt['prefixWitness']:
|
|
505
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
506
|
+
_verify_index_shape(connection, bundle, repair_step)
|
|
507
|
+
receipt = {**receipt,'phaseIndex':index+1,'state':'complete','phaseDigest':phase_hash,
|
|
508
|
+
'completedSteps':receipt['completedSteps']+phase['steps'],
|
|
509
|
+
'prefixWitness':_capture_witness(connection,bundle)}
|
|
510
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
511
|
+
_write_progress(connection, schema, receipt)
|
|
512
|
+
if after_phase_commit_unknown:
|
|
513
|
+
raise CatalogError('migration-outcome-unknown-observe-progress')
|
|
514
|
+
if stop_after_phase == receipt['phaseIndex']:
|
|
515
|
+
return {'status':'in-progress','planDigest':source_plan['digest'],
|
|
516
|
+
'completedPhases':receipt['phaseIndex'],'completedSteps':receipt['completedSteps'],
|
|
517
|
+
'ledgerAdvanced':False}
|
|
518
|
+
continue
|
|
519
|
+
if phase['transaction'] == 'forbidden':
|
|
520
|
+
with connection.transaction():
|
|
521
|
+
_lock_phase_tables(connection, source_plan)
|
|
522
|
+
_verify_phase_execution_boundary(connection, source_plan, person_roles)
|
|
523
|
+
current = _capture_witness(connection, bundle)
|
|
524
|
+
if current != receipt['prefixWitness']:
|
|
525
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
526
|
+
receipt = {**receipt,'state':'intent','phaseDigest':phase_hash}
|
|
527
|
+
_write_progress(connection, schema, receipt)
|
|
528
|
+
step = _phase_steps(source_plan, phase)[0]
|
|
529
|
+
_execute(connection, step['sql'])
|
|
530
|
+
if after_concurrent_effect_before_receipt:
|
|
531
|
+
raise CatalogError('migration-outcome-unknown-observe-progress')
|
|
532
|
+
with connection.transaction():
|
|
533
|
+
_lock_phase_tables(connection, source_plan)
|
|
534
|
+
_verify_phase_execution_boundary(connection, source_plan, person_roles)
|
|
535
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
536
|
+
current = _capture_witness(connection, bundle)
|
|
537
|
+
if _without_concurrent_effect(current, source_plan, phase) != receipt['prefixWitness']:
|
|
538
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
539
|
+
_verify_index_shape(connection, bundle, step)
|
|
540
|
+
receipt = {**receipt,'phaseIndex':index+1,'state':'complete','phaseDigest':phase_hash,
|
|
541
|
+
'completedSteps':receipt['completedSteps']+phase['steps'],
|
|
542
|
+
'prefixWitness':_capture_witness(connection,bundle)}
|
|
543
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
544
|
+
_write_progress(connection, schema, receipt)
|
|
545
|
+
else:
|
|
546
|
+
with connection.transaction():
|
|
547
|
+
_lock_phase_tables(connection, source_plan)
|
|
548
|
+
_verify_phase_execution_boundary(connection, source_plan, person_roles)
|
|
549
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
550
|
+
current = _capture_witness(connection, bundle)
|
|
551
|
+
if current != receipt['prefixWitness']:
|
|
552
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
553
|
+
witness = _run_required_phase(connection, source_plan, phase, person_roles,
|
|
554
|
+
statement_timeout_ms=statement_timeout_ms, lock_timeout_ms=lock_timeout_ms)
|
|
555
|
+
_verify_mixed_metadata_inventory(connection, source_plan)
|
|
556
|
+
receipt = {**receipt,'phaseIndex':index+1,'state':'complete','phaseDigest':phase_hash,
|
|
557
|
+
'completedSteps':receipt['completedSteps']+phase['steps'],
|
|
558
|
+
'prefixWitness':witness}
|
|
559
|
+
_write_progress(connection, schema, receipt)
|
|
560
|
+
if after_phase_commit_unknown:
|
|
561
|
+
raise CatalogError('migration-outcome-unknown-observe-progress')
|
|
562
|
+
if stop_after_phase == receipt['phaseIndex']:
|
|
563
|
+
return {'status':'in-progress','planDigest':source_plan['digest'],
|
|
564
|
+
'completedPhases':receipt['phaseIndex'],'completedSteps':receipt['completedSteps'],
|
|
565
|
+
'ledgerAdvanced':False}
|
|
566
|
+
publication_started = True
|
|
567
|
+
with connection.transaction():
|
|
568
|
+
_verify_phase_head(connection, bundle)
|
|
569
|
+
if _capture_witness(connection, bundle) != receipt['prefixWitness']:
|
|
570
|
+
raise CatalogError('progress-prefix-mismatch')
|
|
571
|
+
_verify_progress_schema(connection, bundle)
|
|
572
|
+
_head_grants(connection, bundle, True)
|
|
573
|
+
_delete_progress(connection, schema, source_plan['id'])
|
|
574
|
+
_drop_progress(connection, schema)
|
|
575
|
+
# The private finalizer performs full catalog and privilege
|
|
576
|
+
# verification before recording history. Avoid a second complete
|
|
577
|
+
# source probe while preserving its atomic publication boundary.
|
|
578
|
+
result = _finalize_phased_migration(connection, source_plan, approved_digest=approved_digest,
|
|
579
|
+
expected_head=expected_head, person_roles=person_roles,
|
|
580
|
+
statement_timeout_ms=statement_timeout_ms, lock_timeout_ms=lock_timeout_ms,
|
|
581
|
+
file_digest=file_digest)
|
|
582
|
+
return {**result,'status':'committed','commitResponsibility':'runner'}
|
|
583
|
+
except NativeError:
|
|
584
|
+
raise CatalogError('migration-outcome-unknown-observe-history' if publication_started else 'migration-outcome-unknown-observe-progress') from None
|
|
585
|
+
finally:
|
|
586
|
+
try:
|
|
587
|
+
try:
|
|
588
|
+
if previous_settings is not None:
|
|
589
|
+
_one(connection, "SELECT set_config('statement_timeout',%s,false),set_config('lock_timeout',%s,false)", tuple(previous_settings))
|
|
590
|
+
finally:
|
|
591
|
+
_one(connection, 'SELECT pg_catalog.pg_advisory_unlock(%s)', (lock,))
|
|
592
|
+
except NativeError:
|
|
593
|
+
raise CatalogError('migration-session-cleanup-failed-observe-history' if publication_started else 'migration-session-cleanup-failed-observe-progress') from None
|