pgdeclare 0.2.1__tar.gz → 0.2.2__tar.gz
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.
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/CHANGELOG.md +11 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/PKG-INFO +1 -1
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/pyproject.toml +1 -1
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/__init__.py +1 -1
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/differ.py +44 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_boundary.py +1 -1
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_expand_contract.py +64 -13
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/.gitignore +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/LICENSE +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/NOTICE +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/README.md +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/__main__.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/changes.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/cli.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/config.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/contract.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/drop_directive.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/executor.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/introspection.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/ledger.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/migrate.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/models.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/prove.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/py.typed +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/quoting.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/retry_executor.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/schema_parser.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/src/pgdeclare/statement_parser.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/conftest.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/dbutil.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_cli.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_comments.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_default_privileges.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_diff.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_domains.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_foreign_data.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_integration.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_lifecycle.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_materialized_views.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_partitions.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_pipeline.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_prove.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_publications_rules.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_ranges_collations.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_retry_executor.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_routines.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_security.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_sequences.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_statement_parser.py +0 -0
- {pgdeclare-0.2.1 → pgdeclare-0.2.2}/tests/test_views.py +0 -0
|
@@ -5,6 +5,17 @@ All notable changes to this project are documented here. The format follows
|
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Until 1.0 the API
|
|
6
6
|
may change in minor releases.
|
|
7
7
|
|
|
8
|
+
## [0.2.2] - 2026-11-19
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- A signature change that only appends parameters with defaults is online
|
|
13
|
+
again. The old and new forms still cannot coexist, but the drop and
|
|
14
|
+
re-create is one statement, and every call of the old form, by position or
|
|
15
|
+
by name, resolves to the new one. Any other change whose forms compete for
|
|
16
|
+
a call (new types at the same count, an old default taken away, a new
|
|
17
|
+
return type or renamed parameters) stays offline.
|
|
18
|
+
|
|
8
19
|
## [0.2.1] - 2026-11-19
|
|
9
20
|
|
|
10
21
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pgdeclare
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Declarative Postgres schemas: diff the live database against your SQL files, with before/after migration blocks and a hash ledger.
|
|
5
5
|
Project-URL: Homepage, https://github.com/powertime-org/pgdeclare
|
|
6
6
|
Project-URL: Source, https://github.com/powertime-org/pgdeclare
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pgdeclare"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
description = "Declarative Postgres schemas: diff the live database against your SQL files, with before/after migration blocks and a hash ledger."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "Apache-2.0"
|
|
@@ -1308,6 +1308,32 @@ def _same_call_types(a: Function, b: Function) -> bool:
|
|
|
1308
1308
|
return a.call_shape_known and b.call_shape_known and a.arg_types == b.arg_types
|
|
1309
1309
|
|
|
1310
1310
|
|
|
1311
|
+
def _appends_defaulted_parameters(new: Function, old: Function) -> bool:
|
|
1312
|
+
"""Whether `new` is `old` with trailing parameters that all have defaults.
|
|
1313
|
+
|
|
1314
|
+
Every call the old form accepts, by position or by name, then resolves to
|
|
1315
|
+
the new one: the old parameters keep their names, types and order, the
|
|
1316
|
+
added ones fill in from their defaults, and no call loses a default it
|
|
1317
|
+
relied on (the new form needs no more arguments than the old). With the
|
|
1318
|
+
same kind and return clause, re-creating it in one statement is invisible
|
|
1319
|
+
to an application still calling the old form.
|
|
1320
|
+
"""
|
|
1321
|
+
if not (new.call_shape_known and old.call_shape_known):
|
|
1322
|
+
return False
|
|
1323
|
+
if new.max_call_args is None or old.max_call_args is None:
|
|
1324
|
+
return False # VARIADIC: leave it to the overlap rule
|
|
1325
|
+
assert new.min_call_args is not None and old.min_call_args is not None
|
|
1326
|
+
if new.kind != old.kind or new.kind != "f":
|
|
1327
|
+
return False
|
|
1328
|
+
if new.get_return_clause() != old.get_return_clause():
|
|
1329
|
+
return False
|
|
1330
|
+
if old.args and not new.args.startswith(old.args + ", "):
|
|
1331
|
+
return False
|
|
1332
|
+
return (
|
|
1333
|
+
new.max_call_args > old.max_call_args and new.min_call_args <= old.min_call_args
|
|
1334
|
+
)
|
|
1335
|
+
|
|
1336
|
+
|
|
1311
1337
|
def _diff_functions(desired: Schema, actual: Schema) -> list[Change]:
|
|
1312
1338
|
"""Diff functions between desired and actual schemas."""
|
|
1313
1339
|
changes: list[Change] = []
|
|
@@ -1358,6 +1384,24 @@ def _diff_functions(desired: Schema, actual: Schema) -> list[Change]:
|
|
|
1358
1384
|
# to the old signature fails from the DROP on. Either way an
|
|
1359
1385
|
# application still calling the old form breaks: offline.
|
|
1360
1386
|
functions_to_drop_for_rename.add(rename_source.signature)
|
|
1387
|
+
if _appends_defaulted_parameters(func, rename_source):
|
|
1388
|
+
# Old and new would compete side by side, but swapped in
|
|
1389
|
+
# one statement there is no moment with both or neither,
|
|
1390
|
+
# and every old call resolves to the new form: online.
|
|
1391
|
+
change = DropAndCreateFunction(
|
|
1392
|
+
function=func,
|
|
1393
|
+
old_args=rename_source.args,
|
|
1394
|
+
old_kind=rename_source.kind,
|
|
1395
|
+
)
|
|
1396
|
+
change.description = (
|
|
1397
|
+
f"Drop {rename_source.keyword.lower()} "
|
|
1398
|
+
f"{rename_source.signature} and create "
|
|
1399
|
+
f"{func.signature} (online: it only appends "
|
|
1400
|
+
f"parameters with defaults, so every old call "
|
|
1401
|
+
f"resolves to it)"
|
|
1402
|
+
)
|
|
1403
|
+
changes.append(change)
|
|
1404
|
+
continue
|
|
1361
1405
|
change = DropAndCreateFunction(
|
|
1362
1406
|
function=func,
|
|
1363
1407
|
old_args=rename_source.args, # Pass old args for correct DROP
|
|
@@ -63,18 +63,64 @@ def _schema(*functions: Function, **kw) -> Schema:
|
|
|
63
63
|
|
|
64
64
|
|
|
65
65
|
class TestSignatureChanges:
|
|
66
|
-
def
|
|
67
|
-
#
|
|
68
|
-
# with two arguments matches both
|
|
69
|
-
#
|
|
66
|
+
def test_appended_default_parameters_are_one_online_statement(self):
|
|
67
|
+
# A third parameter with a DEFAULT: the two forms cannot coexist (a
|
|
68
|
+
# call with two arguments matches both), but swapped in one statement
|
|
69
|
+
# every call of the old form resolves to the new one.
|
|
70
70
|
old = _fn("account", "a uuid, s uuid", "uuid, uuid", 2, 2)
|
|
71
71
|
new = _fn("account", "a uuid, s uuid, ip text", "uuid, uuid, text", 2, 3)
|
|
72
72
|
changes = compute_diff(_schema(new), _schema(old))
|
|
73
73
|
assert [type(c) for c in changes] == [DropAndCreateFunction]
|
|
74
|
-
assert changes[0].category == ChangeCategory.
|
|
75
|
-
|
|
74
|
+
assert changes[0].category == ChangeCategory.ONLINE
|
|
75
|
+
swap = changes[0]
|
|
76
|
+
assert isinstance(swap, DropAndCreateFunction)
|
|
77
|
+
assert swap.old_args == "a uuid, s uuid"
|
|
78
|
+
assert "online" in changes[0].description
|
|
76
79
|
assert not is_held_back(changes[0])
|
|
77
80
|
|
|
81
|
+
def test_appended_defaults_keep_earlier_defaults_optional(self):
|
|
82
|
+
old = _fn("f", "a int, b int", "integer, integer", 1, 2)
|
|
83
|
+
new = _fn("f", "a int, b int, c int", "integer, integer, integer", 1, 3)
|
|
84
|
+
changes = compute_diff(_schema(new), _schema(old))
|
|
85
|
+
assert changes[0].category == ChangeCategory.ONLINE
|
|
86
|
+
|
|
87
|
+
@pytest.mark.parametrize(
|
|
88
|
+
"old,new",
|
|
89
|
+
[
|
|
90
|
+
# An old default dropped: a one-argument call no longer resolves.
|
|
91
|
+
(
|
|
92
|
+
_fn("f", "a int, b int", "integer, integer", 1, 2),
|
|
93
|
+
_fn("f", "a int, b int, c int", "integer, integer, integer", 2, 3),
|
|
94
|
+
),
|
|
95
|
+
# An old parameter renamed: a call naming it fails.
|
|
96
|
+
(
|
|
97
|
+
_fn("f", "a int", "integer", 1, 1),
|
|
98
|
+
_fn("f", "x int, b int", "integer, integer", 1, 2),
|
|
99
|
+
),
|
|
100
|
+
# Same count, new types: competes, and resolves to neither.
|
|
101
|
+
(
|
|
102
|
+
_fn("f", "a int", "integer", 1, 1),
|
|
103
|
+
_fn("f", "a text, b int", "text, integer", 1, 2),
|
|
104
|
+
),
|
|
105
|
+
# A new return type: the old caller reads a different answer.
|
|
106
|
+
(
|
|
107
|
+
_fn("f", "a int", "integer", 1, 1, body="RETURNS int AS '1'"),
|
|
108
|
+
_fn(
|
|
109
|
+
"f",
|
|
110
|
+
"a int, b int",
|
|
111
|
+
"integer, integer",
|
|
112
|
+
1,
|
|
113
|
+
2,
|
|
114
|
+
body="RETURNS text AS '1'",
|
|
115
|
+
),
|
|
116
|
+
),
|
|
117
|
+
],
|
|
118
|
+
)
|
|
119
|
+
def test_other_competing_signatures_stay_offline(self, old, new):
|
|
120
|
+
changes = compute_diff(_schema(new), _schema(old))
|
|
121
|
+
assert [type(c) for c in changes] == [DropAndCreateFunction]
|
|
122
|
+
assert changes[0].category == ChangeCategory.OFFLINE
|
|
123
|
+
|
|
78
124
|
def test_a_signature_no_old_call_reaches_is_created_beside_the_old(self):
|
|
79
125
|
old = _fn("total", "a int", "integer", 1, 1)
|
|
80
126
|
new = _fn("total", "a int, b int", "integer, integer", 2, 2)
|
|
@@ -223,7 +269,7 @@ class TestDeployWhileTheOldVersionServes:
|
|
|
223
269
|
apply_declared_schema(target, sql_dir, plan, offline=True, config=QUIET)
|
|
224
270
|
assert _run(target, "SELECT total(amount => 4)") == [(4,)]
|
|
225
271
|
|
|
226
|
-
def
|
|
272
|
+
def test_a_new_default_parameter_swaps_online(self, tmp_path, databases):
|
|
227
273
|
target, plan = databases
|
|
228
274
|
sql_dir = tmp_path / "sql"
|
|
229
275
|
_declare(sql_dir, V1)
|
|
@@ -236,16 +282,21 @@ class TestDeployWhileTheOldVersionServes:
|
|
|
236
282
|
"account(a uuid, s uuid, ip text DEFAULT NULL)",
|
|
237
283
|
),
|
|
238
284
|
)
|
|
239
|
-
#
|
|
240
|
-
#
|
|
241
|
-
|
|
242
|
-
|
|
285
|
+
# One statement drops account(uuid, uuid) and creates the new form,
|
|
286
|
+
# so no moment has neither (the 2026-11-19 incident, a hand DROP
|
|
287
|
+
# committed before the CREATE) or both ("is not unique").
|
|
288
|
+
apply_declared_schema(target, sql_dir, plan, expand_only=True, config=QUIET)
|
|
289
|
+
# The serving version's calls, by position and by name, still resolve.
|
|
243
290
|
assert _run(target, OLD_CALLS) == [(1, 1, 3)]
|
|
244
|
-
|
|
245
|
-
|
|
291
|
+
assert _run(
|
|
292
|
+
target, "SELECT account(a => gen_random_uuid(), s => gen_random_uuid())"
|
|
293
|
+
) == [(1,)]
|
|
246
294
|
assert _run(
|
|
247
295
|
target, "SELECT account(gen_random_uuid(), gen_random_uuid(), 'x')"
|
|
248
296
|
) == [(1,)]
|
|
297
|
+
apply_declared_schema(
|
|
298
|
+
target, sql_dir, plan, expect_converged=True, config=QUIET
|
|
299
|
+
)
|
|
249
300
|
|
|
250
301
|
def test_expand_keeps_old_calls_working_and_contract_drops(
|
|
251
302
|
self, tmp_path, databases
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|