Skip to content

feat(schema): apply ordered CREATE, ALTER, and DROP TABLE statements - #45

Merged
omer-cengel merged 2 commits into
masterfrom
feature/ordered-schema-table-ddl
Sep 27, 2026
Merged

omer-cengel merged 2 commits into
masterfrom
feature/ordered-schema-table-ddl

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

Schema files are now applied in order to one schema model, so a migration directory that creates tables and later alters or drops them loads as the schema the application actually has, instead of failing on the first statement other than CREATE TABLE.

Changes

  • Statements of an entry's schema files apply in file order; each sees the tables and columns left by the statements and files before it.
  • CREATE TABLE and DROP TABLE (one or several names) update the model. CREATE TABLE IF NOT EXISTS does nothing for an existing table, and DROP TABLE IF EXISTS does nothing for a missing one.
  • ALTER TABLE supports ADD COLUMN, DROP COLUMN, RENAME COLUMN, RENAME TO, ALTER COLUMN ... TYPE, and ALTER COLUMN ... SET/DROP NOT NULL, applied in written order, with ADD COLUMN IF NOT EXISTS, DROP COLUMN IF EXISTS, and ALTER TABLE IF EXISTS.
  • Added columns are appended and typed like CREATE TABLE columns. Renamed and retyped columns keep their position, and a retyped column keeps its nullability. Recorded primary-key and unique constraints follow a renamed column and are removed with a dropped one.
  • A reference to a missing table or column fails, and so does a statement that would repeat a table name or a column name within a table: Table not found in schema: <name>, Column not found in table <table>: <column>, Table already exists in schema: <name>, Column already exists in table <table>: <column>. A repeated CREATE TABLE, which previously loaded silently, now fails.
  • Every other ALTER TABLE action, including SET/DROP DEFAULT, constraint changes, SET STATISTICS/STORAGE/COMPRESSION, and identity or generated-column changes, fails with Unsupported schema statement: Alter. DROP of anything other than a table is still rejected.
  • Table and column names match case-insensitively after identifier delimiters are removed.
  • Documentation describes the accepted forms, their handling, and the failure messages.

Scope and non-goals

  • No statement beyond the listed table DDL is accepted; views, indexes, comments, enums, and other statements are still rejected.
  • ALTER COLUMN ... SET DATA TYPE and ALTER TABLE ONLY are not supported, and a USING clause is not evaluated beyond reading the new type.
  • Schema-qualified names are not modeled, and migrations are not executed against a database.

@omer-cengel
omer-cengel merged commit 836ecfb into master Sep 27, 2026
6 checks passed
@omer-cengel
omer-cengel deleted the feature/ordered-schema-table-ddl branch September 27, 2026 20:22
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