forked from mozilla-releng/balrog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1310213 - enable scheduled deletions (mozilla-releng#182). r=bhea…
…rsum
- Loading branch information
Showing
12 changed files
with
401 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from sqlalchemy import Column, String, MetaData, Table | ||
|
||
|
||
def upgrade(migrate_engine): | ||
metadata = MetaData(bind=migrate_engine) | ||
|
||
# In order to add a column a nullable=False: | ||
# 1) Add the column with nullable=True | ||
change_type = Column("change_type", String(50)) | ||
change_type.create(Table("rules_scheduled_changes", metadata, autoload=True)) | ||
|
||
# 2) Update the values of change_type depending on base_data_version | ||
|
||
migrate_engine.execute(""" | ||
UPDATE rules_scheduled_changes | ||
SET change_type = "insert" | ||
WHERE base_data_version is NULL; | ||
""") | ||
migrate_engine.execute(""" | ||
UPDATE rules_scheduled_changes | ||
SET change_type = "update" | ||
WHERE base_data_version is not NULL; | ||
""") | ||
|
||
# 3) Alter the column and set nullable=False | ||
change_type.alter(nullable=False) | ||
|
||
change_type = Column("change_type", String(50)) | ||
change_type.create(Table("rules_scheduled_changes_history", metadata, | ||
autoload=True)) | ||
|
||
migrate_engine.execute(""" | ||
UPDATE rules_scheduled_changes_history | ||
SET change_type = "insert" | ||
WHERE base_data_version is NULL; | ||
""") | ||
migrate_engine.execute(""" | ||
UPDATE rules_scheduled_changes_history | ||
SET change_type = "update" | ||
WHERE base_data_version is not NULL; | ||
""") | ||
rules_scheduled_changes = Table("rules_scheduled_changes", metadata, autoload=True) | ||
rules_scheduled_changes.c.base_update_type.alter(nullable=True) | ||
|
||
|
||
def downgrade(migrate_engine): | ||
metadata = MetaData(bind=migrate_engine) | ||
Table("rules_scheduled_changes", metadata, autoload=True).c.change_type.drop() | ||
Table("rules_scheduled_changes_history", metadata, | ||
autoload=True).c.change_type.drop() |
Oops, something went wrong.