fix: accept migration template configuration keys - #674
Merged
Conversation
The migration_config allowlist rejected the three keys the template renderer reads, so any customized migration template failed at config construction. - Declare templates, default_format, and title on MigrationConfig, with MigrationTemplates, SQLTemplateOverride, and PythonTemplateOverride describing the override shape. - Validate keys nested under templates.sql and templates.py, reporting the dotted path and the closest valid key, and reject non-mapping overrides with a clear message rather than a render-time TypeError. - Correct the version_table_name docstring: the default is ddl_migrations.
MIGRATION_CONFIG_KEYS rejects any key absent from the MigrationConfig declaration, so the declaration has to stay a complete inventory of what SQLSpec reads. Scan the package for key reads and assert the allowlist covers them. The scanner resolves one level of local aliasing, since a search keyed on the literal name misses the rebinding the template reader uses. Reads through a lookup result are deliberately not tracked, so nested keys are not mistaken for top-level ones. Fixture cases prove each read shape is detected.
- Convert the template tests from a stub config to a real adapter config so they exercise the validation path users hit, and cover the Python template override alongside the SQL one. - Add a migrations guide section for default_format, title, and templates, listing the placeholders each fragment can use. - Correct the documented version_table_name default. - Add the template override types to the configuration reference. - Record v0.58.1 in the changelog.
## Summary - bump SQLSpec to `0.58.1` - refresh prompt-toolkit to 3.0.53 in the lock file
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #674 +/- ##
==========================================
+ Coverage 77.30% 77.33% +0.02%
==========================================
Files 476 476
Lines 68052 68106 +54
Branches 9357 9363 +6
==========================================
+ Hits 52609 52668 +59
+ Misses 12035 12029 -6
- Partials 3408 3409 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
cofin
force-pushed
the
fix/migration-templates
branch
from
August 3, 2026 13:17
9efc0a0 to
c52c8e3
Compare
Subscripting the MigrationConfig TypedDict with a parametrized variable is not a literal key, which mypy rejects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
v0.58.0 started rejecting
migration_configkeys it does not recognize, but three keys that customize generated migration files were never on the recognized list. Anyone using a custom migration template could no longer build their configuration at all. This restores them, and adds a check so the list cannot fall behind again.What changed
templates,default_format, andtitleare accepted. Previously all three raisedImproperConfigurationErrorthe moment a configuration was constructed.default_formatwas the worst of them: the error suggesteddefault_schema, an unrelated setting that changes which schema migrations run against.templates.sqlortemplates.pyreports its full path and the closest valid key, sotemplates.sql.headerrtells you it meantheader. An override that is not a mapping is named along with the type you passed.MigrationTemplates,SQLTemplateOverride, andPythonTemplateOverridedescribe what each fragment accepts, so type checkers cover a surface that previously had none.TypedDict, so it is only correct while that declaration matches what the code actually reads. A test scans the package for key reads and fails if any is undeclared — which is what went unnoticed here, since the template reader rebinds the mapping to a local name before reading it.version_table_namedefaults toddl_migrations, notsqlspec_migrations; the migrations guide now has a template customization section.How you use it
Override only the fragments you want to change; everything else keeps its default.
sqlspec create-migration -m "add users"then writes:Every fragment is rendered with
str.format. Available placeholders aretitle,version,message,description,created_at,author,adapter,project_slug, andslug. The SQL template takesheader,metadata,body, anddescription_key; the Python template takesdocstring,imports,body, anddescription_key.Replacing
bodyreplaces the whole body, including the-- name: migrate-{version}-upand-- name: migrate-{version}-downmarkers.