pgdeclare 0.3.0__tar.gz → 0.3.1__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.
Files changed (50) hide show
  1. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/CHANGELOG.md +12 -0
  2. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/PKG-INFO +1 -1
  3. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/pyproject.toml +1 -1
  4. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/__init__.py +1 -1
  5. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/differ.py +21 -3
  6. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_boundary.py +1 -1
  7. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_comments.py +2 -1
  8. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_expand_contract.py +56 -0
  9. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_routines.py +14 -7
  10. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/.gitignore +0 -0
  11. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/LICENSE +0 -0
  12. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/NOTICE +0 -0
  13. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/README.md +0 -0
  14. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/__main__.py +0 -0
  15. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/changes.py +0 -0
  16. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/cli.py +0 -0
  17. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/config.py +0 -0
  18. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/contract.py +0 -0
  19. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/drop_directive.py +0 -0
  20. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/executor.py +0 -0
  21. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/introspection.py +0 -0
  22. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/ledger.py +0 -0
  23. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/migrate.py +0 -0
  24. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/models.py +0 -0
  25. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/prove.py +0 -0
  26. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/py.typed +0 -0
  27. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/quoting.py +0 -0
  28. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/retry_executor.py +0 -0
  29. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/schema_parser.py +0 -0
  30. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/src/pgdeclare/statement_parser.py +0 -0
  31. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/conftest.py +0 -0
  32. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/dbutil.py +0 -0
  33. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_cli.py +0 -0
  34. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_default_privileges.py +0 -0
  35. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_diff.py +0 -0
  36. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_domains.py +0 -0
  37. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_foreign_data.py +0 -0
  38. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_integration.py +0 -0
  39. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_lifecycle.py +0 -0
  40. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_materialized_views.py +0 -0
  41. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_partitions.py +0 -0
  42. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_pipeline.py +0 -0
  43. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_prove.py +0 -0
  44. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_publications_rules.py +0 -0
  45. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_ranges_collations.py +0 -0
  46. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_retry_executor.py +0 -0
  47. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_security.py +0 -0
  48. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_sequences.py +0 -0
  49. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_statement_parser.py +0 -0
  50. {pgdeclare-0.3.0 → pgdeclare-0.3.1}/tests/test_views.py +0 -0
@@ -5,6 +5,18 @@ 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.3.1] - 2026-11-19
9
+
10
+ ### Changed
11
+
12
+ - A routine re-created because its result or its kind changes (a new
13
+ `RETURNS` type or `TABLE` columns, an aggregate's result, a procedure that
14
+ becomes a function, a window function that becomes a plain one) is now
15
+ offline. The drop and re-create is still one statement, but a plan the
16
+ serving application cached for a call to the old form fails ("cached plan
17
+ must not change result type"), and a call of the old kind no longer works.
18
+ A new body alone stays an online `CREATE OR REPLACE`.
19
+
8
20
  ## [0.3.0] - 2026-11-19
9
21
 
10
22
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pgdeclare
3
- Version: 0.3.0
3
+ Version: 0.3.1
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.3.0"
7
+ version = "0.3.1"
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"
@@ -17,7 +17,7 @@ file layout, bootstrap SQL, locking, failure classification) comes in through
17
17
  embeds it.
