1456 Update registration tables with comments - #4796
Merged
Sepehr-Sobhani merged 3 commits intoJun 20, 2026
Merged
Conversation
Sepehr-Sobhani
force-pushed
the
1456-registration-app-tables-have-meaningful-metadata
branch
2 times, most recently
from
June 12, 2026 22:41
6ee2c24 to
89552a4
Compare
Sepehr-Sobhani
force-pushed
the
1456-registration-app-tables-have-meaningful-metadata
branch
from
June 16, 2026 16:50
89552a4 to
973c715
Compare
dleard
approved these changes
Jun 17, 2026
dleard
left a comment
Contributor
There was a problem hiding this comment.
Looks good! I see a couple places where a URL to the source regulation may be helpful?
Sepehr-Sobhani
force-pushed
the
1456-registration-app-tables-have-meaningful-metadata
branch
2 times, most recently
from
June 19, 2026 23:43
c6b470e to
5784e37
Compare
Sepehr-Sobhani
force-pushed
the
1456-registration-app-tables-have-meaningful-metadata
branch
from
June 20, 2026 00:16
48e317a to
9018d46
Compare
Sepehr-Sobhani
deleted the
1456-registration-app-tables-have-meaningful-metadata
branch
June 20, 2026 00:28
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.
ISSUE 1456
⚠️ This PR added approximately 7,000 new lines of code through the new migration file. We should consider squashing migrations again two or three releases after the latest ticket about adding metadata to the tables is completed.What is
SeparateDatabaseAndState?Django's migration system maintains two parallel layers:
Normally these stay in sync because operations like
AlterFielddo both at once: run the SQL against the database and update Django's tracked state.SeparateDatabaseAndStateis an escape hatch that lets you decouple these two layers, providing separate operation lists for each:The issue
Django's
AlterFieldon a FK or OneToOneField generatesALTER TABLE ... ALTER COLUMN ... TYPE ...in PostgreSQL. PostgreSQL blocks this statement when the column is referenced in a trigger WHEN clause or an RLS policy expression, producing:Since the only actual schema change needed is adding a
db_comment, we useCOMMENT ON COLUMNinstead — a separate DDL statement that does not touch the column type and is not blocked by triggers or policies. However, using a plainRunSQL("COMMENT ON COLUMN ...")would leave Django's migration state out of sync, causingmakemigrationsto re-detect the missingdb_commentand regenerate the same failingAlterFieldon the next run.SeparateDatabaseAndStatesolves both problems:database_operationsrunsCOMMENT ON COLUMN— safe, avoids the conflictstate_operationsrunsAlterFieldagainst Django's state only (never touches the DB) — keeps the tracked schema in syncThe affected columns, grouped by the reason they are blocked:
Blocked by pgtrigger trigger WHEN clauses:
restrict_bcghg_id_unless_operation_registerederc.facilitybcghg_id_idrestrict_bcghg_id_unless_registerederc.operationbcghg_id_idrestrict_boro_id_unless_registerederc.operationbc_obps_regulated_operation_idBlocked by RLS policy subquery expressions:
compliance_obligation_industry_user_delete_policyandoperationpolicieserc.operationoperator_iderc.user_operatoroperator_iderc.user_operatoruser_id