Refactor initialization script transaction management (PP-3684)#3048
Merged
jonathangreen merged 4 commits intomainfrom Feb 13, 2026
Merged
Refactor initialization script transaction management (PP-3684)#3048jonathangreen merged 4 commits intomainfrom
jonathangreen merged 4 commits intomainfrom
Conversation
774bdfe to
4c5f7b1
Compare
2b922e9 to
e26953d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3048 +/- ##
=======================================
Coverage 93.04% 93.04%
=======================================
Files 480 480
Lines 43712 43716 +4
Branches 6028 6027 -1
=======================================
+ Hits 40670 40677 +7
+ Misses 1972 1968 -4
- Partials 1070 1071 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Move from a single long-lived connection wrapping all initialization to letting each sub-operation manage its own transaction boundaries. The advisory lock is now held on a dedicated connection while schema creation, data initialization, and Alembic migrations each use their own connections and transactions. Update pg_advisory_lock to accept Engine | Connection and yield the lock connection, removing the lock_id=None sentinel in favor of callers using nullcontext() directly.
e26953d to
2a532d7
Compare
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.
Description
Refactor the initialization script's transaction management so that each sub-operation (schema creation, data initialization, Alembic migrations) manages its own transaction boundaries, rather than wrapping everything in a single long-lived connection and transaction.
Key changes:
pg_advisory_locknow acceptsEngine | Connectionand yields the lockConnection, removing thelock_id=Nonesentinel in favor of callers usingnullcontext()directly.InstanceInitializationScript.run()passes theEnginetopg_advisory_lockinstead of creating a connection + transaction up front. The advisory lock is held on a dedicated connection while sub-operations use their own connections.initialize_database_schemanow scopes each step (schema DDL, data init, Alembic stamp) in its own transaction._db_initializedstatic method for checking whether the database has been initialized.argsparameter torun()to allow tests to pass arguments directly instead of relying onsys.argv.Motivation and Context
This lays the groundwork for PP-3684, which requires a more well-defined transaction model for initialization.
How Has This Been Tested?
tests/manager/scripts/test_initialization.pytests/manager/sqlalchemy/test_util.pywith parametrizedEngine/Connectionpathstests/migration/test_instance_init_script.pyChecklist