Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
GÉANT Service Orchestrator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GÉANT Orchestration and Automation Team
GAP
GÉANT Service Orchestrator
Commits
db2473dc
Verified
Commit
db2473dc
authored
1 year ago
by
Karel van Klink
Browse files
Options
Downloads
Patches
Plain Diff
add global locking mechanism to database migrations
parent
1956ad7f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!95
add global locking mechanism to database migrations
Pipeline
#84350
passed
1 year ago
Stage: tox
Stage: documentation
Stage: sonarqube
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gso/migrations/env.py
+3
-12
3 additions, 12 deletions
gso/migrations/env.py
with
3 additions
and
12 deletions
gso/migrations/env.py
+
3
−
12
View file @
db2473dc
import
logging
import
os
import
orchestrator
from
alembic
import
context
from
orchestrator.db.database
import
BaseModel
from
orchestrator.settings
import
app_settings
from
sqlalchemy
import
engine_from_config
,
pool
from
sqlalchemy
import
engine_from_config
,
pool
,
text
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
...
...
@@ -17,17 +15,8 @@ logger = logging.getLogger("alembic.env")
config
.
set_main_option
(
"
sqlalchemy.url
"
,
app_settings
.
DATABASE_URI
)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata
=
BaseModel
.
metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def
run_migrations_offline
()
->
None
:
"""
Run migrations in
'
offline
'
mode.
...
...
@@ -85,8 +74,10 @@ def run_migrations_online() -> None:
)
try
:
with
context
.
begin_transaction
():
connection
.
execute
(
text
(
"
SELECT pg_advisory_xact_lock(1000);
"
))
context
.
run_migrations
()
finally
:
connection
.
execute
(
text
(
"
SELECT pg_advisory_unlock(1000);
"
))
connection
.
close
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment