-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from evo-company/improve-remove_project
Improve remove_project, add migration to cleanup condition.checks field
- Loading branch information
Showing
6 changed files
with
97 additions
and
43 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
36 changes: 36 additions & 0 deletions
36
featureflags/migrations/versions/2fa54f8b55c1_cleaup_condition_checks.py
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,36 @@ | ||
from alembic import op | ||
from sqlalchemy.sql import text | ||
|
||
revision = "2fa54f8b55c1" | ||
down_revision = "a327a3ea7a5f" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
conn = op.get_bind() | ||
|
||
conditions = list(conn.execute("SELECT id, checks FROM condition")) | ||
checks = list(conn.execute('SELECT id FROM "check"')) | ||
|
||
print("Found conditions: {}".format(len(conditions))) | ||
print("Found checks: {}".format(len(checks))) | ||
|
||
check_ids = {check.id for check in checks} | ||
|
||
for condition in conditions: | ||
new_checks = {check for check in condition.checks if check in check_ids} | ||
if set(condition.checks) != new_checks: | ||
print( | ||
"Updating condition {} with new checks: before={}, after={}".format( | ||
condition.id, condition.checks, new_checks | ||
) | ||
) | ||
|
||
conn.execute( | ||
text("UPDATE condition SET checks = :checks WHERE id = :id"), | ||
{"checks": list(new_checks), "id": condition.id}, | ||
) | ||
|
||
|
||
def downgrade(): ... |
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