Skip to content

Latest commit

 

History

History
691 lines (560 loc) · 39.3 KB

namespaces.md

File metadata and controls

691 lines (560 loc) · 39.3 KB

Schema Namespaces

Table of Contents

SchemaBot uses namespaces to organize declarative schema files. A namespace maps to the database-specific grouping concept:

Database Namespace maps to How to list
MySQL Schema name SHOW DATABASES
Vitess Keyspace SHOW KEYSPACES
PostgreSQL Schema \dn

Schema Directory Structure

The schema directory is the source of truth. Each subdirectory is a namespace containing SQL files and optional configuration.

schemabot onboard -d <database> -e <environment> -s <schema-dir> generates any of the layouts below from a live pull of the source environment, so you rarely author one by hand — the examples here are what it produces and what you maintain afterwards.

MySQL — Single schema name

The simplest case. One database, one schema name:

myapp/schema/
├── schemabot.yaml
└── testapp/
    ├── users.sql
    ├── orders.sql
    └── products.sql
# schemabot.yaml
database: testapp
type: mysql

MySQL — Multiple schema names on the same database

A single MySQL database server can have multiple schema names (SHOW DATABASES). Each subdirectory is a namespace, all managed under one schemabot.yaml:

myapp/schema/
├── schemabot.yaml
├── app_primary/
│   ├── users.sql
│   └── sessions.sql
└── app_analytics/
    ├── events.sql
    └── metrics.sql
# schemabot.yaml
database: myapp
type: mysql

SchemaBot plans each namespace independently — app_primary and app_analytics each produce their own SchemaChange with separate table changes.

Each namespace is diffed against its own MySQL database, so a table whose schema file is deleted is dropped in that namespace's database and shows up under that namespace only. This needs a namespace-free target DSN; see MySQL target DSN requirements for what a DSN that names a database cannot do.

MySQL — Different databases entirely

When an app talks to separate database servers, each gets its own schema directory with its own schemabot.yaml:

myapp/
├── primary-schema/
│   ├── schemabot.yaml          # database: app_primary, type: mysql
│   └── app_primary/
│       ├── users.sql
│       └── sessions.sql
└── analytics-schema/
    ├── schemabot.yaml          # database: app_analytics, type: mysql
    └── app_analytics/
        ├── events.sql
        └── metrics.sql

These are completely independent SchemaBot configurations — different targets, different credentials, different plans.

Vitess — Multiple keyspaces

Vitess databases have multiple keyspaces under a single schemabot.yaml. Each keyspace subdirectory is a namespace:

myapp/schema/
├── schemabot.yaml
├── commerce/
│   ├── orders_seq.sql
│   ├── products_seq.sql
│   └── vschema.json
└── commerce_sharded/
    ├── orders.sql
    ├── products.sql
    └── vschema.json
# schemabot.yaml
database: commerce
type: vitess

SchemaBot plans all keyspaces together — a single plan can contain changes across commerce and commerce_sharded. This is necessary because DDL and VSchema changes across keyspaces may need to be deployed atomically (e.g., moving a table between keyspaces).

Vitess — VSchema changes

vschema.json controls Vitess routing (which tables live in which keyspace, sharding strategy, vindexes, etc.). When a vschema.json file changes:

  1. Plan detects the diff and includes it as a FileChange for display
  2. Apply sends the full vschema.json content to the branch (not the diff)
  3. The PlanetScale engine applies both DDL and VSchema atomically

A plan can have DDL-only changes, VSchema-only changes, or both.

A VSchema change that removes a vindex, a table routing entry, or a table's column-vindex association, or that changes a vindex definition, the keyspace's sharded flag, or a table's type, primary vindex, or auto_increment, is an unsafe change and requires the same --allow-unsafe acknowledgment as destructive DDL — see lint-and-safety-levels.md.

Removing a namespace

Deleting every schema file in a namespace, or moving them all out of it, does not remove the namespace from the plan while another namespace still declares files under the schema root. Every table the emptied namespace still holds is planned as a DROP TABLE change: an unsafe change that needs the explicit drop approval before it can run. On PostgreSQL some of these drops are blocked instead, such as a table that a view reads; see Tables with no schema file. Only the files the pull request itself removes count — a deletion it inherited from history its base branch has not caught up with is not one it proposes.

A pull request that removes the last schema files under the root — the only namespace, or every one of them — cannot be planned at all: an empty root is indistinguishable from one that moved, so discovery fails closed and the plan comment says the removal has not taken effect and what completes it.

To retire a namespace, drop its tables first, through a reviewed schema change that keeps the files in place, and delete the directory once they are gone. The divergence is visible exactly once — in the pull request whose diff contains the deletion. After it merges, the default branch carries no record that the namespace existed, so no later plan surfaces those tables.

To keep a namespace declared while it holds no tables, leave one .sql file in its directory whose whole content is the empty-namespace declaration:

-- This namespace is empty. Add CREATE TABLE declarations here.

The file creates the namespace and contributes no statement, so the namespace reconciles to no tables on every plan. Deleting that file is a removal like any other: the pull request that deletes it plans every table the namespace holds as a drop.

Where to Put the Schema Directory

SchemaBot is location-agnostic: config discovery finds schemabot.yaml anywhere in the repository — the directory containing it is the schema directory. Namespaces come from directory names in either layout: with the config at the schema root, each subdirectory is a namespace (as below); with the config inside a single namespace directory next to its .sql files (flat layout), that directory's basename is the namespace. Nothing in SchemaBot forces a particular path, so placement is a repository-semantics choice. For greenfield repositories, a repository-root schema/ directory is the recommended layout:

myapp/
├── schema/
│   ├── schemabot.yaml
│   └── myapp/
│       ├── users.sql
│       └── orders.sql
├── service-a/
└── service-b/
  • Prefer to keep schema files out of build-tool resource directories (Maven/Gradle src/main/resources, embedded asset dirs). Those paths mean "packaged into the application artifact" — but the application never reads these files. Only SchemaBot does, from GitHub, at PR time. Placing them there ships dead weight in every build and implies runtime semantics the files don't have.
  • Keep visible distance from imperative tools during coexistence. If the repository still carries Flyway or Liquibase versioned change scripts while SchemaBot takes over, keep the two mechanisms in visibly different places. Those scripts live in resources/ because the app executes them from the classpath at startup; SchemaBot is the opposite model — declarative desired state, applied out-of-band. Side by side in one resources tree, "which file do I edit?" becomes a coin flip.
  • The schema is a repository-level concern. The database usually spans application modules (domain tables, framework tables such as Spring Batch's BATCH_*, history tables), so its desired state belongs at the top level, not nested inside one module.
  • Short stable paths keep operations simple. A server-side allowed_dirs: [schema] allowlist (matched against the directory containing schemabot.yaml and its descendants), CODEOWNERS scoping, and PR review path filters all stay trivial with a root path, and the directory-name-is-the-namespace contract stays visible at a glance.

A module-root directory outside src/ (e.g. my-data-module/schema/) also works and avoids the packaging problem — reasonable when one module clearly owns the database, but most schemas span modules.

For existing (brownfield) repositories, treat the root schema/ layout as a nice-to-have, not a requirement. SchemaBot behaves identically wherever the config lives, so adopting it does not require moving files that already have an established home. Relocating is worth it only if the points above start to bite — packaging dead weight, confusion next to imperative change scripts, or allowlist/CODEOWNERS churn — and can be done later as a follow-up.

Environment Substitution in Namespace Names

Some infrastructure names schemas with an environment suffix: bikeshare_staging in staging, bikeshare_production in production. Rather than maintaining separate directories for each environment, use {env} in the directory name. When an environment is specified (via -e), {env} is replaced with the environment value. Existing $ENV directories remain supported.

Example

Directory structure:

myapp/schema/
├── schemabot.yaml
└── bikeshare_{env}/
    ├── bikes.sql
    └── stations.sql

Running against different environments resolves the namespace accordingly:

# Namespace becomes "bikeshare_staging"
schemabot plan -s myapp/schema -e staging

# Namespace becomes "bikeshare_production"
schemabot plan -s myapp/schema -e production

Rules

  • {env} and legacy $ENV are replaced with the environment value from -e (e.g., staging, production). New schemabot onboard --template-env-suffix output uses {env}.
  • If no environment is specified, the tokens are left as-is (no substitution).
  • Works in both flat layout (directory name = namespace) and subdirectory layout (subdirectory names = namespaces).
  • You can mix templated directories with regular directories in the subdirectory layout. Do not include both bikeshare_{env}/ and bikeshare_$ENV/ in one schema root: they resolve to the same namespace and are rejected.
  • Quote literal paths in shell commands, especially legacy $ENV names, to prevent shell variable expansion.
  • Pass concrete schema names to pull --namespace and onboard --namespace, such as bikeshare_production; placeholders are for repository directories and ignore_namespaces entries.

Per-Environment Schema Roots

By default every environment reads the same schema: the directory holding schemabot.yaml. When environments need different schemas, give the config directory an entry named for the environment. That entry becomes the environment's schema root, and its subdirectories are the environment's namespaces. Pull request plans and local schemabot plan -s <config dir> -e <environment> resolve it the same way, so a local plan reads the schema the pull request plans. schemabot onboard writes the pulled namespace files into the source environment's schema root, and schemabot.yaml stays in the config directory.

The entry can be a real directory or a symlink. Environments that share one schema can point at a common directory:

orders/schema/
├── schemabot.yaml
├── base/
│   └── orders_001/
│       └── orders.sql
├── staging    -> base
└── production -> base

An environment directory can also be built from namespace symlinks into one shared tree. Each environment then lists only the namespaces it has, with no ignore_namespaces entries needed for the rest:

app/
├── schemabot.yaml
├── tables/
│   └── app_{env}/
│       └── items.sql
├── staging/
│   ├── app_{env}   -> ../tables/app_{env}
│   └── app_1_{env} -> ../tables/app_{env}
└── production/
    └── app_{env}   -> ../tables/app_{env}

Here staging plans app_staging and app_1_staging, and production plans app_production.

  • An environment with no entry of its own reads the config directory.
  • An environment symlink must use a relative target that resolves to a directory inside the config directory, and every directory on the way to the target must be a real directory. An absolute target, a target outside the config directory, a target reached through another symlinked directory, or a target that is not a directory fails the plan instead of falling back to the config directory.
  • An entry named for the environment that is neither a directory nor a symlink also fails the plan.
  • Namespace symlinks inside an environment directory resolve relative to that directory. They may point anywhere in the repository, including outside the environment directory, as ../tables/... does above.
  • With flat files directly in an environment schema root, the namespace is that root's directory name after any symlink is resolved. In the first layout that is base.
  • A pull request that only adds, repoints, renames, or removes an environment or namespace symlink, or turns one into a regular file, changes the schema an environment plans, so SchemaBot plans it like any other schema change. A symlink to a file, such as one documentation file linking another, is not a schema input unless it sits directly in a config directory, where an environment's schema root is named.
  • SchemaBot learns which changed files are symlinks from the pull request's diff. When GitHub will not produce the diff, because the pull request changes too many files or lines, or a file is renamed without changes, and the repository is also too large for GitHub to list in one request, the files that listing leaves out are read only inside the databases' allowed_dirs. Without allowed_dirs on every database the repository serves, SchemaBot treats them as regular files, logs a warning, and counts them in schemabot.github.symlink_modes_unread_total, so a symlink change among them is not planned.

Ignoring Namespaces

Some schema roots contain a namespace directory that should never be reconciled against a live database. A common example is a Vitess keyspace that exists only in local test infrastructure: the repository carries its schema files so local tooling can create the keyspace, but no real environment has it (or the environment keeps it intentionally empty). Without an exclusion, every plan would propose creating those tables.

List such namespaces under ignore_namespaces in schemabot.yaml:

myapp/schema/
├── schemabot.yaml
├── commerce/
│   ├── orders.sql
│   └── vschema.json
└── commerce_test/          ← ignored: never planned or applied
    ├── fixtures.sql
    └── vschema.json
# schemabot.yaml
database: commerce
type: vitess
ignore_namespaces:
  - commerce_test

Rules

  • Entries are bare namespace names, not paths. An entry containing / or \ (e.g., schema/commerce_test) is rejected when the config is loaded.
  • Ignored namespaces are excluded from plans, applies, and merge-gate checks. This applies to both the GitHub PR flow and the CLI (schemabot plan / schemabot apply read the same schemabot.yaml).
  • {env} and legacy $ENV substitution apply to entries the same way they apply to directory names: fixtures_{env} ignores the fixtures_staging namespace when planning for staging.
  • Matching is exact and case-sensitive. An entry that matches no namespace directory excludes nothing; the plan proceeds and the unmatched entry is reported (a CLI warning, a server-side log) so a typo or stale entry is visible.
  • Ignoring every namespace in the schema root is an error: the plan fails rather than reconciling an empty desired state.
  • Ignoring a namespace does not exempt the directory from layout validation; a schema root mixing flat files and subdirectories is still rejected.

Exclusions are disclosed

Every plan that excluded namespaces says so: the PR plan comment renders an ℹ️ Namespaces excluded from this plan by ignore_namespaces: … line under the plan summary (also on "no changes" results, so a withheld namespace is distinguishable from an unchanged one), and the CLI prints the same disclosure for plan and apply. When reviewing a PR that introduces an ignore_namespaces entry, the disclosure plus the config diff is the review surface: the plan stops reconciling that namespace from this PR onward.

MySQL target DSN requirements

For MySQL targets, ignore_namespaces requires a namespace-free target DSN (one that does not name a database), where each namespace directory is diffed against its own database. A DSN that already names a database diffs the whole database as one unit: an ignored namespace's live tables would have no declaring files and the diff would plan them as DROP TABLE, the inverse of "ignore". SchemaBot refuses this combination, and the plan fails with an error asking for a namespace-free DSN or removal of ignore_namespaces.

A DSN that names a database also cannot drop a table when the schema root has two or more namespaces. Every namespace is diffed against that one database, so a live table that no schema file declares is in every namespace's live schema at once, and the deleted file that said which namespace held it is no longer in the request. SchemaBot cannot place the DROP TABLE in a namespace, so the plan fails with an error that names the table, the namespaces and the database. To drop it, keep that database's schema files in one namespace directory, or have a SchemaBot operator switch the target to a namespace-free DSN. With a single namespace, the drop belongs to it and is planned like any other drop.

Ignoring Tables

Some live tables exist in a managed namespace but are not SchemaBot's to manage: a schema-versioning tool's bookkeeping table, a table owned by a third-party framework, a one-off table an operator created by hand. No file declares them, so every one is planned as DROP TABLE, and that unsafe change blocks the merge until someone reaches for --allow-unsafe, which un-blocks every other drop in the plan too.

Temporary tables are the same case with a schedule attached: a backfill's working copy, a staging table a nightly job creates and drops, anything a process leaves on the target between runs. Whether the plan sees one depends on when it runs, so without an entry the same branch plans a drop on one push and nothing on the next. An entry covers both, since it withholds the table when it is there and is silent when it is not.

List such tables under ignore_tables in schemabot.yaml:

# schemabot.yaml
database: commerce
type: mysql
ignore_tables:
  - flyway_schema_history
  - legacy_audit_log

An ignored table is withheld from the planner's view of the live schema. The plan neither proposes creating it nor proposes dropping it, and an apply never touches it.

Patterns

Some applications create tables at runtime, such as one queue table per configured trigger. A list of names cannot cover the next one created, so the next plan proposes dropping it. Wrap a regular expression in slashes to withhold the whole family:

# schemabot.yaml
database: commerce
type: mysql
ignore_tables:
  - flyway_schema_history
  - /^relay_[0-9]+_feed$/
  • A pattern matches the whole table name, whether or not you write ^ and $. /relay_[0-9]+_feed/ withholds relay_7_feed, but not old_relay_7_feed or relay_7_feed_backup. To also match a prefix or suffix, say so with .*.
  • Matching is case-sensitive, the same as a plain entry. Start the expression with (?i) to ignore case.
  • The syntax is RE2, the regular expression syntax of Go. It has no backtracking, a pattern is at most 256 bytes, slashes included, and all of a config's patterns together are at most 1024 bytes, so no config can stall a plan. Lookarounds and backreferences are not supported.
  • A pattern that does not compile is an error naming the entry. The plan or apply fails rather than skipping the entry, because a skipped entry withholds nothing.
  • An entry is a pattern only when it starts and ends with /. Any other entry is an exact table name, so existing entries keep their meaning. Wrap a pattern in quotes if your YAML tooling needs it; the quotes are not part of the entry. A pattern cannot require a slash, so an entry such as /var/lib/app/ is refused as a path rather than read as a pattern that matches nothing.
  • A plan records the entries as written, and an apply, resume or rollback of that plan withholds by the same patterns. A table the application creates between the plan and the apply is withheld when it matches, never dropped.

Upgrade SchemaBot servers and data planes before adding a pattern. An older build refuses the pattern as a path when it reads schemabot.yaml. If a plan comes from an older data plane that reads the pattern as a literal table name, the server refuses that plan instead of storing a drop of the tables the pattern matches.

Rules

  • Entries are not namespace-qualified, so an entry applies to every namespace the plan covers. A name that occurs in two namespaces is withheld in both.
  • Environment substitution does not apply. Namespace entries substitute {env} or $ENV because namespace directories are environment-suffixed; table names are not.
  • A plain entry matches exactly and case-sensitively. An entry that matches no live table withholds nothing and the plan proceeds, without comment: a table that is not always on the target is the ordinary case, not a mistake. The server logs unmatched entries, patterns included.
  • On the MySQL-family engines, naming one archive-shaped table (<name>_archive_YYYY, with an optional month and day) makes the planner read every archive table's definition on that target, whether or not the entry matches anything. Any pattern entry does the same, since SchemaBot cannot tell before reading the catalog whether a pattern matches an archive table. That shape is what daily or monthly partition rotation produces, so on a rotating target the extra reads can be substantial. Prefer naming the table you mean.

Declaring a table in a schema file and ignoring it is a contradiction SchemaBot refuses, at onboard time before anything is written and at plan time thereafter. That includes a pattern that matches a declared table. The refusal ignores case, since some databases fold table names to lower case. Two spellings count as the same table when one lower-cases or Unicode-folds to the other, for plain entries and patterns alike, so a few non-ASCII spellings that were distinct before patterns, such as the long s ſ and s, now collide. The error names the entries to remove, and for a pattern, the declared tables it matches, so you can narrow it.

Databases that share a schema

Two databases can split one schema between them. One example is an app whose unsharded tables live in shard 0's schema, next to that shard's copy of the sharded tables. One database holds the unsharded tables, and the other holds the sharded tables in every shard's schema. On the cluster where they meet, each database's plan sees the other's tables as undeclared, so each schemabot.yaml lists the other's tables under ignore_tables:

# shop/schemabot.yaml           # shop_sharded/schemabot.yaml
database: shop                  database: shop_sharded
type: mysql                     type: mysql
ignore_tables:                  ignore_tables:
  - orders                        - sequences
  - order_items

A pull request that adds a table to one database has to add it to the other's ignore_tables too. Otherwise its own plan passes, and the missing entry only shows up later, as a DROP TABLE in the other database's plan. So SchemaBot checks every plan and apply from a pull request for this.

Two databases share a schema when, in the same environment, both have a target on the same cluster behind the same deployment, and a namespace of each is stored in one schema there. SchemaBot asks that deployment's data plane which schema each namespace addresses on the target, because only the data plane knows the target's connection. A MySQL target whose DSN names a database stores every namespace in that database. A target with a schema_overrides entry stores the namespace under the override's name. Otherwise each namespace is its own schema, so shop and shop_sharded on the same cluster share nothing. For each table that one database declares in a shared schema, the other must withhold it, by name or by pattern. If it does not, the environment's check fails. The error names the table, the database whose ignore_tables is missing it, and the file to add it to. The other database's files are read from the pull request's head, so a pull request that adds the table and the entry together passes.

  • A table that both databases declare in one schema also fails the check, whatever the lists say. Each table belongs to one of them. This holds when the two declare it under different namespaces that the target stores in one schema. A pair that declares the same table name under two namespaces the target stores as two schemas passes, because those are two separate tables.
  • A database cannot withhold a table it declares itself. ignore_tables applies to every namespace of a database, so when the other database declares a table in a shared schema and this one declares a table of the same name in another of its namespaces, no entry can keep it out. The check fails and names both namespaces. Rename one of the two tables, or store the two namespaces in different schemas.
  • Every data plane that serves one of the targets must be able to report which schema each namespace addresses. A data plane from a release that cannot fails the environment, and the comment names the deployment to upgrade. Any other failure to get the answer fails the environment too, and the server logs have the cause.
  • Entries match case exactly. A target that folds table names stores Refunds as refunds, so a table declared with capital letters needs an entry for its lower-case spelling as well, or a pattern that matches both. The error names every spelling still missing.
  • The other database's files must come from a directory its own allowed_dirs allow, the same source policy its own plans pass. If they do not, or if SchemaBot cannot read them, the environment fails. It does not pass a pair it could not compare. A schemabot.yaml found elsewhere in the repository is refused the same way.
  • A database whose schemabot.yaml is in another repository is managed from there, so it is not compared. SchemaBot skips it when the database accepts no schema changes from this repository, or when a search of the repository read every config it found and none was for that database. A miss that skipped an unreadable config fails the environment.
  • An apply also needs the branch to have every base branch change to the other database's schemabot.yaml and schema files. The comparison read them at the pull request's head, so a branch missing a newer change to them is refused as stale, like a branch missing a change to the database's own schema. Merge or rebase the base branch and apply again.
  • A plan narrowed with --target runs the check too. The disagreement is in the schema files, so it fails the environment's check whichever target the plan named.
  • The CLI plans one database from a local directory and does not run this check.

Exclusions are disclosed

Every plan that withheld tables says so: the PR plan comment renders an ℹ️ Tables in … excluded by `ignore_tables`: … line under the plan summary (also on "no changes" results, so a withheld table is distinguishable from a declared one), and the CLI prints the same disclosure for plan and apply. Past five tables the line leads with its count and folds the names into a collapsed block, so how many were withheld stays visible unexpanded. The reason in parentheses says who withheld the table: ignore_tables is this config, and the planners use the same line for the tables their own naming conventions leave in place:

Reason Engines Tables
archive naming MySQL, PostgreSQL <name>_archive_YYYY, with an optional month and day
leading underscore MySQL Names starting with _, such as an online schema change's shadow, checkpoint or leftover tables

The MySQL planner applies the leading-underscore convention before ignore_tables, so an entry naming a _ table is reported under leading underscore, not as withheld by the config. The PlanetScale planner leaves _ tables out without disclosing them, and does not skip archive tables. The PR comment and CLI name the first 50 tables of a group and count the rest.

A schema file that declares a live table one of these conventions skips is refused on MySQL, naming the table: the planner never sees the live table, so it would propose creating a table that already exists.

When reviewing a PR that introduces an ignore_tables entry, the disclosure plus the config diff is the review surface: the plan stops seeing that table from this PR onward.

Dropping Tables

The MySQL planner leaves some live tables out of every plan by their names: an online schema change's leftover _ tables and <name>_archive_YYYY tables (see the table above). Because the plan never sees them, removing a schema file cannot drop them. To drop one through SchemaBot, name it under drop_tables in schemabot.yaml:

# schemabot.yaml
database: commerce
type: mysql
drop_tables:
  - _events_old

The plan proposes DROP TABLE for each listed table that is on the target. The statement shows in the PR plan comment and in plan and apply output like any other drop, and the drop is listed under unsafe changes, so it needs the same consent as any other drop (--allow-unsafe). On a deployment with pending drops enabled, the apply moves the table into _pending_drops rather than dropping it outright, so it can be recovered until the retention period ends.

An entry that names no table on the target plans nothing, and the PR plan comment and plan and apply output say so, one line per entry:

⚠️ drop_tables entry _events_olds names no table on the target, so this plan drops nothing for it. Fix the name, or remove the entry if the table is already gone.

That is usually a typo, a name wrapped in backticks, the wrong case, or a table already dropped. Without the line, the table you meant would still be listed under its naming convention and the plan would look clean.

When a plan covers several environments, an entry is listed only when no environment's plan has the table. Once the drop has landed in staging and not yet in production, staging's plan is clean and production's still drops the table, so the entry is not listed: it is still needed for production. The first 20 entries get a line each, and one more line counts the rest.

The same rule holds across the targets of an environment that rolls out to several. Every target is planned with the same list, so an entry is listed only when no target has the table. While one target still has it and plans its drop, the entry is not listed. If a target could not be planned, no entry is listed, since what that target holds is unknown.

Rules

  • MySQL only. A plan of a PostgreSQL database, or of one the PlanetScale engine plans, fails when its config lists drop_tables and asks you to remove the key.
  • Each entry is one exact, case-sensitive table name. There are no patterns: list each table to drop, so the config diff shows every table the plan will drop. An entry that is blank, padded with whitespace, or contains / is an error naming it.
  • Entries are not namespace-qualified, so an entry applies to every namespace the plan covers.
  • A table a schema file declares cannot also be listed, and neither can a table ignore_tables withholds. The plan fails and names the entry, so you can remove it from one of the two.
  • A listed table written in the last 24 hours is refused, naming it. A table that still receives rows, such as the shadow table of an online schema change another tool is running, is not a leftover yet. Wait until nothing writes to it. The check reads the write time MySQL keeps in memory, which starts empty when the server starts. When MySQL has no write time for a listed table, the plan proceeds only if the server has been up for at least 24 hours, since it would have recorded any write in that time. On a server up for less, the plan is refused and says how long to wait. MySQL also keeps no write time for a table it has evicted from its dictionary cache, which it does only to a table nothing has open, or for any table after a replica that was already running takes over as the writer, so in those cases a write in the last 24 hours goes unseen. Passing the check does not prove nothing uses the table: confirm that yourself before you list it.
  • _spirit_sentinel, in any case, is refused. It is the table that holds an apply started with --defer-cutover until someone runs the cutover, so dropping it would run that cutover. Run it with schemabot cutover instead.
  • A listed table that is a working table of a SchemaBot apply on the same database and environment that is still running or is stopped, such as its copy _users_new or its checkpoint _users_chkpnt, is refused, naming the apply. A stopped apply resumes from that copy, so start or cancel the apply first. The names are worked out from the tables the apply changes, the way the engine shortens them to fit 64 characters included. A collision refuses the entry for both tables, which errs on the safe side. The check runs when the plan is made and again when the apply is created.
  • An entry that names no live table plans nothing and the plan proceeds. The server logs the entry, so an operator can tell a stale or misspelled entry from a drop that ran.
  • A rollback never drops a listed table. It restores the schema the apply started from, so a listed table still on the target is left in place. A listed table the naming conventions skip stays dropped, since the planner never manages it. A listed table with an ordinary name is recreated, as it would be without the list.
  • A plan records the entries, and an apply, resume or drift check of that plan proposes the same drops.

Remove the entry once the drop has landed. An entry left behind plans nothing, but it would drop a table someone later creates under the same name.

Per-Target Schema Overrides

{env} and $ENV substitution handle physical schema names that vary by environment. When names vary by deployment within one environment — several regional clusters in the same environment naming the schema bikeshare_qa, bikeshare_eu_qa, and bikeshare_us_qa — one schema directory cannot express the variance, and copying the directory per region would triple the source of truth.

Instead, keep one canonical directory (bikeshare/) and map the canonical namespace to each deployment's physical schema on the data-plane target. (target_resolver is the gRPC data plane's target-to-connection inventory — see Configuration for how targets are defined.)

