MSM — Deploying a Schema Version
The final lifecycle step: apply a generated deployment script to a MariaDB
server. One script both creates a fresh schema and upgrades any older
released version to the target. Driven by msm.* + db.* tools of the
mariadb-shell MCP server. See mariadb-schema-management for the model.
Assume MariaDB 11.8.
Prerequisite
The deployment script for the target version must already exist
(releases/deployment/<schema>_deployment_<version>.sql), i.e. the release was
prepared, its update script filled, and the deployment script generated — see
mariadb-schema-management-release. Check what is deployable with
msm.get_deployment_script_versions.
Deploy
1. conn = db.connect(uri="root@host:port") # open a connection first
2. msm.deploy_schema(
connection_id=conn,
version="1.1.0", # optional; defaults to the latest generated script
backup=True, # optional; dump an existing schema before upgrading
backup_directory="...", # optional; where the backup is written
)
msm.deploy_schema runs the deployment script on that connection. It requires an
open connection (that is why the tool is only available alongside the db.*
group). With backup=True, an existing schema is dumped first so a failed
upgrade can be restored.
Create-or-upgrade semantics
The deployment script decides what to do from the target schema's state:
- Empty / absent schema → created fresh at the target version.
- Existing MSM schema at an older released version → upgraded by running each
msm_update_<from>_to_<to>()in sequence up to the target, then applying the idempotent objects and authorization. - Already at the target version → nothing to change.
The msm_schema_version view is the source of truth for the installed version;
it is set to 0,0,0 while a create/upgrade is in progress. The script aborts
with a clear SIGNAL error when it cannot safely proceed:
- a non-MSM schema of the same name exists (no
msm_schema_versionview); - the schema is stuck at
0,0,0(a previous run was interrupted); - the current version has no update path in this deployment script.
Inspect state with msm.get_last_deployment_version (what a server would report)
and msm.get_last_released_version / msm.get_released_versions (project side).
Guidelines
- Deploy the generated script only; never a hand-edited deployment file.
- Use
backup=Truefor production upgrades so a failure is recoverable. - Upgrades are only possible along the released-version chain — if a server is on a version with no update script leading toward the target, the deployment will refuse it. Ensure every release was prepared with its update script filled.
- Re-running the same version is safe (idempotent objects re-create cleanly; the create/upgrade dispatcher is version-guarded).
See Also
mariadb-schema-management— lifecycle overview and full section model.mariadb-schema-management-release— generating the deployment script this step runs.mariadb-schema-management-develop— the development script releases are cut from.