Repository navigation
Add plain postgres models, and stop doubling % in constraint literals - #162
Merged
Merged
Conversation
…rals `plain postgres models` describes the data model as the registry sees it, with no database: every field, every relation with its target and `on_delete` rule, the relations pointing back at each model with any declared reverse accessor, and constraints and indexes with their conditions compiled to SQL. `--json` carries the same facts as data, a target narrows it to a model (by class name, label or table) or a package, and `--all` adds the installed packages' models. `unique` and `1:1` mean effective uniqueness: an unconditional single-field unique constraint, never a partial one. The same facts are `plain.postgres.describe`. `quote_value` no longer doubles `%` in a string literal. The DDL it feeds runs with no parameters, so the doubled form was stored as written: a `CheckConstraint(check=~Q(name="100%"))` was created as `'100%%'` and let the one value it names through. Convergence recognizes a stored definition that only differs by the doubled literal and replaces the constraint under its own name — a check in one DROP/ADD statement then validated, a unique rebuilt concurrently under a temporary name and swapped in — instead of reporting a definition change you have to stage. A model edited from a `100%%` literal to `100%` looks the same to it and is replaced in place; the validation still has to pass. Also: `Options.unique_field_names`, `PackageConfig.is_app` in place of three prefix checks, `reversed_field` on reverse descriptors, and `plain postgres schema` sharing the same target matching.
Contributor
|
Next steps:
|
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.
What
plain postgres modelsdescribes the data model as the registry sees it, with no database connection: every field, every relation with its target andon_deleterule, the relations pointing back at each model with any declared reverse accessor, and constraints and indexes with their conditions compiled to SQL.--jsoncarries the same facts as data; a target narrows it to a model (class name, label or table) or a package;--alladds the installed packages' models. The same facts are available fromplain.postgres.describe.uniqueand1:1mean effective uniqueness: an unconditional, single-field unique constraint. A partial unique is listed with itsWHEREclause and never promoted, so "one open thread per bot" can't be mistaken for "one thread per bot".quote_valueno longer doubles%in string literals. The DDL it feeds runs with no parameters, so the doubled form was stored as written:CheckConstraint(check=~Q(name="100%"))was created as'100%%'and let the one value it names through.Upgrade path. Existing databases hold the doubled form. Convergence now recognizes a stored definition that differs from the model only by that doubling and replaces the constraint under its own name without staging: a check in one
DROP CONSTRAINT, ADD CONSTRAINT ... NOT VALIDstatement then validated; a unique rebuilt concurrently under a temporary name and swapped in inside one transaction. The table is never without the constraint. A failed replacement blocks sync. Plain indexes already rebuilt automatically.Known limit: a model edited from a
100%%literal to100%produces the same stored text and is replaced in place rather than staged under a new name. The validation still has to pass.Also:
Options.unique_field_names,PackageConfig.is_appreplacing three prefix checks, a publicreversed_fieldon reverse descriptors, andplain postgres schemasharing the same target matching (it now accepts a package label too).Verified