From d007daa31748a6a5bc9bc7c932469fd6da215f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20=C3=87engel?= Date: Sat, 10 Oct 2026 00:36:07 +0300 Subject: [PATCH] feat(schema): ignore unmodeled statements and report errors in SQL terms Only CREATE/ALTER/DROP TABLE, CREATE TYPE ... AS ENUM, and ALTER TYPE ... ADD VALUE change the schema model; every other parsed statement, including views, schemas, session statements, TRUNCATE, policies, roles, domains, and non-enum CREATE TYPE, is now ignored without being resolved against the schema. Statements that may still change the model are rejected with SQL-term messages instead of parser class names: unsupported ALTER TABLE and ALTER TYPE actions, functions or procedures without a dollar-quoted body, and opaque statements that open as table or type DDL, such as ALTER FOREIGN TABLE. --- docs/postgresql.md | 175 ++++++++++----- .../schema/parser/DefaultSchemaParser.java | 211 +++++++++++------- .../SqlcjCompilerIntegrationTest.java | 4 +- .../parser/DefaultSchemaParserTest.java | 126 ++++++++--- 4 files changed, 346 insertions(+), 170 deletions(-) diff --git a/docs/postgresql.md b/docs/postgresql.md index be4155b..7df8a81 100644 --- a/docs/postgresql.md +++ b/docs/postgresql.md @@ -92,10 +92,13 @@ file, a list of files, or a directory of `.sql` migration files; see [`sql[].schema`](configuration.md#sqlschema) for the accepted forms and the order the files are read in. -- Only `CREATE TABLE`, `DROP TABLE`, and the `ALTER TABLE` forms listed in - [Ordered Table DDL](#ordered-table-ddl) update the schema model. The - statements listed in [Ignored Statements](#ignored-statements) are accepted - and leave it unchanged. Any other statement in a schema file is rejected. +- One rule decides every statement: only the `CREATE TABLE`, `DROP TABLE`, and + `ALTER TABLE` forms listed in [Ordered Table DDL](#ordered-table-ddl) and the + `CREATE TYPE ... AS ENUM` and `ALTER TYPE ... ADD VALUE` forms listed in + [Enum Types](#enum-types) update the schema model, and every other statement + a schema file records is accepted and leaves it unchanged. Only the few + statements listed in [Ignored Statements](#ignored-statements) are rejected + instead, because sqlcj cannot tell what they would do to the model. - The statements of the schema files of one entry are applied in order to one schema model, so each of them sees the tables and columns the statements and files before it left. @@ -244,9 +247,9 @@ left: | `ALTER TYPE ... ADD VALUE '