--- name: mariadb-schema-management-develop description: "Develop the next version of a MariaDB Schema Management (MSM) schema in development/_next.sql, and keep large scripts maintainable by breaking section bodies out into development/sections/ files linked with the SOURCE ''[start:end]; statement. Use when evolving an existing MSM schema for a new version, editing the _next.sql development script, or splitting a growing schema script into SOURCE-included section files. Read mariadb-schema-management first for the section model." --- # MSM — Developing the Next Version After a release, `prepare_release` has already bumped the development version and you continue editing `development/_next.sql` toward the next release. This skill covers iterating on that script and the **SOURCE breakout** mechanism for keeping it maintainable. See `mariadb-schema-management` for the section model. Assume MariaDB 11.8. ## Iterating on `_next.sql` Make changes in the same sections you authored initially, using `msm.set_section_sql_content` / `msm.get_sql_content_from_section`: - New/changed **tables and data** → section 140. - New/changed **views, routines, triggers, events** → section 150 (idempotent: `CREATE OR REPLACE` / `DROP IF EXISTS`). This is the ONLY place for them: the target's section 150 runs in full on every deployment, so upgraded schemas get them too. Removing an object additionally needs a `DROP ... IF EXISTS` in the update script's section 240. - **Grants/roles** → section 170 (`CREATE ROLE IF NOT EXISTS`, then `GRANT`); it also runs on every deployment. Revoking a privilege additionally needs a `REVOKE` in the update script's section 270. The development file always describes the **full, current** schema (not a diff) — it is the source for the next version snapshot. The per-release *migration* from the previous version is written separately when you prepare the release (see `mariadb-schema-management-release`, sections 240/270). Keep the development version in section 910 current with `msm.set_development_version` as the target version firms up. ## SOURCE breakout files (keeping the script maintainable) When a section grows large, move its body into one or more files under `development/sections/` and reference them from `_next.sql` with a `SOURCE` statement. MSM inlines this content when it snapshots the version during `prepare_release`, so SOURCE is purely a **development-time** organizing tool — released version and deployment scripts are always fully inlined. ### Syntax ```sql SOURCE ''[:]; -- optional comment ``` - The `[start:end]` **slice is required** and is a character-offset slice of the referenced file's content (Python-style). Use `[0:]` for the whole file. `[:]` makes `prepare_release` fail, and a `SOURCE` line without a slice is copied into the release verbatim, so the deployment fails with a syntax error: - `[53:]` — drop the first 53 characters (e.g. a one-line copyright header). - `[663:-115]` — drop a 663-char header **and** the last 115 chars (footer). - `[:200]` — keep only the first 200 characters. - Relative paths resolve against the **development/** folder (where `_next.sql` lives), so use `'./sections/...'`. - The leading indentation of the `SOURCE` line is applied to every inlined line. ### Why the slice offsets Each breakout file is a **standalone, valid SQL file** with its own copyright header (and optionally a footer). The slice strips that header/footer so only the object definitions are inlined into `_next.sql`. Pick the offset to match your header length (count the characters up to the first real statement). ### Example `development/_next.sql`, section 140 body: ```sql SOURCE './sections/140-10_tables.sql'[663:-115]; -- Ignore header and footer SOURCE './sections/140-30_inserts.sql'[53:]; -- Remove copyright header ``` section 150 body: ```sql SOURCE './sections/150-10_views.sql'[53:]; SOURCE './sections/150-20_procedures_functions.sql'[53:]; SOURCE './sections/150-30_triggers.sql'[53:]; ``` ### File naming convention Name breakout files `-_.sql` so they sort in load order and map back to their section, e.g. `140-10_tables.sql`, `140-30_inserts.sql`, `150-20_procedures_functions.sql`, `170_roles.sql`. ### Rules - Respect the section's placement/delimiter rule even in breakout files: content destined for 140/170 must be plain `;`-terminated (it lands in a stored-procedure body); content for 150 uses `DELIMITER %%` for routine bodies. - Keep the `SOURCE` lines inside the correct MSM section of `_next.sql`; edit that section body via `msm.set_section_sql_content` so the banners stay intact. - After editing breakout files, a `prepare_release` will inline them; verify the generated version snapshot looks complete. ## Next When the development version is feature-complete, prepare a release: `mariadb-schema-management-release`. ## See Also - `mariadb-schema-management` — lifecycle overview and full section model. - `mariadb-schema-management-create` — the initial project + first authoring. - `mariadb-schema-management-release` — snapshot the version and write the migration. - `mariadb-alter-table`, `mariadb-create-view`, `mariadb-create-procedure` — the DDL you edit here.