-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23e3696
commit a26bf57
Showing
1 changed file
with
55 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Backfill commit id | ||
Revision ID: c181484ce40f | ||
Revises: dc0ed346df63 | ||
Create Date: 2021-07-29 08:13:59.714930 | ||
""" | ||
from alembic import op | ||
from sqlalchemy import MetaData | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = "c181484ce40f" | ||
down_revision = "dc0ed346df63" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
connection = op.get_bind() | ||
meta = MetaData() | ||
meta.reflect(bind=connection) | ||
|
||
commit_table = meta.tables["commit"] | ||
distribution_table = meta.tables["distribution"] | ||
|
||
commits = connection.execute(commit_table.select()) | ||
distributions = connection.execute(distribution_table.select()) | ||
commits_by_sha = {c["sha"]: c for c in commits} | ||
|
||
i = 1 | ||
|
||
for distribution in distributions: | ||
if distribution.commit_id: | ||
continue | ||
|
||
commit = commits_by_sha.get(distribution["sha"]) | ||
if not commit: | ||
print(f"Could not find commit for distribution {distribution.id}") | ||
continue | ||
|
||
connection.execute( | ||
distribution_table.update() | ||
.where(distribution_table.c.id == distribution.sha) | ||
.values(commit_id=commit.id) | ||
) | ||
|
||
print(f"Updated distribution {1}") | ||
i += 1 | ||
|
||
print("Done with migration") | ||
|
||
|
||
def downgrade(): | ||
pass |