target_resolver:
  targets:
    eu-bikeshare-qa:
      type: mysql
      schema_overrides:
        bikeshare: bikeshare_eu_qa
      dsn_from:
        # namespace-free endpoint/credentials

The canonical namespace stays the name everywhere SchemaBot labels a namespace — requests, plans, tasks, drift comparison, pull responses. The physical name only enters the data plane where the engine addresses the schema. The one place it is visible to a reviewer is the DDL itself: PostgreSQL statements are schema-qualified, so the SQL a plan shows and an apply executes names the physical schema, exactly as it will run on the target. SchemaBot never rewrites DDL to hide that, and an apply whose stored DDL names a different schema than the target now maps the namespace to is refused rather than executed.

Rules

  • MySQL and PostgreSQL are supported, with exactly one mapping per target.
  • A MySQL target DSN must be namespace-free; a DSN that already names a database is rejected at config load. A PostgreSQL DSN names the database while the override selects a schema within it.
  • A non-empty map is a strict allowlist: a requested namespace without a mapping fails rather than falling back to the canonical name, so a misrouted request cannot land in the wrong physical schema.
  • An empty/omitted map preserves the default behavior: the requested namespace is the physical schema.
  • MySQL schema names must be unquoted-identifier-safe ([a-zA-Z0-9_$], at most 64 characters).
  • PostgreSQL schema names must be non-empty and at most 63 bytes, with no double quote, NUL, or leading or trailing whitespace. Other characters, including hyphens, are supported because identifiers are quoted by the PostgreSQL engine.