18
18
  """
19
19
 
20
- __version__ = "0.3.0"
20
+ __version__ = "0.3.1"
21
21
 
22
22
  from .config import DEFAULT_CONFIG, PgDeclareConfig
23
23
  from .models import (
@@ -1437,10 +1437,28 @@ def _diff_functions(desired: Schema, actual: Schema) -> list[Change]:
1437
1437
  func.kind != actual_func.kind
1438
1438
  or func.get_return_clause() != actual_func.get_return_clause()
1439
1439
  ):
1440
- # Use combined Drop+Create to keep them together
1441
- changes.append(
1442
- DropAndCreateFunction(function=func, old_kind=actual_func.kind)
1440
+ # One statement, so nothing ever finds it missing, but a
1441
+ # caller of the old form reads a different answer: a cached
1442
+ # plan for it fails ("cached plan must not change result
1443
+ # type") and a procedure is not called like a function. The
1444
+ # application still serving must be stopped: offline.
1445
+ what = (
1446
+ f"its kind changes from {actual_func.keyword.lower()} "
1447
+ f"to {func.keyword.lower()}"
1448
+ if func.kind != actual_func.kind
1449
+ else "its result changes, and a cached plan for a call "
1450
+ "to the old form fails"
1451
+ )
1452
+ change = DropAndCreateFunction(
1453
+ function=func,
1454
+ old_kind=actual_func.kind,
1455
+ category=ChangeCategory.OFFLINE,
1456
+ )
1457
+ change.description = (
1458
+ f"Drop and re-create {func.keyword.lower()} "
1459
+ f"{func.signature} (offline: {what})"
1443
1460
  )
1461
+ changes.append(change)
1444
1462
  else:
1445
1463
  changes.append(ReplaceFunction(function=func))
1446
1464
 
@@ -114,4 +114,4 @@ def test_the_default_config_is_neutral():
114
114
  def test_the_public_api_is_exported():
115
115
  for name in pgdeclare.__all__:
116
116
  assert hasattr(pgdeclare, name), name
117
- assert pgdeclare.__version__ == "0.3.0"
117
+ assert pgdeclare.__version__ == "0.3.1"
@@ -260,7 +260,8 @@ def _apply(sql_dir: Path, target_url: str, plan_db: str, content: str) -> None:
260
260
  """Apply `content`, then prove a fresh diff against it is empty."""
261
261
  config = PgDeclareConfig(report=lambda _line: None)
262
262
  _write(sql_dir, content)
263
- apply_declared_schema(target_url, sql_dir, plan_db, config=config)
263
+ # Recreating what a comment is on can be offline (a new result type).
264
+ apply_declared_schema(target_url, sql_dir, plan_db, offline=True, config=config)
264
265
  desired = build_desired_schema(sql_dir, target_url, plan_db, config=config)
265
266
  actual = introspect_schema(target_url, config=config)
266
267
  assert compute_diff(desired, actual, schemas=["public"]) == []
@@ -29,6 +29,7 @@ from pgdeclare import (
29
29
  from pgdeclare.changes import (
30
30
  AlterColumnType,
31
31
  CreateFunction,
32
+ ReplaceFunction,
32
33
  DropAndCreateFunction,
33
34
  DropAndCreateView,
34
35
  DropDomain,
@@ -174,6 +175,28 @@ class TestSignatureChanges:
174
175
  assert changes[0].category == ChangeCategory.OFFLINE
175
176
 
176
177
 
178
+ class TestResultChanges:
179
+ def test_a_new_result_is_offline(self):
180
+ # Same identity, so one statement, but a plan the serving version
181
+ # cached for the old result fails: "cached plan must not change
182
+ # result type".
183
+ old = _fn("f", "a int", "integer", 1, 1, body="RETURNS TABLE (x int) AS '1'")
184
+ new = _fn(
185
+ "f", "a int", "integer", 1, 1, body="RETURNS TABLE (x int, y int) AS '1'"
186
+ )
187
+ changes = compute_diff(_schema(new), _schema(old))
188
+ assert [type(c) for c in changes] == [DropAndCreateFunction]
189
+ assert changes[0].category == ChangeCategory.OFFLINE
190
+ assert "result changes" in changes[0].description
191
+
192
+ def test_a_new_body_stays_online(self):
193
+ old = _fn("f", "a int", "integer", 1, 1, body="RETURNS int AS '1'")
194
+ new = _fn("f", "a int", "integer", 1, 1, body="RETURNS int AS '2'")
195
+ changes = compute_diff(_schema(new), _schema(old))
196
+ assert [type(c) for c in changes] == [ReplaceFunction]
197
+ assert changes[0].category == ChangeCategory.ONLINE
198
+
199
+
177
200
  class TestDroppedRoutines:
178
201
  def test_an_undeclared_routine_is_a_contract_drop(self):
179
202
  gone = _fn("gone", "a int", "integer", 1, 1)
@@ -493,6 +516,39 @@ class TestDeployWhileTheOldVersionServes:
493
516
  target, sql_dir, plan, expect_converged=True, config=QUIET
494
517
  )
495
518
 
519
+ def test_a_new_result_is_refused_online(self, tmp_path, databases):
520
+ target, plan = databases
521
+ sql_dir = tmp_path / "sql"
522
+ _declare(sql_dir, V1)
523
+ apply_declared_schema(target, sql_dir, plan, config=QUIET)
524
+
525
+ # What a serving connection holds: a plan cached for the old result.
526
+ conn = psycopg2.connect(target)
527
+ conn.autocommit = True
528
+ try:
529
+ with conn.cursor() as cur:
530
+ cur.execute("PREPARE old_total AS SELECT * FROM total(1)")
531
+ cur.execute("EXECUTE old_total")
532
+ _declare(
533
+ sql_dir,
534
+ V1.replace(
535
+ "total(a int) RETURNS int LANGUAGE sql AS 'SELECT a'",
536
+ "total(a int) RETURNS bigint LANGUAGE sql AS 'SELECT a'",
537
+ ),
538
+ )
539
+ with pytest.raises(Exception, match="Migration execution failed"):
540
+ apply_declared_schema(
541
+ target, sql_dir, plan, expand_only=True, config=QUIET
542
+ )
543
+ cur.execute("EXECUTE old_total") # untouched: still answers
544
+ assert cur.fetchall() == [(1,)]
545
+
546
+ apply_declared_schema(target, sql_dir, plan, offline=True, config=QUIET)
547
+ with pytest.raises(psycopg2.Error, match="cached plan"):
548
+ cur.execute("EXECUTE old_total")
549
+ finally:
550
+ conn.close()
551
+
496
552
  def test_expand_keeps_old_calls_working_and_contract_drops(
497
553
  self, tmp_path, databases
498
554
  ):
@@ -407,8 +407,10 @@ class TestRoutineRoundTrip:
407
407
  .replace("'SELECT a + b'", "'SELECT x + y'")
408
408
  )
409
409
  # The new procedure signature competes with the old one for a call
410
- # of two arguments, and `step`'s renamed parameters break a call
411
- # naming the old ones, so both swaps are offline.
410
+ # of two arguments, `step`'s renamed parameters break a call naming
411
+ # the old ones, `tally`'s new result breaks a plan cached for the old
412
+ # one, and a procedure that becomes a function is called differently:
413
+ # all four swaps are offline.
412
414
  offline = [
413
415
  c
414
416
  for c in _plan(sql_dir, recreated, target_url, plan_db)
@@ -416,7 +418,9 @@ class TestRoutineRoundTrip:
416
418
  ]
417
419
  assert sorted(c.object_name for c in offline) == [
418
420
  "public.book(IN amount bigint, INOUT booked bigint)",
421
+ 'public.odd "proc"()',
419
422
  "public.step(x integer, y integer)",
423
+ "public.tally()",
420
424
  ]
421
425
  _apply(sql_dir, recreated, target_url, plan_db, offline=True)
422
426
  routines = _routines(target_url)
@@ -459,9 +463,10 @@ class TestRoutineRoundTrip:
459
463
  assert _routines(target_url) == [("row_no", "w", "")]
460
464
  assert _pending(sql_dir, target_url, plan_db) == []
461
465
 
462
- # A window function cannot be replaced by a plain one.
466
+ # A window function cannot be replaced by a plain one, and a call
467
+ # with OVER fails once it is: offline.
463
468
  plain = "CREATE FUNCTION row_no() RETURNS bigint LANGUAGE sql AS 'SELECT 1::bigint';"
464
- _apply(sql_dir, plain, target_url, plan_db)
469
+ _apply(sql_dir, plain, target_url, plan_db, offline=True)
465
470
  assert _routines(target_url) == [("row_no", "f", "")]
466
471
  assert _pending(sql_dir, target_url, plan_db) == []
467
472
 
@@ -516,16 +521,18 @@ class TestRoutineGrants:
516
521
  assert privileges() == [("tally",), ("work",)]
517
522
  assert _pending(sql_dir, target_url, plan_db, config) == []
518
523
 
519
- # A new result type recreates the aggregate: the grant is replayed.
524
+ # A new result type recreates the aggregate (offline): the grant is
525
+ # replayed.
520
526
  changed = granted.replace(
521
527
  "CREATE AGGREGATE tally(*) (SFUNC = int8inc, STYPE = int8, INITCOND = '0');",
522
528
  "CREATE AGGREGATE tally(*) (SFUNC = int4inc, STYPE = int4, INITCOND = '0');",
523
529
  )
524
- _apply(sql_dir, changed, target_url, plan_db, config)
530
+ _apply(sql_dir, changed, target_url, plan_db, config, offline=True)
525
531
  assert privileges() == [("tally",), ("work",)]
526
532
  assert _pending(sql_dir, target_url, plan_db, config) == []
527
533
 
528
- _apply(sql_dir, base, target_url, plan_db, config)
534
+ # Back to the base's result type: offline again.
535
+ _apply(sql_dir, base, target_url, plan_db, config, offline=True)
529
536
  assert privileges() == []
530
537
  assert _pending(sql_dir, target_url, plan_db, config) == []
531
538
 
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