Skip to content

Make schema.sql drop nothing and safe to run in sections - #175

Draft
mapgie wants to merge 3 commits into
mainfrom
ccr-4c1e42cb-qk67nv
Draft

mapgie wants to merge 3 commits into
mainfrom
ccr-4c1e42cb-qk67nv

Conversation

@mapgie

@mapgie mapgie commented Oct 6, 2026

Copy link
Copy Markdown
Owner

What

  • No more DROP POLICY. All 20 policies are now created only if they're missing (checked against pg_policies), instead of being dropped and recreated on every run. Supabase's SQL Editor no longer has a policy DROP to flag as destructive, and a re-run changes nothing.
  • CHECK constraints are replaced only when needed. todos_due_period_check and tags_repeat_unit_check are replaced only if they're missing or lack the newest allowed value (checked via pg_get_constraintdef). On a database that already matches, nothing runs.
  • The nfc_tags section works on its own. The one-time copy used to read tags.nfc_id, which only exists after an earlier section runs, so running the nfc_tags section alone on a database without that column failed. It now checks for the column. If it's missing, it copies from tag_id and skips app-made UUID keys, which mean "no tag".

The file still never deletes a table, a column or a row.

Checked against Postgres 16

Case Result
Fresh database, whole file twice No errors; 20 policies
Old-shape database (no tags.nfc_id), nfc_tags section alone Stickered chores copied; UUID-keyed chore left without a tag
Same database, then the whole file Same row counts in tags, scans and todos; old due_period CHECK widened
Detach a tag, re-run file and section Tag stays detached

Tests and docs

🤖 Generated with Claude Code

https://claude.ai/code/session_019GVgMQ79V38GrDnnF6mMB7


Generated by Claude Code

claude added 3 commits October 6, 2026 08:28
Policies are now created only when missing (pg_policies) instead of
dropped and recreated, and the two CHECK constraints are replaced only
when missing or out of date. Supabase's SQL Editor no longer flags the
file as destructive, and a re-run is a no-op.

The nfc_tags carry-across checks that tags.nfc_id exists. On a database
that never got that column it copies from tag_id instead, skipping
app-made UUID keys, so the section works when pasted on its own.

Checked against Postgres 16: fresh database twice, an old-shape database
with only the nfc_tags section, the whole file after it, and a re-run
after a detach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019GVgMQ79V38GrDnnF6mMB7
The old pin built with the Gradle build cache on, so a PR that changes
no app source restored every compile task from the cache and CodeQL
failed with "could not process any code". android-Actions #37 added
--no-build-cache to the CodeQL Build step; 55fd017 is its current main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019GVgMQ79V38GrDnnF6mMB7
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.

2 participants