diff options
author | morpheus65535 <[email protected]> | 2024-05-08 22:29:31 -0400 |
---|---|---|
committer | morpheus65535 <[email protected]> | 2024-05-08 22:29:31 -0400 |
commit | 4815313ac6f36154e6e59b0ee3ca87c04a36bb7c (patch) | |
tree | c060028db58eec367664dbb42a4df0ca7bff27b0 /migrations | |
parent | d686ab71b2e342f0b25a029aa4af263a23c6efeb (diff) | |
download | bazarr-4815313ac6f36154e6e59b0ee3ca87c04a36bb7c.tar.gz bazarr-4815313ac6f36154e6e59b0ee3ca87c04a36bb7c.zip |
Fixed db migrations dropping tables content because of ForeignKey constraints. #2489
Diffstat (limited to 'migrations')
-rw-r--r-- | migrations/env.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/migrations/env.py b/migrations/env.py index d706218a2..beddf9710 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,6 +1,7 @@ from flask import current_app from alembic import context +from sqlalchemy import text import logging @@ -95,8 +96,22 @@ def run_migrations_online(): ) with context.begin_transaction(): + bind = context.get_bind() + + if bind.engine.name == 'sqlite': + bind.execute(text("PRAGMA foreign_keys=OFF;")) + elif bind.engine.name == 'postgresql': + bind.execute(text("SET CONSTRAINTS ALL DEFERRED;")) + context.run_migrations() + if bind.engine.name == 'sqlite': + bind.execute(text("PRAGMA foreign_keys=ON;")) + elif bind.engine.name == 'postgresql': + bind.execute(text("SET CONSTRAINTS ALL IMMEDIATE;")) + + bind.close() + if context.is_offline_mode(): run_migrations_offline() |