You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aa3475e
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -92,10 +92,13 @@ file, a list of files, or a directory of `.sql` migration files; see
92
92
[`sql[].schema`](configuration.md#sqlschema) for the accepted forms and the
93
93
order the files are read in.
94
94
95
-
- Only `CREATE TABLE`, `DROP TABLE`, and the `ALTER TABLE` forms listed in
96
-
[Ordered Table DDL](#ordered-table-ddl) update the schema model. The
97
-
statements listed in [Ignored Statements](#ignored-statements) are accepted
98
-
and leave it unchanged. Any other statement in a schema file is rejected.
95
+
- One rule decides every statement: only the `CREATE TABLE`, `DROP TABLE`, and
96
+
`ALTER TABLE` forms listed in [Ordered Table DDL](#ordered-table-ddl) and the
97
+
`CREATE TYPE ... AS ENUM` and `ALTER TYPE ... ADD VALUE` forms listed in
98
+
[Enum Types](#enum-types) update the schema model, and every other statement
99
+
a schema file records is accepted and leaves it unchanged. Only the few
100
+
statements listed in [Ignored Statements](#ignored-statements) are rejected
101
+
instead, because sqlcj cannot tell what they would do to the model.
99
102
- The statements of the schema files of one entry are applied in order to one
100
103
schema model, so each of them sees the tables and columns the statements and
101
104
files before it left.
@@ -244,9 +247,9 @@ left:
244
247
|`ALTER TYPE ... ADD VALUE '<label>' BEFORE '<neighbour>'`| Inserts the label directly before the neighbour. |
245
248
|`ALTER TYPE ... ADD VALUE '<label>' AFTER '<neighbour>'`| Inserts the label directly after the neighbour. |
246
249
|`ALTER TYPE ... ADD VALUE IF NOT EXISTS '<label>'`| Does nothing when the type already has the label. As PostgreSQL does, the existing label decides before the neighbour, so a neighbour the type does not have is not resolved at all. |
247
-
| Any other `ALTER TYPE` action, such as `RENAME TO`, `RENAME VALUE`, `OWNER TO`, `SET SCHEMA`, or an attribute change | Rejected. |
248
-
|`CREATE TYPE` of a composite, range, or shell type |Rejected. |
249
-
|`DROP TYPE`| Rejected. sqlcj's parser does not read the statement, so it is reported as a syntax error. |
250
+
| Any other `ALTER TYPE` action, such as `RENAME TO`, `RENAME VALUE`, `OWNER TO`, `SET SCHEMA`, or an attribute change | Rejected as `Unsupported ALTER TYPE action at line <n>`. |
251
+
|`CREATE TYPE` of a composite, range, or shell type |Ignored. A column of such a type is recorded with its declared type, as [Unsupported Types and DDL](#unsupported-types-and-ddl) describes. |
252
+
|`DROP TYPE`| Rejected. sqlcj's parser does not read the statement, so it is reported as a syntax error; see [Ignored Statements](#ignored-statements). |
250
253
251
254
Type names are matched case-insensitively, after their SQL identifier
252
255
delimiters are removed, and labels are matched exactly. A statement that repeats
@@ -359,7 +362,7 @@ are recorded with their declared type; see
359
362
| Column-level `CHECK (...)`| Accepted and ignored. |
360
363
| Table-level `FOREIGN KEY (...) REFERENCES ...`, named or unnamed | Accepted and ignored. |
361
364
| Table-level `CHECK (...)`, named or unnamed | Accepted and ignored. |
362
-
|Any statement outside [Ordered Table DDL](#ordered-table-ddl) and [Ignored Statements](#ignored-statements), such as `CREATE VIEW`| Rejected. |
365
+
|A table statement sqlcj's parser cannot read, such as `ALTER FOREIGN TABLE`| Rejected; see [Ignored Statements](#ignored-statements). |
363
366
| Any other table-constraint kind | Rejected. |
364
367
| Unparsable SQL | Rejected. |
365
368
@@ -392,8 +395,8 @@ statements and files before them left; the enum-type statements are listed in
392
395
|`ALTER TABLE ... ALTER COLUMN ... SET NOT NULL`| Models the column non-null. |
393
396
|`ALTER TABLE ... ALTER COLUMN ... DROP NOT NULL`| Models the column nullable. |
394
397
|`ALTER TABLE IF EXISTS ...`| Does nothing when the table is not modeled. It covers only the table, so a missing column of a modeled table still fails. |
395
-
| Any other `ALTER TABLE` action outside [Ignored Statements](#ignored-statements), such as `SET DEFAULT`| Rejected. |
396
-
|`DROP` of an object that is neither a table nor listed in [Ignored Statements](#ignored-statements), such as `DROP VIEW`| Rejected. |
398
+
| Any other `ALTER TABLE` action outside the constraint actions listed in [Ignored Statements](#ignored-statements), such as `SET DEFAULT`| Rejected as `Unsupported ALTER TABLE action at line <n>`. |
399
+
|`DROP` of any object other than a table, such as `DROP VIEW` or `DROP INDEX`| Ignored; see [Ignored Statements](#ignored-statements). |
397
400
398
401
One `ALTER TABLE` may state several actions; they are applied in the written
399
402
order. Table and column names are matched case-insensitively, as query analysis
@@ -413,22 +416,64 @@ sqlcj: Invalid schema source /home/dev/project/sql/migrations/V2__orders.sql: Co
413
416
## Ignored Statements
414
417
415
418
A schema file records the whole history of a database, not only its tables, so
416
-
these statements are accepted and leave the schema model exactly as the
417
-
statements and files before them left it:
418
-
419
-
| Statement | Notes |
419
+
one rule decides every statement it states: a statement sqlcj models is applied,
420
+
and every other statement is accepted and leaves the schema model exactly as the
421
+
statements and files before it left it. There is no list of accepted kinds to
422
+
keep up to date.
423
+
424
+
The modeled statements are the `CREATE TABLE`, `DROP TABLE`, and `ALTER TABLE`
425
+
forms of [Ordered Table DDL](#ordered-table-ddl) and the
426
+
`CREATE TYPE ... AS ENUM` and `ALTER TYPE ... ADD VALUE` forms of
427
+
[Enum Types](#enum-types). Everything else a migration history holds is ignored,
428
+
including
429
+
430
+
-`CREATE INDEX`, `CREATE UNIQUE INDEX`, `ALTER INDEX`, and `DROP INDEX`,
431
+
-`COMMENT ON TABLE`, `COMMENT ON COLUMN`, and `COMMENT ON VIEW`, the only
432
+
`COMMENT ON` targets sqlcj's parser reads; see below,
433
+
-`CREATE EXTENSION`, `CREATE SEQUENCE`, `ALTER SEQUENCE`, and `DROP SEQUENCE`,
434
+
-`GRANT`, `REVOKE`, and `ALTER DEFAULT PRIVILEGES`,
435
+
-`CREATE FUNCTION`, `CREATE PROCEDURE`, `DROP FUNCTION`, `CREATE TRIGGER`, and
436
+
`DROP TRIGGER`; a function or procedure body must be dollar-quoted, as below,
437
+
-`INSERT`, `UPDATE`, `DELETE`, and `TRUNCATE`, a migration's data statements,
438
+
-`CREATE VIEW`, `DROP VIEW`, and the `CREATE`, `REFRESH`, and `DROP` forms of
439
+
`MATERIALIZED VIEW`,
440
+
-`CREATE SCHEMA` and `DROP SCHEMA`,
441
+
-`SET`, `RESET`, `ANALYZE`, `COMMIT`, and a plain `SELECT`, such as the
442
+
`SELECT pg_catalog.set_config(...)` a `pg_dump` snapshot opens with,
443
+
-`CREATE POLICY`, `CREATE ROLE`, `CREATE USER`, and `ALTER ROLE`,
444
+
-`CREATE DOMAIN` and `ALTER DOMAIN`,
445
+
- a `CREATE TYPE` of a composite, range, or shell type, and
446
+
- a statement sqlcj's parser reports only as opaque text and that does not open
447
+
as table or type DDL, such as `ALTER FUNCTION`, `ALTER SCHEMA`,
448
+
`CREATE AGGREGATE`, or `CREATE CAST`.
449
+
450
+
An ignored statement is not resolved against the schema at all, so it may name a
451
+
table or a column the snapshot does not model: a view over an unmodeled table
452
+
and a `TRUNCATE` of one are both accepted.
453
+
454
+
These statements are rejected rather than ignored, because sqlcj cannot tell
455
+
what they would do to the schema model:
456
+
457
+
| Statement | Diagnostic |
458
+
| --- | --- |
459
+
| An `ALTER TABLE` action outside [Ordered Table DDL](#ordered-table-ddl) and the constraint actions below |`Unsupported ALTER TABLE action at line <n>`|
460
+
| An `ALTER TYPE` action other than `ADD VALUE`|`Unsupported ALTER TYPE action at line <n>`|
461
+
| A `CREATE FUNCTION` or `CREATE PROCEDURE` whose body is not delimited by the untagged `$$ ... $$`|`Unsupported schema statement: CREATE FUNCTION without a dollar-quoted body at line <n>`, with `CREATE PROCEDURE` for a procedure |
462
+
| A statement sqlcj's parser reports only as opaque text and that opens as table or type DDL |`Unsupported schema statement: ALTER FOREIGN TABLE at line <n>`, quoting the opening words |
463
+
464
+
An opaque statement opens as table DDL when its first words are `CREATE`,
465
+
`ALTER`, or `DROP`, then any of `GLOBAL`, `LOCAL`, `TEMP`, `TEMPORARY`,
466
+
`UNLOGGED`, or `FOREIGN`, then `TABLE`, and as type DDL when they are `CREATE`
467
+
or `ALTER`, then `TYPE`. The words are matched case-insensitively and the
468
+
diagnostic quotes them in upper case, single-spaced, so both
469
+
`ALTER FOREIGN TABLE ft ADD COLUMN x integer` and its lower-case spelling are
470
+
rejected as `Unsupported schema statement: ALTER FOREIGN TABLE at line <n>`.
471
+
472
+
These `ALTER TABLE` actions are ignored like any other unmodeled statement,
473
+
except that the statement still resolves its table:
474
+
475
+
| Action | Notes |
420
476
| --- | --- |
421
-
|`CREATE INDEX`, `CREATE UNIQUE INDEX`||
422
-
|`ALTER INDEX`||
423
-
|`DROP INDEX`, `DROP INDEX IF EXISTS`||
424
-
|`COMMENT ON TABLE`, `COMMENT ON COLUMN`, `COMMENT ON VIEW`| These are the only `COMMENT ON` targets sqlcj's parser reads; see below. |
425
-
|`CREATE EXTENSION`, `CREATE EXTENSION IF NOT EXISTS`||
0 commit comments