Expand description
AST-based rewriting of database and schema names in mod statements.
When a profile suffix is active, database names in mod files must be
suffixed (e.g., app -> app_dev). When a staging suffix is active,
schema names must be suffixed (e.g., public -> public_staging).
This module provides rewrite_database_names and rewrite_schema_names,
which apply these transformations at the AST level using the auto-generated
VisitMut traversal. This is safer than raw text substitution because it
only touches actual identifier nodes, not string literals or comments.
ยงSupported Statement Types
The visitor handles all statement types permitted in mod files:
COMMENT ON DATABASE/SCHEMAGRANT ... ON DATABASE/SCHEMAALTER DEFAULT PRIVILEGES IN DATABASE/SCHEMA
The auto-generated traversal uses two separate hooks for database/schema names depending on AST position:
visit_database_name_mut/visit_schema_name_mutโ associated type hooks used by COMMENT ON DATABASE/SCHEMA and ALTER DEFAULT PRIVILEGESvisit_unresolved_database_name_mut/visit_unresolved_schema_name_mutโ concrete struct hooks used by GRANT ON DATABASE/SCHEMA (viaUnresolvedObjectName::Database/Schema)
Both hooks receive &mut UnresolvedDatabaseName / &mut UnresolvedSchemaName,
so the rewriting logic is shared via a helper function. Both hooks must be
overridden to cover all mod statement types.
Structsยง
- Database
Name ๐Rewriter - Visitor that rewrites database name identifiers by appending a suffix.
- Schema
Name ๐Rewriter - Visitor that rewrites schema name identifiers by appending a suffix.
Functionsยง
- rewrite_
database_ ๐name - Append
suffixto the database name if it matchesdatabase_name. - rewrite_
database_ ๐names - Rewrite database names in parsed mod statements by appending a suffix.
- rewrite_
schema_ ๐name - Append
suffixto the schema part (last ident) if it matchesschema_name. - rewrite_
schema_ ๐names - Rewrite schema names in parsed mod statements by appending a suffix.