Skip to content

fix: drop the ID sequences in the teardown script - #273

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/teardown-drops-sequences
Nov 17, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/teardown-drops-sequences

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • db-scripts/teardown/delete_tables.sql now drops the four viron.*_id_seq sequences after the tables. They are standalone (not OWNED BY a column), so DROP TABLE ... CASCADE left them behind, and a re-run of setup (CREATE SEQUENCE IF NOT EXISTS) kept counting from the old values. This is option 1 from The teardown script leaves the ID sequences behind, so a reset database does not restart IDs at 1 #272. The viron schema is left in place: dropping it was optional in the issue, and keeping it avoids deleting anything the teardown never created.
  • New TeardownScriptTest reads the real create_sequences.sql and delete_tables.sql files and runs them against H2 in PostgreSQL mode. It advances every sequence, tears down, sets up again, and asserts that each sequence starts at 1. A second test confirms the teardown still runs against an empty schema.
  • The README's project-tree line now says that the teardown drops the tables and ID sequences.

Closes #272

Test plan

  • mvn -B test: 682 tests run, 0 failures.
  • Regression check: with delete_tables.sql reverted to main, TeardownScriptTest fails (expected: 1 but was: 4). With the fix restored, it passes.
  • Not run against a real PostgreSQL. The sandbox can't start Postgres, so the scripts were only run on H2's PostgreSQL mode. DROP SEQUENCE IF EXISTS is standard PostgreSQL syntax, but a manual run of psql -f db-scripts/teardown/delete_tables.sql followed by setup is recommended before merge.

Merge note

This PR touches db-scripts/*, which is on the dev loop's do-not-auto-merge list. It is left open for human review.

Deferred issues

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

🤖 Generated with Claude Code

The four viron.*_id_seq sequences are standalone, so DROP TABLE ... CASCADE
left them behind and a re-run setup kept counting from the old values.
The teardown now drops them, and a test runs the real setup and teardown
scripts against H2 to pin that ids restart at 1.

Closes #272

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (performed inline. The Copilot reviewer could not be added: Could not resolve user with login 'copilot'):

  • Scope: PASS. Three files: the teardown script (the fix), the README tree line that describes it, and the new test. There is no unrelated churn.
  • Tests-new: PASS. No new production methods. TeardownScriptTest covers the changed script.
  • Tests-fix: PASS. Checked by running it, not by reasoning. With delete_tables.sql checked out from main, teardownThenSetup_restartsEverySequenceAtOne failed with expected: 1 but was: 4. With the fix restored, it passed.
  • Sibling structure: PASS. The test follows CreationDateSchemaTest's H2 setup: DataSourceConfig + DbInteractions, a PostgreSQL-mode in-memory URL, and closing Hikari in @AfterEach.
  • Sibling renames: PASS. Nothing was renamed.
  • Docs: PASS. The README is the only doc that mentions the teardown, and it is updated. The OpenAPI spec, MVP, PLANNING, REBUILD_PLAN, tickets and Postman are not affected, since no endpoint changed.
  • Issue resolution: PASS. The teardown script leaves the ID sequences behind, so a reset database does not restart IDs at 1 #272 option 1 is fully applied for all four sequences. The optional schema drop was left out on purpose, and the PR body says why.
  • CI: PASS. build, python-client (3.8) and python-client (3.12) are green on the head commit.
  • DTO boundary / Spec alignment / Java-Python parallelism / Override correctness: PASS (not applicable). No controller, DTO, endpoint, client or @Override changed.

Observations to weigh:

  • src/test/java/preponderous/viron/database/TeardownScriptTest.java:32: the script paths are relative to the working directory. That holds under Maven Surefire, which runs from the project root, and in CI, but an IDE run from another directory would fail to find the files.
  • src/test/java/preponderous/viron/database/TeardownScriptTest.java:86: runScript splits on ; after removing whole-line -- comments. That is enough for the current scripts, but it would break on a semicolon inside a string literal or on a trailing comment.
  • The scripts were run only on H2's PostgreSQL mode. A manual run against a real PostgreSQL is still recommended (see the test plan).

Summary: ready for human review. This PR is held from autonomous merge only because it touches db-scripts/*.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 3681a16 into main Nov 17, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the feature/teardown-drops-sequences branch November 17, 2026 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The teardown script leaves the ID sequences behind, so a reset database does not restart IDs at 1

1 participant