Summary

Scenario schemabot.yaml Namespaces Example
MySQL, single schema 1 1 testapp/
MySQL, multiple schema names 1 many app_primary/, app_analytics/
MySQL, different databases 1 per database 1 each separate directories
Vitess, multiple keyspaces 1 many commerce/, commerce_sharded/
Environment-specific namespace 1 1 per env bikeshare_{env}/ (legacy bikeshare_$ENV/)
Different schema per environment 1 per environment root staging/, production -> base
Repo-only namespace (never deployed) 1 all except ignored ignore_namespaces: [commerce_test]
Deployment-specific physical schema 1 1 canonical bikeshare/ + per-target schema_overrides

How Namespaces Flow Through the System

The namespace key is always the directory name. Each stage maps namespaces to progressively richer types:

1. Schema directory — directories on disk

schema/
├── schemabot.yaml
├── commerce/            ← namespace "commerce"
│   ├── orders_seq.sql
│   └── vschema.json
└── commerce_sharded/    ← namespace "commerce_sharded"
    ├── orders.sql
    └── vschema.json

2. SchemaFiles — parsed into map[string]*Namespace

"commerce"         → {Files: {"orders_seq.sql": "CREATE TABLE ...", "vschema.json": "{...}"}}
"commerce_sharded" → {Files: {"orders.sql": "CREATE TABLE ...", "vschema.json": "{...}"}}

3. PlanResult.Changes — engine outputs []SchemaChange

{Namespace: "commerce",         Tables: [{Table: "orders_seq", Operation: "alter", DDL: "..."}], Files: []}
{Namespace: "commerce_sharded", Tables: [{Table: "orders", Operation: "create", DDL: "..."}], Files: [{Name: "vschema.json", Diff: "..."}]}