pgschema.toml is the project configuration file. It declares which tables are config tables, so that dump exports their rows and plan and apply keep them in sync.
Overview
The
pgschema.toml file is automatically loaded when present in the current directory. No flag is needed.pgschema.toml file in your project directory:
[data]
string[]
default:"[]"
Glob patterns for tables whose rows pgschema manages. Patterns are matched against unqualified table names in the target schema, with the same rules as
.pgschemaignore: * matches any characters, ? matches one, and a leading ! negates a pattern.dumpwrites its rows todata/<table>.csvand appends a\copydirective to the schema file. No flag is needed, but--fileis required so the CSV files have a location.planandapplycompare its rows with the target database and generateINSERT,UPDATE, andDELETEsteps. Rows in the database that are not in the file are deleted.- The table must have a primary key. Rows are matched by it.
Consistency Rules
The config and the schema files must agree, so that reading the schema alone shows exactly which tables are managed:-
Every listed table needs a
\copydirective. If a table matches[data]but the schema has no directive for it,planandapplyfail:This makes “list the table, then dump” the only way to start managing a table, and prevents a plan that would delete every row of a table you have not exported yet. -
Every
\copydirective needs a listed table. A directive for a table that does not match[data]is an error, since it is almost always a forgotten config line. -
A table cannot be both managed and ignored. A table that matches
[data]here and[tables]in.pgschemaignoreis an error.
Relationship to .pgschemaignore
Ignore patterns stay in .pgschemaignore. pgschema.toml holds project configuration that is not about exclusion. Both files are loaded from the current directory.
