-
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.
Improve remove_project, add migration to cleanup condition.checks field
- Loading branch information
m.kindritskiy
committed
Dec 4, 2024
1 parent
e87c6c3
commit 11d2ab1
Showing
6 changed files
with
96 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
35 changes: 35 additions & 0 deletions
35
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,35 @@ | ||
from alembic import op | ||
|
||
|
||
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( | ||
"UPDATE condition SET checks = :checks WHERE id = :id", | ||
{"checks": 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