Merge pull request !2775 from rhodecode-enterprise-ce feature/RCCE-217_optimize_migration
feature: adds validation that column does not exist before adding it
This commit is contained in:
commit
cf21fcf3da
1 changed files with 15 additions and 9 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
import logging
|
||||
|
||||
from psycopg2.errorcodes import DUPLICATE_COLUMN
|
||||
from sqlalchemy import *
|
||||
from sqlalchemy.engine import reflection
|
||||
|
||||
|
|
@ -24,18 +26,22 @@ def upgrade(migrate_engine):
|
|||
|
||||
context = MigrationContext.configure(migrate_engine.connect())
|
||||
op = Operations(context)
|
||||
inspector = inspect(migrate_engine)
|
||||
|
||||
pr_tables = [db.PullRequest.__table__, db.PullRequestVersion.__table__]
|
||||
for pr_table in pr_tables:
|
||||
with op.batch_alter_table(pr_table.name) as batch_op:
|
||||
new_column = Column(
|
||||
"settings_json",
|
||||
MutationObj.as_mutable(
|
||||
JsonType(dialect_map=dict(mysql=UnicodeText(16384))),
|
||||
),
|
||||
default=dict,
|
||||
)
|
||||
batch_op.add_column(new_column)
|
||||
existing_columns = [col["name"] for col in inspector.get_columns(pr_table.name)]
|
||||
new_column_name = "settings_json"
|
||||
if new_column_name not in existing_columns:
|
||||
with op.batch_alter_table(pr_table.name) as batch_op:
|
||||
new_column = Column(
|
||||
new_column_name,
|
||||
MutationObj.as_mutable(
|
||||
JsonType(dialect_map=dict(mysql=UnicodeText(16384))),
|
||||
),
|
||||
default=dict,
|
||||
)
|
||||
batch_op.add_column(new_column)
|
||||
|
||||
_inherit_settings(db, meta.Session, op)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue