Skip to content

Graphic preview

100%
Page type: concept

Database URLs and dev databases

Accepted database URL formats, and the difference between the target, dev, shadow, and throwaway databases.

Edge documents the current development build and may describe unreleased behavior. To use those commands, build Ptah from master. For an installed release, select its version in the header.

Every Ptah command that touches a database takes a URL, and the URL’s scheme selects the engine. The same syntax names databases in four roles: the target you are changing, and up to three kinds of disposable databases that exist so mistakes happen somewhere harmless. This page defines all four; other pages link here instead of redefining them.

Engine Example
PostgreSQL postgres://user:pass@localhost:5432/app
MySQL mysql://user:pass@localhost:3306/app (Go-driver form mysql://user:pass@tcp(localhost:3306)/app is also accepted)
MariaDB mariadb://user:pass@localhost:3306/app (the Atlas CLI spelling maria://user:pass@localhost:3306/app is also accepted)
SQLite sqlite://relative.db, sqlite:///absolute/path/app.db, sqlite:file:C:/absolute/windows/path/app.db, sqlite:///:memory:, sqlite:file:memdb1?mode=memory&cache=shared
SQL Server sqlserver://sa:pass@localhost:1433?database=app (plus a Ptah-only schema parameter — see SQL Server)
ClickHouse clickhouse://user:pass@localhost:9000/app
CockroachDB cockroachdb://user:pass@localhost:26257/app
YugabyteDB yugabytedb://user:pass@localhost:5433/app
Oracle oracle://user:pass@localhost:1521/service (renders, plans, reads a live catalog, and runs versioned migrations)
YDB, through its provider ydb://localhost:2136/local, or ydbs:// over TLS (see YDB)
Spanner’s PostgreSQL interface, through its provider spanner://localhost:5432/app, with cloudspanner:// and google-spanner:// as the same address (see Spanner)

Scheme aliases normalize to the canonical dialect (postgresql://, sqlite3://, mssql://, crdb://, ysql://, ch://, and more) — the full alias list is on the Database support matrix. A URL with an unrecognized scheme fails with unsupported database dialect.

A MySQL or MariaDB server behind a Unix socket takes the Atlas CLI socket form, mysql+unix://user:pass@/run/mysqld/mysqld.sock?database=app, or mariadb+unix:// and maria+unix://: the path is the socket, database names the database, and a host is ignored. The Go-driver form mysql://user:pass@unix(/run/mysqld/mysqld.sock)/app reaches the same socket.

A MySQL or MariaDB server whose certificate a private certificate authority signed is verified with ssl-ca, the path of a PEM file of CA certificates: mysql://user:pass@db.internal:3306/app?ssl-ca=/etc/ptah/mysql-ca.pem. The connection then requires TLS and verifies the certificate and the host name against that file alone, for that URL only. A relative path is read from the directory the command runs in. The rules, the refused combinations and a local example are in MySQL and MariaDB.

A MySQL or MariaDB URL naming no database is the whole server, as in the Atlas CLI; as a dev database it is a dev server.

A password holding a character a URL reserves, such as @ : / ? # %, is percent-encoded in a URL. The Go-driver form takes it as written, because that driver reads a password up to the last @ before the last /. A URL written with such a character raw is refused, and the error says so.

Ptah never repeats a password. Output, errors and reports show an address with its password as *** and the value of a secret parameter, such as sslpassword, authToken or TOKEN, as redacted, in every form an engine takes: a URL, a Go-driver DSN with or without a scheme, and a keyword, ADO or ODBC string. A secret-named run-time parameter that PostgreSQL’s options setting passes, such as -c app.jwt_secret=..., is shown as redacted too. A setting whose name holds key, token, secret, credential or jwt and whose value is a boolean, such as allowPublicKeyRetrieval=true or _foreign_keys=false, is a flag and keeps its value; a password setting is hidden whatever its value. The rest of the address stays, so the line still says which database it means.

A password the address repeats in another part, such as the database name, the host or the user, is hidden there by the rule below, which is the rule a driver’s error is held to: postgres://app:hunter22@db/hunter22 shows as postgres://app:***@db/***. The line that names the address and the error that follows it hide the same values. The exception is a password that is a word of the address’s grammar: the scheme, the name of a setting, or redacted. The line keeps those words, and the error, which is free text, does not, so with the password sslmode the line shows ?sslmode=bogus and the error ?***=bogus. A part of the address that only holds a short password’s letters, as the database execute holds x, stays.

A driver’s or a server’s error can quote the address, or what the driver read from it, and a hook or another program Ptah starts can print a password it was given. Ptah takes each secret it knows of out of that text:

  • A secret of five characters or more is taken out wherever it occurs, glued to other text too, as in -pSecret1 or \nSecret1.
  • A shorter one is taken out only where it stands as a credential:
    • between the : or the / and the @ of an address, as written or percent-encoded: app:...@host, app/...@host;
    • after the user name of the address and a :, and before a space or the end of a line, as curl’s -u app:... and a line of a password file write it;
    • as the whole value of a secret setting after an = or a :, such as password=, PGPASSWORD=, password: or the JSON "password": ";
    • after a -p that follows a space, a quote or the start of the text;
    • after --password and after Bearer;
    • after PASSWORD or IDENTIFIED BY and a single or a double quote, or the E' that opens a PostgreSQL escape string.

A short password in any other place stays, so with the password x an error still reads database=execute, and with the password 1 it still reads 127.0.0.1:1. A word that only holds a short password’s letters stays whole, and does not show the password by what is missing from it. A program that writes a short password in another shape prints it.

The same rule holds for every other secret Ptah takes out of text: a role password in a server’s answer, an embedding provider’s API key in a response body, a sensitive = true variable of atlas.hcl, and the address and the credential a provider conformance run holds a provider’s replies to.

The target database is the one a command reads or changes: --db-url on native commands, --url on Atlas-compatible ones. It is the only database whose state matters after the command exits.

A dev database (--dev-url) is a disposable replay target used for validation:

  • ptah migrations validate and ptah migrations lint clean it and replay the migration directory on it to prove the SQL executes;
  • schema apply rehearses its plan on it before touching the target;
  • schema diff replays a migration directory on it, and creates a --from schema file on it when --to is a database or migration directory;
  • Atlas-compatible verbs use it for planning, linting, and rollback verification.

A dev or shadow URL given for the run, on the command line or through its PTAH_* variable, is opened even when the run needs nothing from it, such as ptah schema diff of two schema files, ptah schema compare, ptah schema plan or a ptah migrations down with nothing to roll back. A URL nothing answers on then fails this run, while the mistake is in front of the operator, rather than the first later run that needs the database. The dev: key in ptah.yaml is different: it is a default for every command in the project, so a native command that needs nothing from the dev database does not fail on a dev: URL nothing answers on. ptah schema inspect of a database never opens a dev URL, wherever it came from.

ptah-compat opens every dev URL it is given, from a flag or from atlas.hcl, because the Atlas CLI fails on one it cannot reach. Its schema inspect of a database is the exception, as it is on the Atlas CLI.

Two kinds of URL are read without a connection in such a run. A docker URL, docker:// or docker+<engine>://, is read for the server its tag names, and no container is started. When a selected executable provider provisions the URL’s engine, only the engine is read, and the provider is asked for no database. A URL whose engine is not the target’s is refused. A sqlite:// URL or a file path is not opened, since opening it would create the file, so a SQLite dev path that does not exist is not refused there.

A dev database must hold nothing the reset would drop when a command starts. Ptah refuses a table before anything is dropped, as the Atlas CLI does, and any other such object too. Ptah then cleans the replay realm before migration execution and after the replay, failed or not. Commands read the replayed state before the final cleanup, on the same session. No fixed time limit applies to a cleanup: it takes as long as emptying the realm takes. After an interrupt, the cleanup has 30 seconds to finish; a second interrupt stops the process at once.

Everything a dev database runs stays inside it. Where a schema names a database rather than a namespace — MySQL, MariaDB, and ClickHouse — a plan carrying the target’s schema name is re-scoped onto the dev database before it is rehearsed, and a statement naming some third database is refused instead of run.

mysql://, mariadb:// and maria:// open one driver, and the server’s version banner, not the scheme, says which engine answers. A dev URL may spell the family differently from its target, and two spellings of one database are one database. schema apply and migrate diff refuse a MySQL dev database for a MariaDB target, and the reverse.

A shadow database (--shadow-db) is a disposable verification target for commands that write or record migrations: ptah migrations generate replays the directory — including the new migration, up, down, and up again — before keeping any files, and ptah migrations checkpoint and ptah migrations baseline use it to verify that migrations reproduce the expected schema before anything is recorded. ptah migrations down uses it to verify the rollback plan before changing the target.

The shadow database must meet the same rule and must not be the target’s live database realm. Ptah checks both before changing either database, and empties the shadow database again after each run. A replay on the shadow database refuses the same statements as a replay on a dev database (see statement forms that fail closed). A docker URL and trust in the SQL lift those refusals there. PTAH_DEV_SERVER_DISPOSABLE does not: a shadow database is often a database on the target’s own server, and the cleanup of a server the run owns drops roles the target may use. A replay on the shadow database does not keep one session from migration to migration, so a temporary table, which a dev database replay on PostgreSQL or SQLite may stage data in, is refused there.

A throwaway test database is what ptah migrations test and ptah schema test run cases against: by default a fresh ephemeral SQLite database per case, or the database passed with --db-url when tests must exercise a real server dialect — see Test migrations and schemas. On YDB the provider runs the cases in a dev realm in that database.

  • Disposable means Ptah may drop everything it supports. Dev and shadow database workflows clean user objects, and test seed steps bypass the seeder’s protected-environment guards. Point these flags at scratch databases only, never at a real environment. Rollback verification, schema apply, schema diff, and migrate diff refuse, before any reset, a dev or shadow URL naming a database they read, by URL or by the realm each server reports. Equal network database names fail closed across different endpoints because DNS aliases and replicated members cannot be proven independent before destructive cleanup. Two SQLite databases in memory are one database only when both URLs open one shared-cache name, so an in-memory dev database beside an in-memory target is accepted, under the target’s URL too. Cleanup rejects system, template and metadata databases, and a server’s default database unless the run owns it.
  • Migration-diff scope does not reduce the replay realm. Repeated --schema values select which schemas migrate diff compares and emits. They do not limit which schemas a migration may create or which user schemas final cleanup removes. PostgreSQL extensions remain in both scoped projections: an extension is a database-wide identity, and its schema records installation placement rather than ownership by that schema. An extension declared on both sides remains synced even when installed outside the named schemas; an extension the replay created and the desired schema omits remains an explicit global removal. One the dev database held when the command started is its environment: a comparison leaves it out unless the desired schema declares it, so no migration drops it.
  • The replay realm follows the database engine. PostgreSQL, CockroachDB, and YugabyteDB cleanup treats all user schemas and user-installed extensions in the selected database as one dependency graph. The row-security policies of its tables go before any relation: a policy holds back each relation it reads, so tables whose policies read each other’s table are dropped too. Extensions the dev database held when the run started stay installed, with everything they own, so a migration may use a type from one without creating it, as under Atlas; a schema one is installed in is emptied in place. A dev URL that selects a schema with search_path also keeps the database’s other schemas as they were, public included. An extension the run created is dropped with the schemas and tables it owns; TimescaleDB’s catalog schemas are this shape. So are PostgreSQL and YugabyteDB default privileges: the global ones, and with search_path those set in the selected schema. A default the run set is taken back, so a Supabase image works as a dev database. MySQL, MariaDB, and ClickHouse cleanup owns the selected database. SQL Server cleanup owns all supported user schemas in the selected database. SQLite cleanup owns main on one pinned session. YDB has no SQL that creates a database, so its provider gives a run a dev realm instead: a directory under ptah_dev in the database its dev, shadow or test URL names, which the run treats as its whole database and the provider removes at the end. A run against the database itself leaves ptah_dev out, so the URL may name the target; see YDB.
  • PostgreSQL cleanup gives back the schema it empties. The schema the dev URL selects, public when it selects none, comes back after the cleanup with the owner, grants and comment it had when the run started. A role created on the server afterwards can use public as it could before. A run that revokes USAGE on public or comments it does not hand the change to the next run, and neither does one whose dev database keeps an extension in public, where the schema is emptied in place. A schema the connecting role does not own is emptied in place too, since only its owner may drop it. On PostgreSQL 13 and 14 the bootstrap superuser owns public in every new database, so a dev database an ordinary role owns is this case. Ptah refuses such a schema before it drops anything when the role holds a grant option on it, because the cleanup could not take back what a run grants there.
  • MySQL-family cleanup needs global catalog visibility. MySQL cleanup credentials require global SELECT, DROP, ALTER, ALTER ROUTINE, EVENT, LOCK TABLES, and PROCESS. MySQL also requires global TRIGGER and, on MySQL 8.0.20 and newer, SHOW_ROUTINE; MariaDB requires global SHOW VIEW. Ptah checks these privileges before destructive DDL. It fails closed when another user database contains a routine, event, or trigger because stored-program bodies can reference the cleanup realm without a catalog dependency. Use dedicated server instances and credentials only for disposable dev databases.
  • ClickHouse realm cleanup requires 24.11 or newer. Ptah uses CHECK GRANT with global SHOW DATABASES and SHOW TABLES to prove complete catalog visibility before dropping objects. ClickHouse does not expose ordinary-view dependencies, so Ptah fails closed when another user database contains a view, materialized view, live/window view, dictionary, or Buffer, Distributed, or Merge table. Older servers fail before cleanup because role-aware visibility cannot be proven safely.
  • PostgreSQL-family cleanup keeps the database-scoped artifacts it found. Publications, subscriptions, logical replication slots, event triggers, and non-extension foreign-data wrappers, servers, or user mappings the dev database held when the command started are its environment, as under Atlas: the realm cleanup leaves them and checks they are still there. PostgreSQL and YugabyteDB reject one the run created before DDL, since the cleanup cannot remove it. A PostgreSQL publication is the exception: replaying a desired schema that declares one creates it, so the cleanup drops each publication the dev database did not hold when the command started, after the check that refuses the rest. A replay may create, change and drop its own publications. It may not change or drop one the dev database held, such as supabase_realtime, since the cleanup keeps that publication as it finds it. Where the server cannot list its publications when the command starts, every publication statement is refused. Ptah lists them from catalogs and views any role may read, user mappings from pg_user_mappings, so the check runs the same for an ordinary role that owns the dev database as for a superuser. An object the server created when it built the database template is not counted: YugabyteDB 2026.1.2 puts the foreign server yb_global_views_server into every database, and the cleanup leaves it, and the extensions it depends on, in place. PostgreSQL also removes and verifies database large objects transactionally. YugabyteDB does not run that PostgreSQL-specific large-object operation.
  • A docker block’s starting point is kept whole. A PostgreSQL dev database an atlas.hcl docker block provisions starts from what its image and baseline leave. Cleanup returns that database to the starting point instead of emptying the realm, and refuses when the run dropped part of it or changed what no statement restores.
  • SQL Server cleanup rejects replication state. A replication-enabled database or replicated table fails before DDL, along with other unsupported database-scoped artifacts. Remove replication configuration or use a dedicated disposable database before replay.
  • Cross-realm operations fail before execution. Ptah rejects direct statements that switch or mutate another database, protected namespace, server, cluster, another session’s temporary namespace, external file, or attached SQLite database. It also rejects statement forms whose nested SQL cannot be confined safely during replay.
  • Replay cleanup is serialized by realm. PostgreSQL, YugabyteDB, MySQL, MariaDB, and SQL Server use database advisory locks, and the YDB provider a semaphore on the coordination node ptah_locks, keyed by the database and the dev realm. SQLite, ClickHouse, and CockroachDB use an operating-system file lock keyed by the normalized database identity. That file lock coordinates only Ptah processes that resolve the same temporary lock path and can access it, normally processes running as the same operating-system user with the same temporary-directory configuration. Different users, different temporary directories, other hosts, and non-Ptah clients are not coordinated. Cross-host ClickHouse and CockroachDB replay is unsupported because neither engine provides the required effective session advisory lock.
  • Match the target engine. Replay verification proves the SQL executes on the engine it ran against, so a dev or shadow database should run the same engine (and ideally the same version) as the target.
  • Match the target’s collation on SQL Server. The collation decides which names are one name, so a dev or shadow database under another collation builds another state than the target holds. A command that holds both connections compares how the two servers read names that differ in case, in accent, in width and in kana, and refuses when they differ, naming both collations. See Identifier collation.
  • Every flag has an environment variable. PTAH_DB_URL, PTAH_DEV_URL, and PTAH_SHADOW_DB set the corresponding flags, which keeps credentials out of CI command lines. A malformed non-empty value fails before command execution. See Configuration.

Replay rejects SQL sublanguages and storage mechanisms whose effects cannot be proven to stay inside the disposable realm:

  • PostgreSQL-family DO, CALL, routine creation or alteration, foreign-table creation or alteration, foreign servers, IMPORT FOREIGN SCHEMA, a search_path other than the empty one, SELECT INTO protected namespaces, and CockroachDB’s ALTER DEFAULT PRIVILEGES FOR ALL ROLES without IN SCHEMA.

  • MySQL and MariaDB executable comments, CALL, a CREATE or ALTER of an event, a trigger, a routine or a MariaDB package or package body, prepared statements, MariaDB compound statements outside a stored program, such as BEGIN NOT ATOMIC or an Oracle-mode block that begins with DECLARE or with a BEGIN other than BEGIN or BEGIN WORK, LOAD DATA/LOAD XML, IMPORT TABLE, and externally backed FEDERATED, CONNECT or SPIDER tables, or a table with a CONNECTION option. A DEFINER clause is read as the server reads it, an unquoted host such as app@$ included. A CREATE or ALTER whose words the guard cannot follow to a kind of object it knows is refused, since it may define a body. On MariaDB, the statement a SET STATEMENT ... FOR or an ANALYZE runs is checked as a statement of its own. A SET of a global or persisted variable is refused in any spelling: SET GLOBAL, SET @@global.x, or an item of a longer list. A SET NAMES, SET CHARACTER SET or character_set_client change to a character set outside the UTF-8 family is refused too: under latin1 the byte 0xA0 is white space, and under gbk a valid UTF-8 character can hide the quote after it, so the guard would read the statement other than the server does. The refusal says to convert the history to utf8mb4. For the same reason a dev session whose client character set is outside the UTF-8 family is refused before any statement runs, whether a charset or collation parameter of the dev URL or the server’s own default sets it; charset=utf8mb4 in the dev URL gives the session utf8mb4 on such a server too. A migration can set NO_BACKSLASH_ESCAPES, ANSI_QUOTES or, on MariaDB, MSSQL, so a statement that holds a backslash, a double quote or a [ is read under each combination of them, and refused when any reading refuses it.

  • In a MySQL or MariaDB dev database the operator named, a write to another database is refused where the guard reads the other database’s name in the statement: a statement that creates, changes, drops or truncates one of its tables, DROP TABLES and RENAME TABLES included; an INSERT or REPLACE with or without INTO; every table the references of an UPDATE or a DELETE name, after an index hint, a MariaDB FOR SYSTEM_TIME clause, a STRAIGHT_JOIN or a MySQL alias named returning; table maintenance; an ALTER TABLE that renames a table into it, exchanges a partition with it, converts a partition into one of its tables or one of its tables into a partition, or points a MERGE table at it; a CREATE TABLE ... LIKE of one of its tables, which copies a MERGE table’s UNION; a view over one of its tables; and a call of one of its functions or an advance of one of its sequences. The guard reads these forms. It does not prove that no other spelling reaches another database.

  • MySQL and MariaDB statements that act on the whole server are refused in every realm and under trust: SHUTDOWN, RESTART, KILL, BINLOG, PURGE and the other replication statements, CLONE, LOCK INSTANCE, and MariaDB’s BACKUP STAGE.

  • MySQL and MariaDB statements that reach the account the run connects as are refused in every realm and under trust, because the run and its cleanup connect as that account until the command ends. The guard reads the session’s account and the roles it holds once, before the first statement. ALTER USER, RENAME USER, SET PASSWORD and SET DEFAULT ROLE are refused whatever account they name, the last two also as any item of a MariaDB SET list. DROP USER, DROP ROLE, every REVOKE, REVOKE PROXY included, and MariaDB’s CREATE OR REPLACE are refused when they name the account or a role it holds, and so is a GRANT that gives the account a password, a TLS requirement or a resource limit. CREATE USER, CREATE ROLE and GRANT are refused for an account that a new connection would match first: the same user, or the anonymous user, on a narrower host; on an address, when the session’s host is a name or a host name pattern such as %.example.com, since the guard cannot know which address that name stands for; or on a network written as 192.168.0.0/255.255.0.0 or 192.168.0.0/16, which MySQL tries before a host pattern or a name. The account is named by CURRENT_USER, CURRENT_USER(), USER(), CURRENT_ROLE or PUBLIC, or by its user and host in any quoting. A DROP USER or a REVOKE names one account, so 'app'@'%' there is not 'app'@'localhost'. User names compare exactly, after the trimming each server does. Host names compare as the server lowercases them: a dotted capital I (İ) is i and a Kelvin sign (K) is k on every server, and MariaDB 11.8 and 12.3 also read a long s (ſ) as s and a dotless i (ı) as i. MySQL trims spaces, tabs, line feeds, vertical tabs, form feeds and carriage returns at both ends of a user, host or role name, so 'app '@'% ' names app@%. MariaDB trims the spaces at the end of a name when it writes its grant tables, so DROP USER 'app '@'% ' removes the row of app@%, and the account is refused once the server reloads them. A statement is refused when either reading names the account. A write to a table of the mysql schema that holds accounts or privileges, such as mysql.user, mysql.db or MariaDB’s mysql.global_priv, is refused in the same way, and so is a view over one: the server reads the write as a change to its accounts once it reloads them, which MySQL does after any account statement that fails. On a server with lower_case_table_names set, the guard lowercases the name as the server does, so mysql.global_prİv is that table and mysql.uſer is not. The guard also reads the statements of a routine, trigger or event body, and refuses the CREATE or ALTER that writes one of these refusals into a body. A statement that names only other accounts gets the answer its realm gives it.

  • SQL Server EXEC/EXECUTE, SETUSER in every form, procedure/function/trigger creation or alteration, synonym/external-table creation, BULK INSERT, BACKUP, RESTORE, and server-level maintenance statements. T-SQL has no DDL to rename an object or to drop a default the server named, so Ptah writes an EXEC for each, and the guard accepts those in the shape the SQL Server renderer writes them and in no other. A rename is EXEC sp_rename N'[dbo].[users].[email]', N'mail', N'COLUMN';: each part of the name in brackets, every argument an N'...' literal, and the type COLUMN, INDEX, OBJECT or none. The others are the batches that drop or replace a column’s default. A rename is refused when its name reaches another database, when it names a temporary table, and when its type is another one, such as DATABASE. So is the procedure under another name, such as sys.sp_rename or otherdb..sp_rename, which runs in that database, and an argument built when the statement runs, such as a variable or a concatenation. A replacement is refused when the new default is more than one expression, and its ALTER TABLE ... ADD DEFAULT is judged as the same statement written on its own.

    T-SQL needs no semicolon between two statements, so the guard reads a batch into the statements the server runs from it, ending each where the server does, and judges every one: ALTER TABLE t ADD DEFAULT 0 FOR c DROP DATABASE other is two statements, and the DROP DATABASE is refused. So is the one in DELETE FROM t OUTPUT deleted.* DROP DATABASE other, where the asterisk ends the DELETE, and in SELECT @ DROP DATABASE other, where a bare @ is a variable. It also judges the statement an IF, ELSE or WHILE runs, the statements of a BEGIN ... END block and of TRY and CATCH, and the EXEC whose rows an INSERT stores. A procedure named with no EXEC, such as sp_executesql N'...' or xp_cmdshell 'dir' as the first statement of a batch, runs as EXEC of that name and is judged as one. An EXEC of one constant literal, such as the EXEC('CREATE SCHEMA [app]') the renderer writes under IF SCHEMA_ID('app') IS NULL, is judged as the batch the literal holds, eight levels deep at most. The server converts a literal without the N prefix to the database’s code page first, so such a literal that holds a character outside ASCII is judged as any other EXEC.

    Without trust, the guard refuses these statements wherever they stand, including in a block, after an IF and in a constant EXEC:

    • A name of another database that the dev session reaches. The guard reads the names a statement writes as identifiers: the target of a write, a table a query reads, the body of a view, function, procedure or trigger, NEXT VALUE FOR, CREATE STATISTICS and UPDATE STATISTICS, WRITETEXT, UPDATETEXT and READTEXT, OUTPUT ... INTO, REFERENCES, and the procedure an EXEC runs. Reads count: INSERT INTO dbo.t SELECT id FROM other.dbo.t is refused, and only trust lets a run read another database. In a name of three parts or more, the third part from the end can name a database, so other..t is the table t in other. A part before it names a server, or the database of the column in WRITETEXT other.dbo.t.c, and a name with such a part is always refused.

      The guard reads the dev database’s name from the dev session with DB_NAME(). A database part that is empty, or spelled exactly as the dev database, is local, so [dev].dbo.t and dev..t pass. For any other database part, the guard asks the dev session HAS_DBACCESS with that name, once per name in a run. An answer of 1 means the session reaches a database of that name, and the name is refused. An answer of 0 or NULL means it reaches none, so the server reads the name as a column, or a method called on one, and it passes. That covers SELECT p.geo.STAsText() FROM dbo.places AS p, t.doc.nodes('/a'), n.c.value('.', 'int'), a computed column area AS g.geo.STArea(), a check CHECK (g.geo.STIsValid() = 1) and SELECT dbo.t.c FROM dbo.t. The guard does not decide by the alias or by a following parenthesis, because both mislead: SELECT o.dbo.f() FROM dbo.x AS o runs the function f of the database o. HAS_DBACCESS answers for a database the login cannot list: under DENY VIEW ANY DATABASE, DB_ID returns NULL and sys.databases leaves out a database the login is mapped into, and HAS_DBACCESS still answers 1. master.sys.databases and tempdb.sys.objects are reads of another database, since every login reaches master and tempdb, and are refused. DEV.dbo.t is refused even where the collation ignores case: the session reaches DEV, and no fold the guard could apply matches every collation. A trusted run asks no question.

      The answers hold for the run’s own statements, in whatever order a command asks: migrations validate asks before each file and runs that file before it asks about the next. Without trust the guard refuses each statement that could make another database reachable: EXECUTE AS and SETUSER in every form, a bare SETUSER that goes back included, CREATE DATABASE, and EXEC. It refuses a user or a role created, altered or dropped, ALTER AUTHORIZATION and ALTER DATABASE always, and the cleanup refuses a dev database that holds a user other than the run’s own.

      Another session on the same server can change an answer after the guard asked about a name. It can create a database or map the login into one, release a database it holds in single-user mode, bring an OFFLINE database back online, or move one from RESTRICTED_USER to MULTI_USER. The guard keeps the answer it read, that the run does not reach the database, for the rest of the run, and accepts a later statement that names it.

      T-SQL lets @, # and $ follow the first character of a name, so the server reads x@.dbo.t as the table t in the database x@, and the guard reads it the same way. The guard does not know which words are reserved, so in FROM .dev.dbo.t, with the server part left out, it reads FROM as part of the name and refuses it. A name the statement holds in a string, as OBJECT_ID(N'other.dbo.t') does, is not read.

    • DBCC CHECKIDENT, CHECKTABLE and CHECKCONSTRAINTS on a table of another database. The server reads their first argument as a table name in any quoting: 'other.dbo.t', N'other.dbo.t', "other.dbo.t" and [other.dbo.t] all name the table t in other. The guard reads that name with the rule above, so DBCC CHECKIDENT ('dbo.items', RESEED, 1) after seed data passes. A first argument that is not a constant name, such as a variable or an expression, is refused. DBCC CHECKCONSTRAINTS with no table checks the dev database and passes. Every other DBCC acts on the server and is refused with trust or without it.

    • A function that reads a file on the server or a remote source: OPENROWSET, OPENDATASOURCE, OPENQUERY, sys.dm_os_enumerate_filesystem, sys.dm_os_file_exists, sys.fn_get_audit_file, sys.fn_get_audit_file_v2, sys.fn_xe_file_target_read_file, sys.fn_trace_gettable and sys.fn_dump_dblog, under any spelling of the name. The procedures that read the file system, such as xp_dirtree, xp_fileexist and xp_subdirs, are refused as every EXEC is.

    • ADD SIGNATURE and ADD COUNTER SIGNATURE.

    Text whose statement boundaries the guard cannot find is refused, with trust or without it. The refusal gives the offset and says how to rewrite the text: end each statement with a semicolon, and put the statements an IF, a WHILE or a block runs between BEGIN and END. The guard cannot find the boundaries at an END that closes no BEGIN, a number written against a word, as in 0x1GRANT, a character the server reads as whitespace and the guard’s lexer does not, such as U+200B, and a currency sign such as £, which the server reads as the start of a money constant (£1 is 1.0000). Nor can it inside a MERGE, which ends only at the semicolon the server requires: a statement word before that semicolon is refused, except the DELETE, INSERT, SET and UPDATE of its WHEN clauses.

  • ClickHouse remote, distributed, replicated, and unknown table engines, external dictionary sources, FREEZE/UNFREEZE, and SYSTEM statements but SYSTEM STOP MERGES and SYSTEM START MERGES of one table in the dev database, which a table rebuild runs. Tables and standalone materialized views must select an explicitly allowlisted engine.

  • SQLite ATTACH, DETACH, temporary views and triggers, any statement that names the temp schema, and non-restorable pragmas.

  • YDB, through its provider’s replay guard, writes whose target is an absolute path, climbs out of the dev realm with .., is named through a $ expression or names a cluster, PRAGMA TablePathPrefix, DEFINE ACTION, DO, EVALUATE, users, groups, GRANT, REVOKE, secrets, resource pools, backups, ALTER DATABASE, topics, external data sources and tables, async replication, transfers, and streaming queries.

Replay runs every migration of a directory on one session, as migrate apply runs the migrations of one run, so a PostgreSQL SET, RESET or set_config(name, value, false) carries into the migrations after it, and into the reads and the cleanup Ptah runs on that session. Such a setting is accepted where it changes nothing a later statement reaches, how Ptah reads that statement, or how Ptah reads the dev database back:

  • statement_timeout, lock_timeout, idle_in_transaction_session_timeout, idle_session_timeout and transaction_timeout, at any value;
  • client_min_messages, check_function_bodies, row_security, xmloption, default_tablespace and default_table_access_method, at any value;
  • search_path at the empty path '', or given back with DEFAULT or RESET;
  • standard_conforming_strings at on, and client_encoding, or SET NAMES, at UTF-8.

These are what pg_dump --schema-only sets around the objects it dumps. In set_config the name is written as a string, and so is the value of search_path, standard_conforming_strings or client_encoding.

A setting of any other parameter is accepted when it ends with its transaction:

  • SET LOCAL and SET CONSTRAINTS;
  • set_config(name, value, true), with the name written as a string and true written as the keyword.

A parameter that changes how the server writes a value out, such as DateStyle or TimeZone, belongs here: set for the session, it would change the text Ptah reads a column default back as.

SET LOCAL session_replication_role = replica belongs here too. It turns triggers off, foreign key checks among them, for the statements of its migration, so a migration can load rows in any order. It cannot outlive the migration: replay refuses a file that leaves a transaction open, so a transaction ends no later than its migration, on commit and on rollback alike, and outside a transaction PostgreSQL ignores SET LOCAL. Set for the session, it would carry into the migrations after it and into the cleanup, so it is refused there.

PostgreSQL CREATE TEMP TABLE and CREATE TEMPORARY TABLE are accepted on the replay’s pinned physical session. Later statements and migrations can use those tables, including through pg_temp. Ptah discards that session after success, failure, or cancellation. Explicit pg_temp_<number> targets remain protected; the replay cannot take ownership of another session’s temporary tables.

SQLite CREATE TEMP TABLE and CREATE TEMPORARY TABLE are accepted too. Later statements and migrations can use the table. A SQLite temporary table lives on the connection, and an in-memory dev database keeps its only connection, so Ptah drops the replay’s temporary objects after success, failure, or cancellation instead of discarding the session. A statement that names the temp schema, such as CREATE TABLE temp.t, remains refused.

A PostgreSQL-family COMMENT ON SCHEMA is accepted when the dev URL pins no schema. The reset that ends the replay returns each schema it keeps to the comment it held, and drops the others. A URL pinned to one schema is reset without reading that state, so there the comment is refused. A privilege on a schema is refused in every replay, because it depends on the server’s roles, and so is a comment on a protected namespace such as pg_catalog. The pinned community binary replays all of these, so ptah-compat is stricter here, deliberately.

A COMMENT ON EXTENSION is accepted, under the same condition, on an extension the dev database did not hold when the replay claimed it: the history created it, and the reset drops it with its comment. pg_dump writes such a comment after each extension it dumps, and Ptah renders one for a declared extension. A comment on an extension the dev database held is refused, since the reset keeps the extension and the comment would outlive the run. The name is compared as the server stores it, so an unquoted name is read in lower case.

Replay runs each migration the way migrations up does, in one transaction unless the file opts out with -- +ptah no_transaction or -- atlas:txmode none. Such a setting holds for the rest of its migration and is gone before the next. In a file that opts out, PostgreSQL ignores a SET LOCAL with a warning, on replay and on apply alike.

A PostgreSQL migration file that opens and closes its own transaction replays as written. Histories written for golang-migrate have files that begin with BEGIN and end with COMMIT. Replay reads such a file as a whole before it runs a statement and runs it without a transaction of its own. A file that fails is rolled back on the pinned session before the dev database is cleaned. The whole file is refused, with the statement named, when it:

  • leaves a transaction open, closes one it did not open, or opens one inside another;
  • uses ROLLBACK, ABORT, SAVEPOINT, RELEASE or ROLLBACK TO;
  • writes AND CHAIN, PREPARE TRANSACTION, COMMIT PREPARED, or a BEGIN mode other than an isolation level, access mode or DEFERRABLE (COMMIT AND NO CHAIN is a plain COMMIT);
  • asks for -- atlas:txmode file and opens its own transaction.

This holds for PostgreSQL only, and only where Ptah replays an existing migration directory. Elsewhere in a replay each of these statements is refused on its own. In a golang-migrate directory, and in one that --runner golang-migrate or migration.runner names, replay runs a file the way ptah-compat migrate apply runs it, which is how golang-migrate’s default mode runs it: a file that opens its own transaction runs in the transactions the file sent as one query runs in, and a file of one statement runs without one. The reading there also accepts what golang-migrate applies: a COMMIT outside a block, a BEGIN inside one, and SAVEPOINT, RELEASE and ROLLBACK TO inside one; see Transactions in a golang-migrate directory. LOCK TABLE is accepted for the same reason as SET LOCAL; a lock on a table in a protected namespace is refused.

A rollback that ptah migrations down --runner golang-migrate --shadow-db verifies runs each down file on the shadow database the same way, and --plan builds the target version there by running each up file the same way.

Some settings stay refused even for one transaction. A search_path that names a schema (and its alias SET SCHEMA) decides where an unqualified name lands, which would let a CREATE FUNCTION reach pg_catalog; under the empty path an unqualified CREATE has no schema to land in and fails. role and session_authorization change who the rest of the migration runs as. allow_system_table_mods is refused as well.

A standard_conforming_strings other than on, or a client_encoding other than UTF-8, makes the server read the bytes of a later statement by other rules than Ptah does: measured on PostgreSQL 18.6, either lets a statement Ptah reads as one SELECT run a CREATE ROLE. PostgreSQL 19 refuses standard_conforming_strings = off itself. DEFAULT and RESET are refused for both, since they give back the value the session started with. A dev session that starts with either setting, such as one whose URL sets client_encoding=GBK, is refused before the replay.

A name written without a schema is read the way the server reads it. A statement that refers to an existing object looks its name up in pg_catalog before any schema of the search path, so UPDATE pg_settings writes the catalog’s view, and sets the parameter of the row it changes, as SET would. Before the replay the guard reads the names the dev session’s catalog holds in its protected namespaces: relations, routines, types, operators and the other objects a statement can name. A statement that writes, alters, drops, locks, comments on or grants on one of them under its bare name is refused, as it is with the schema written, and the refusal says to qualify the name. On CockroachDB the same holds for the names in pg_extension.

A CREATE can hold such a reference too: the table after ON in CREATE INDEX, CREATE TRIGGER and CREATE POLICY, after TO in CREATE RULE and after FROM in CREATE STATISTICS. A table of your own that has a catalog’s name, such as app.pg_settings, is accepted when its schema is written.

A CREATE is judged by where it creates, not by what its name reaches. The server puts an object whose name has no schema in the first schema of the search path, so CREATE TYPE point makes public.point beside pg_catalog.point, and the guard accepts it, as it accepts CREATE OR REPLACE. A later statement that names the object without its schema is a reference again: DROP TYPE point reaches pg_catalog.point, so the guard refuses it, as the server does; write public.point.

The server skips a schema of the search path that does not exist, so under a path such as public, pg_catalog a DROP SCHEMA public makes the next CREATE land in pg_catalog. A dev session whose search path lists a protected namespace anywhere therefore has every CREATE without a schema refused, under trust too, and the refusal says to qualify the name. Ptah refuses a dev database whose search path starts with pg_catalog before the replay.

A direct write to a protected namespace is refused in every spelling the guard reads: with the schema written, bare, quoted, Unicode-escaped, or behind the dev database’s own name, as in ptah_dev.pg_catalog.pg_authid. A write the server carries through another object is refused where the guard can read the object:

  • A view whose query names a relation of a protected namespace, such as CREATE VIEW v AS SELECT * FROM pg_authid, is accepted, and so is a read through it. An INSERT, UPDATE, DELETE, MERGE or COPY that writes through it is refused, as is one through a view over that view.
  • A CREATE RULE whose action writes a protected namespace, or writes through such a view, is refused.
  • A CREATE TRIGGER whose function arguments name a relation of a protected namespace, or call a function the guard refuses as a call, is refused. The check_foreign_key function of the refint extension runs its arguments as SQL, so check_foreign_key(1, 'cascade', 'id', 'pg_catalog.pg_description', 'objoid') deletes catalog rows, and an argument that calls set_config changes the replay session. A text search configuration such as 'pg_catalog.english' names no relation and is accepted.
  • A table that inherits from a relation of a protected namespace or is a partition of one is refused: CREATE TABLE ... INHERITS, PARTITION OF, ALTER TABLE ... INHERIT and ATTACH PARTITION.
  • An operator, an aggregate, a type, an operator class or a conversion that names a function the guard refuses as a call is refused. The guard reads every value of a definition list, whatever the option and whether the value is quoted. A refused function is a cluster control function such as pg_terminate_backend or set_config, a replication function, a large object function, pg_import_system_collations, a session advisory lock, and, unless the run trusts its SQL, a server file function or a dblink function. set_config is refused there whatever it would set, because the server passes it arguments the statement does not spell out.

The guard judges each write when it runs, over what the replay has done to the dev database up to that statement. It keeps one graph of relations: the views, the rules and the triggers the replay creates, replaces, renames, moves or drops, and the ones the dev database already holds, such as an extension’s, which it reads before the replay. A write reaches what a view’s query, a rule’s action and a trigger’s arguments name, and the tables a cascading foreign key, a partition or an inherited table carries it to. So a write through a view over a view that a later statement replaces with one over pg_authid is refused, and so is a delete whose trigger names a view created after the trigger. A trigger’s argument is looked up when the write runs, as the trigger does.

The guard reads a view as one the server writes through on its own when its query is one SELECT, without DISTINCT or a window, of one relation after FROM, with only a WHERE or an ORDER BY after it. Such a view writes that relation alone, so a filter that reads a catalog does not make the write a catalog write. A view of any other shape counts every relation its query names. A dropped view reaches nothing, so a table later created under its name is written as usual. The guard matches a relation by its schema and name, and reads a name without a schema through the dev session’s search path, as the server does: a table of public is written as usual beside a view of the same name in a schema the path does not reach. Where the guard cannot tell which relation a name without a schema means, it refuses the write, and the refusal says to qualify the name.

A function that reads, lists or changes the files of the server’s host is refused unless the run trusts its SQL: pg_read_file, pg_read_binary_file, pg_stat_file, the pg_ls_*dir functions, and adminpack’s pg_file_write, pg_file_rename, pg_file_unlink and pg_file_sync. So is a COPY to or from a program or a file of the host, such as COPY t FROM '/etc/hostname'. lo_import and lo_export read and write host files too, and stay refused under trust with the rest of the large object functions. pg_import_system_collations is refused in every scope, because the schema it adds collations to is an argument the guard cannot read.

On CockroachDB a statement can name a table of another database of the same server, as other.public.t or as other.t. Such a name is refused unless the run trusts its SQL. A name of two parts counts as another database’s when its first part is neither the dev database nor one of its schemas. PostgreSQL and YugabyteDB refuse a reference to another database themselves.

A call of such a function in a column default, a generated column, a CHECK constraint, a policy or a rule action is refused as any call is. CockroachDB has no rules, operators or aggregates, and its server refuses a write through a view; the guard refuses a write through a CockroachDB view that reaches a protected namespace all the same.

A Unicode-escaped identifier, such as U&"pg\005fcatalog", is decoded before the guard reads the statement, so it counts as the name it spells. One whose escapes the guard cannot decode is refused.

The rejection happens while Ptah validates the whole migration, before its first statement executes. Realm-local removals Ptah can classify without reading a routine body, such as DROP FUNCTION, DROP FOREIGN TABLE, DROP SYNONYM and DROP EXTERNAL TABLE, stay allowed.

A docker:// or docker+<driver>:// dev URL starts a server for one command and removes it afterwards, so the server holds only what the run put there. On such a server, replay also runs the statements it refuses elsewhere only because their effect reaches past the dev database:

  • PostgreSQL-family DO, CALL, routine creation and alteration, CREATE and DROP of a role, user, group or database, ALTER ROLE without SET or RESET, role membership, privileges on a role, database, schema, language or parameter, CockroachDB’s ALTER DEFAULT PRIVILEGES FOR ALL ROLES without IN SCHEMA, DROP OWNED, REASSIGN OWNED, COMMENT ON a role, a database, or an extension or schema of the dev database, and ALTER EXTENSION ... UPDATE [TO ...] whose name and version Ptah reads. A server declared disposable lifts all of these except a comment on an extension or a schema the dev database held when the run claimed it and the extension update, because that server outlives the run and its reset keeps them. Replay does not read a DO block or a routine body; outside one, any other ALTER EXTENSION stays refused. A rehearsal allows a schema’s own comment and privileges where its reset returns them.
  • MySQL and MariaDB routines, triggers, CALL, GRANT, REVOKE, CREATE and DROP of a user, role or database, writes to another database, the key cache statements CACHE INDEX and LOAD INDEX INTO CACHE, and SET RESOURCE GROUP. A statement that reaches the account the run connects as stays refused, and so does a write to an account table of the mysql schema, in a body too. CREATE TABLE and ALTER TABLE with a FEDERATED, CONNECT or SPIDER engine, or a CONNECTION option, stay refused: their writes can reach an account table through the table they name. The guard reads a body as the statement that defines it writes it. SQL that a body builds and runs, with PREPARE and EXECUTE or MariaDB’s EXECUTE IMMEDIATE, is not read, so such a body can still reach the account here.
  • YDB writes anywhere in the server, PRAGMA TablePathPrefix, actions, users, groups, permissions, secrets, resource pools, backups and topics, on docker://ydb/<tag>, which the YDB provider starts. YDB gets no dev realm there: the database is the dev database.

So a migration directory that creates its role in a DO block or defines a function replays on docker://postgres/18/dev.

The rest of the list above still fails closed on a provisioned server. Those statements change the replay session or the sessions the rest of the command opens (SET search_path, ALTER ROLE ... SET, any ALTER DATABASE, transaction control), change how the command’s later SQL runs (ALTER SYSTEM, event triggers, casts, languages), reach past the container (foreign servers, subscriptions, dblink, an external COPY, a server file function), or mutate a protected namespace such as pg_catalog. A MySQL or MariaDB event stays refused because the scheduler runs it during the rest of the command.

A YDB external data source or table, async replication, a transfer and a streaming query reach outside the container and stay refused. local-ydb takes every connection without a credential, so the YDB provider refuses docker://ydb when the container runtime is on another machine, where its port would be published on every interface of that host.

A docker://<engine>/... or docker+<engine>://... URL whose engine belongs to a selected executable provider goes to that provider instead. The provider picks the image, starts the server and removes it when the command ends. Ptah records the address it gets back as a server the run owns, as for a server it starts itself. A provider that will not provision answers with a refusal that says whether it does not serve the request or its runtime is unavailable, and the command stops with that reason.

The decision reads what Ptah recorded when it started the server, not the URL’s spelling. A named server keeps the whole list, since it may hold databases and roles that are not the run’s. Its refusal names the two ways to this realm, a docker URL and the declaration below, and trust in the SQL, which lifts the refusal without making the server the run’s.

A server Ptah did not start can be as disposable: a CI service container the job throws away, or a container the operator runs. PTAH_DEV_SERVER_DISPOSABLE=1 declares that the server --dev-url names is the run’s own. Replay then runs the statements listed above on it, as on a server Ptah provisions, except a comment on an extension or a schema the dev database held when the run claimed it and an extension update, and refuses the same rest.

Terminal window
PTAH_DEV_SERVER_DISPOSABLE=1 ptah migrations validate --dir migrations --dev-url "$DEV_URL"

The declaration covers the whole server, its default database (postgres) included. After a replay Ptah cleans the dev database. On PostgreSQL, CockroachDB and YugabyteDB it also drops every role the server did not hold when the command claimed the dev database. On a server nothing else uses, those roles are the run’s, so a later command that replays the same directory creates them again. A role the server already held stays, whoever created it. A YDB dev URL declared this way gets no dev realm: its database is the dev database, and it has to be empty. A database a replay creates, and a role or a user on any other engine, stays on the server until the container is removed. A later command that replays the same directory on the same server meets it, so a migration that creates one without checking for it first fails the second time. Declare only a server that nothing else uses.

The declaration names the server of a dev database and never a shadow database’s. The commands that replay a history only to verify it do not read it: ptah migrations down, migrations up, migrations drift, migrations baseline and migrations checkpoint, and ptah-compat migrate down, migrate apply, migrate drift and migrate checkpoint. ptah migrations generate reads it for its --dev-url and not for its --shadow-db.

Every command that replays a migration directory or rehearses a plan on a dev database reads the variable, on both binaries, and refuses a non-boolean value before any work, whether or not it replays. Strict Atlas compatibility keeps the variable, because the pinned community binary runs these statements on any dev database.

The refusals above protect a shared server from SQL the run cannot confine to its dev database. When you wrote that SQL or reviewed it, you can tell Ptah to run it on a dev server that other work shares: pass --trust-replay-sql to a native command, or set PTAH_TRUST_REPLAY_SQL=1 for either binary. The flag takes precedence over the variable. With neither, the guard refuses as described above, and each refusal that trust would lift says so.

Terminal window
ptah migrations validate --dir migrations --dev-url "$DEV_URL" --trust-replay-sql
PTAH_TRUST_REPLAY_SQL=1 ptah-compat migrate validate --dir file://migrations --dev-url "$DEV_URL"

Trust does not confine anything. The SQL runs with the privileges of the dev connection, and what it does to the rest of the server is yours to accept. Ptah still cleans only the dev database it claimed, and never drops a role, a database or another server-level object the SQL created. A role a DO block creates stays on the server after the run. The next run that replays the same directory meets it: a DO block that checks for the role first passes, and a bare CREATE ROLE fails with the server’s own error, such as role "app_admin" already exists (SQLSTATE 42710). Give the dev connection only the privileges you are willing to hand to that SQL, and write role creation so that it can run twice.

A schema apply whose target is on the dev server meets the same thing in one run. The rehearsal creates the roles the plan declares, so the apply that follows fails on CREATE ROLE with that error. The next run finds the role on the server and plans no CREATE ROLE. Keep the dev database on a server of its own, or create the role first.

Trust is not ownership. It does not declare the server disposable and does not imply PTAH_DEV_SERVER_DISPOSABLE. On a server Ptah provisions or one declared disposable, the cleanup drops the roles the run created, with trust or without it.

Trust lifts every refusal whose only reason is that the statement’s effect reaches past the dev database, and not a list of spellings. A DO block can EXECUTE a CREATE ROLE, so refusing a bare CREATE ROLE while running the DO block would protect nothing. On a server the run does not own, trust accepts:

  • on PostgreSQL, CockroachDB and YugabyteDB, the statements a server Ptah provisions accepts except a comment on an extension or a schema the dev database held when the run claimed it and an extension update, and also an external COPY, a server file function, dblink, IMPORT FOREIGN SCHEMA and, on CockroachDB, a name of another database;
  • on MySQL and MariaDB, routines, triggers, CALL, prepared statements, MariaDB compound statements, users, roles, GRANT, REVOKE, loadable functions, other databases and writes to them, the key cache and resource group statements, LOAD DATA, LOAD XML, IMPORT TABLE, SELECT ... INTO OUTFILE or DUMPFILE, and a client character set outside the UTF-8 family, set by the history or by the dev session, but no statement that reaches the account the run connects as and no write to an account table of the mysql schema. CREATE TABLE and ALTER TABLE with a FEDERATED, CONNECT or SPIDER engine, or a CONNECTION option, stay refused in every realm and under trust. The guard cannot prove that their destination is not an account table. The same rule applies to table options in a stored or anonymous body and in a partition definition. INSTALL SONAME and CREATE SERVER stay refused too;
  • on SQL Server, EXEC, SETUSER, functions, procedures and DML triggers, databases, logins, credentials, synonyms, a name of another database the dev session reaches, reads included, DBCC CHECKIDENT, CHECKTABLE and CHECKCONSTRAINTS on a table of another database or one not named as a constant, BACKUP, RESTORE, BULK INSERT, the functions that read a file on the server or a remote source, and ADD SIGNATURE and ADD COUNTER SIGNATURE;
  • on ClickHouse, SQL functions, databases, users, roles, row policies, named collections, GRANT, REVOKE, ON CLUSTER, writes to another database or through a table function, any table engine, dictionary sources, BACKUP, FREEZE, UNFREEZE and INTO OUTFILE;
  • on SQLite, VACUUM INTO.

A refusal that protects the run itself stays under trust. That covers a statement that changes the replay session, the identity it runs as or its transaction; a MySQL or MariaDB statement that reaches the account the run connects as; a write to a system catalog such as pg_catalog, or to a MySQL account table such as mysql.user; server configuration such as ALTER SYSTEM, SET GLOBAL or RECONFIGURE; an object the dev database cleanup cannot remove, such as an event trigger, a YugabyteDB publication or a SQL Server ledger table; a MySQL event or a SQL Server DDL trigger, which would run on their own during the rest of the command; a MySQL statement that acts on the whole server, such as SHUTDOWN, KILL or a replication change; and a MySQL executable comment, which hides SQL from the guard. SQLite keeps ATTACH, load_extension and a pragma that changes state refused.

On MySQL and MariaDB these refusals hold for a statement as the history writes it. The guard does not read the SQL that a statement builds and runs, and trust accepts the statements that do: a prepared statement, a routine that CALL runs, and on MariaDB EXECUTE IMMEDIATE and a compound statement. Each of them can run a statement that trust keeps refused. Measured on MySQL 8.4.13 and MariaDB 11.8.9 under trust, PREPARE s FROM 'SET GLOBAL max_connect_errors = 101' followed by EXECUTE s changes the server setting, and so does a procedure that runs the same SET GLOBAL, where the statement written on its own is refused. On MariaDB a prepared CREATE EVENT creates an event. Trust declares that you accept what the history runs. The refusals that stay catch a statement the history writes on its own, not one it builds to get past them.

On MySQL and MariaDB, a refusal that stays under trust also holds only for a statement the guard reads as the server does. The guard reads each statement as UTF-8. Under trust a prepared statement can change the client character set as SET NAMES can, so trust lifts that refusal and the refusal of a non-UTF-8 dev session too. After such a change the server reads the bytes of the statements that follow by other rules, and an event or an executable comment the guard does not see can run. Keep a history that trust replays in utf8mb4 for these refusals to hold.

On PostgreSQL, CockroachDB and YugabyteDB too, these refusals hold for a statement as the history writes it. The guard does not read a DO block or the body of a routine, and trust accepts both, so under trust a DO block, or an operator, a trigger or a default that calls a routine the history created, can run a statement that trust keeps refused. Measured on PostgreSQL 18.7 under trust, a DO block that updates pg_catalog.pg_authid changes the role, where the same UPDATE written on its own is refused. This is the design: trust declares that you accept what the history runs.

On PostgreSQL, CockroachDB and YugabyteDB the guard reads each statement as UTF-8 with standard-conforming strings, and the refusal of a client_encoding or standard_conforming_strings setting that changes that reading stays under trust. A DO block that trust runs can change either, so trust lifts the refusal of a dev session that starts with one. Keep a history that trust replays in UTF-8, with standard_conforming_strings on, for the refusals that stay to hold.

An executable provider, such as the YDB provider, guards its own dev databases and decides in its dialect what trust lifts. A provider that declares database.dev-replay-trust (provider contract 25.43) receives the declaration with each replay guard request and with each dev session Ptah opens for the run, so a statement its guard accepts under trust also runs. When you declare trust and the provider does not declare the feature, Ptah stops before the replay and names the provider: install a provider release that supports it, or run without the declaration. Without the declaration, every provider replays under its own default confinement.

The YDB provider lifts a write outside its dev realm, actions, users, groups, permissions, backups and statements that reach past the server. It keeps a statement that changes the session, such as PRAGMA TablePathPrefix or USE, refused, inside the body of an action or a DO block too.

Trust covers the SQL a run executes on its dev database: a migration directory it replays there or on a shadow database, a desired schema file it loads there, and the baseline and plan a rehearsal writes. An apply to the target never needs it, and a command that parses or compares its input without executing it runs no input SQL. These commands read the setting, and each refuses a value that is not a boolean before any work:

  • ptah, with --trust-replay-sql: migrations validate, migrations lint, migrations generate, migrations down, migrations baseline, migrations up, migrations drift, migrations checkpoint, schema inspect, schema diff and schema apply.
  • ptah-compat, through the variable: migrate validate, migrate diff, migrate lint, migrate down, migrate apply, migrate drift, migrate checkpoint, schema inspect, schema diff, schema apply, schema plan lint and schema plan validate.

migrations up and migrations down replay SQL only on a shadow database, so each refuses a typed --trust-replay-sql that its run cannot use: up without the drift check, and down without a shadow database. The variable is not refused there, so a CI job can set it for every command it runs. A refusal on a shadow database names the variable alone, and a server-level refusal there names a docker URL as the remedy. A Go program that calls migration/shadow reads no variable and passes trust in the options, as shadow.ReplayTrust.

Strict Atlas compatibility keeps the variable, because the pinned community binary runs these statements on any dev database.

There is no ptah.yaml key for trust, and a ptah.yaml that sets trust_replay_sql is refused as an unknown key. A command discovers ptah.yaml in its working directory, so the file belongs to the repository whose SQL the run replays. If that file could trust its own SQL, a pull request from a fork that runs migrations lint or schema diff against a dev URL from the CI secrets could lift the guard for itself. Trust comes from whoever runs the command, on the command line or in the job’s environment. The permission to run a program a project file names follows the same rule; see Programs a project file names.

schema inspect of a schema file and schema diff with a file on either side load that file on the dev database, from the schema Ptah reads out of it. Tables, routines, policies and views land in the dev database and need no declaration on any server. A role the file declares, as CREATE ROLE or as a role-bootstrap block, belongs to the server. When the dev server does not hold that role, the load creates it only where something accounts for it:

  • on a server Ptah provisions or one declared disposable, the role is created and the cleanup drops it with the run;
  • under trust, the role is created and stays on the server;
  • on any other server, the load refuses before it writes the dev database. The refusal names each role and the three remedies.

A role the server already holds is not created again, and the result describes it as the server has it. migrate diff, migrations generate and schema plan do not load the desired file on the dev database: they plan the role into their output and create nothing.

Before schema apply rehearses its plan, it recreates the target’s current schema in the dev database. Every statement of that baseline is checked against the same rules as a replay before the first one runs. A routine or trigger body can write outside the dev database when it runs, and a role, a user or a privilege the cleanup does not remove outlives it, so a target that holds one is rehearsed only on a server the run owns, one Ptah provisions from a docker URL or one declared with PTAH_DEV_SERVER_DISPOSABLE=1, or when the run trusts the SQL. The refusal names the baseline statement and these remedies.

A selection narrows the comparison, not what the target holds. With --include, --exclude or --schemas, or a URL bound to one schema with search_path, the compared state can leave out an object that a statement of the baseline or of the plan names: a policy of an included table that calls auth.uid() with auth left out, or a planned foreign key to a table in an excluded schema. The target applies such a statement, so the baseline also recreates each object the statements name, read whole from the target, and then what those objects name in turn: tables with their keys and indexes, views, routines, sequences, types, domains and extensions, and their schemas. An object nothing names stays out, because a selection often leaves out what the dev server cannot build, such as an extension it does not have.

To find those objects the rehearsal reads the target again, and only the schemas the statements name, beside the schema the URL pins. A word a statement uses as a qualifier, folded to lower case, is a candidate, and a schema nothing names is not read, so a schema whose objects the reader cannot inspect does not stop the rehearsal. How a word becomes a schema depends on the engine:

  • An engine whose connection selects schemas along a search path, as PostgreSQL, CockroachDB and YugabyteDB do, matches it against the schemas the target holds.
  • An executable provider whose engine carries namespaces (schema.common-namespaces) receives the words as the schema selectors of its filtered inspection. The provider decides which schema a word selects, and a word that selects none, such as a table alias, reads nothing. A quoted schema name that keeps upper-case letters, such as "App", is sent as app, so a provider that compares schema names exactly does not find it.
  • Every other engine, and a provider whose engine carries no namespaces, reads what its URL reaches once. For such a provider that is its whole database: when the read fails, the rehearsal fails with a message that names the missing feature.

The comparison itself is not widened. A role belongs to the server rather than to one database, so a plan has no CREATE ROLE for a role the target already holds, and a dev server of its own may still lack one a statement names, such as the role of a policy’s TO app_admin. On a server the run owns, the baseline creates each such role that the dev server did not hold when the run claimed it, with the attributes the target gives it and no password, and the cleanup drops it with the run. A role is named the way an object is, by its bare name in the code below, and the rule errs toward naming: a column called like the role counts too. On any other server no role is created, so the dev server has to hold the roles the statements name.

The objects recreated this way are checked against the same rules as the rest of the baseline, so a routine such as auth.uid() is recreated only on a server Ptah provisions from a docker URL or one declared with PTAH_DEV_SERVER_DISPOSABLE=1, or when the run trusts the SQL, and refused by name otherwise.

A name counts as named where it appears in the code of a statement, or in what PostgreSQL resolves in a routine body before the plan goes on. That is the whole of an SQL body, and the declarations of a PL/pgSQL body, such as r auth.accounts%ROWTYPE or v extensions.vector(3), without their defaults: PostgreSQL resolves a call in a PL/pgSQL body, and a default, only when the block runs. A DO block runs at once, so the whole of it counts, and one that names no language is PL/pgSQL. The rule is the same for a routine the target holds and for a planned CREATE FUNCTION, CREATE PROCEDURE or DO block.

A name qualified by its schema counts wherever it stands. A bare name reached along the dev session’s search_path counts only where it can name the object: a function where a call names it, a table, view or sequence where SQL names a relation, such as after FROM, JOIN or REFERENCES, and a type anywhere. So a planned column title does not recreate a function title().

On PostgreSQL, CockroachDB and YugabyteDB, a string counts where the server reads it as the name of a relation as it reads the statement: a constant cast to regclass, as in 'app.ids'::regclass or CAST('app.ids' AS regclass), and the first argument of nextval, currval or setval written as a constant, as in nextval('app.ids'). So a column default nextval('app.ids') with app excluded recreates the sequence app.ids and its schema, whether the plan adds the default or the target already holds it. The text is read as the server reads it: a dot outside double quotes separates the schema from the name, an unquoted part is folded to lower case, and a bare name is a table, view or sequence found along the dev session’s search_path. The sequence stays outside the comparison: the plan neither creates nor drops it.

Any other name inside a string literal names nothing, so DEFAULT 'app.ids' and a string passed to another function recreate nothing. Neither does a name built from other strings, such as nextval('app.' || 'ids'), nor one passed as text, such as nextval('app.ids'::text), which PostgreSQL looks up only when the expression runs. CockroachDB looks up the text form as it reads the statement, so there that default fails the rehearsal with relation "app.ids" does not exist. A sequence the target does not hold either fails it the same way on every engine. When a statement of the baseline or of the plan fails after objects were recreated this way, the error lists them.

A dev URL that pins one schema with search_path leaves the other schemas the dev database held at the claim as it finds them, with what they hold, so an object written into one of them would outlive the run and fail the next one. On PostgreSQL, CockroachDB and YugabyteDB, and on an engine whose provider session lists its schemas, the claim records those schemas. There the rehearsal refuses a baseline that would write an object into one of them before it writes anything, names the schema and the objects, and writes nothing beyond the reset, whether or not the server is disposable. Point --dev-url at a database that does not hold the schema: a schema the baseline creates is the run’s, and its cleanup drops it.

Comments follow a narrower rule. A comment on a table or a column is written. The comment an extension’s control file gives is not written, because CREATE EXTENSION sets it; Ptah reads that comment from the dev server. A comment the target gave an extension itself is written on a server Ptah provisions from a docker URL. Elsewhere it is written only for an extension the dev database did not hold when the run claimed it, on a dev URL that pins no schema, since the cleanup drops that extension with its comment. A comment on an extension the claim found is refused, because the cleanup keeps the extension and does not restore its comment.

A schema’s own comment and the privileges on it are written on any server, because they end with the run. A target often holds them, on public or on a schema of its own, and a dev database whose public was dropped and created again has neither. On PostgreSQL, CockroachDB and YugabyteDB, the claim records the owner, access list and comment of the schemas a reset keeps, and every reset returns those schemas to them and drops the others. A dev URL that pins one schema with search_path is the exception: its cleanup leaves that schema as it finds it, so they are refused there, with the remedies above. Its cleanup does drop a schema beside the pinned one that the claim did not find, with everything in it, so a schema the baseline recreated does not reach the next run. A privilege for a role the dev server does not hold fails on that server, as it does on a table.

The plan is held to the same rules, before the first statement of the baseline or the plan runs. The plan comes from the desired schema, so a role, a routine or trigger body, or a comment the cleanup keeps is rehearsed only on a server Ptah provisions from a docker URL or one declared with PTAH_DEV_SERVER_DISPOSABLE=1, and a role or a body also under trust. On any other server, without trust, the rehearsal refuses, names the plan statement and the remedies, and leaves the target and the dev server as they were. Without this check, a role the rehearsal created would outlive the cleanup on the dev server, and the real apply would fail on it when the target is on the same server. Under trust that is what happens; see SQL you trust.

In a YDB dev realm, the baseline leaves out the permissions the target holds on its database root. The realm’s root would stand in for the target’s, but a reset in the middle of a run keeps the realm’s root and its permissions, so a grant written there would reach the next target rehearsed in the realm.