Skip to content

0.1.3: a literal DEFAULT before CHECK, and datetime modifiers, survive schema conversion - #1

Merged
ralyodio merged 3 commits into
mainfrom
fix/default-literal-before-check
Sep 25, 2026
Merged

ralyodio merged 3 commits into
mainfrom
fix/default-literal-before-check

Conversation

@ralyodio

Copy link
Copy Markdown
Contributor

Two schema-converter bugs met while porting moshcoding.com's runtime DDL:

  • role text not null default 'viewer' check (role in (...)) converted to default 'viewer' (CHECK) (role in (...)), which Postgres rejects. rewriteDefault/stripDefault measured the start of the DEFAULT value on the code mask, where the blanked string literal reads as whitespace, so \sdefault\s+ swallowed 'viewer' and took CHECK as the value. The gap after DEFAULT is now measured on the text.
  • default (datetime('now','+7 days')) became now(), dropping the modifier. Only the bare datetime('now') is special-cased now; the function rewriter turns the rest into (now() + interval '7 days').

Unit test added for both; 126/126 pass.

🤖 Generated with Claude Code

ralyodio and others added 3 commits September 25, 2026 16:28
…e schema conversion

rewriteDefault/stripDefault measured the start of the DEFAULT value on the code
mask, where a string literal is blanked to spaces, so `default 'viewer' check
(...)` skipped past 'viewer' and rewrote CHECK as the default value: the
converted DDL read `default 'viewer' (CHECK) (role in (...))` and failed to
parse. Any app that runs its CREATE TABLE statements at start-up through the
client hit this (moshcoding). The gap after DEFAULT is now measured on the
text.

`default (datetime('now','+7 days'))` was short-circuited to now(), dropping
the modifier; only the bare datetime('now') form is special-cased now, and
the function rewriter produces (now() + interval '7 days') for the rest.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@ralyodio
ralyodio merged commit efcb0d3 into main Sep 25, 2026
4 checks passed
@ralyodio
ralyodio deleted the fix/default-literal-before-check branch September 25, 2026 16:37
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.

1 participant