Skip to content

Commit

Permalink
Merge 78c1068 into ab677ab
Browse files Browse the repository at this point in the history
  • Loading branch information
dianaclarke committed Apr 21, 2021
2 parents ab677ab + 78c1068 commit 7dce8ff
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
78 changes: 78 additions & 0 deletions conbench/tests/migrations/test_662175f2e6c6_backfill_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import datetime
import os

from alembic import command
from alembic.config import Config

from ...db import Session
from ...entities.commit import Commit


this_dir = os.path.abspath(os.path.dirname(__file__))
config_path = os.path.join(this_dir, "../../../alembic.ini")


def test_upgrade():
repository = "https://github.com/apache/arrow"
github = {
"parent": "4beb514d071c9beec69b8917b5265e77ade22fb3",
"message": "ARROW-12429: [C++] Fix incorrectly registered test",
"date": datetime.datetime(2021, 4, 17, 14, 25, 26),
"author_name": "David Li",
"author_login": "lidavidm",
"author_avatar": "https://avatars.githubusercontent.com/u/327919?v=4",
}
commit_1 = Commit.create(
{
"sha": "fdd6ab11a71d4c40b4d24afa8458fed3d4589980",
"repository": repository,
"timestamp": github["date"],
"message": github["message"],
"author_name": github["author_name"],
"author_login": github["author_login"],
"author_avatar": github["author_avatar"],
}
)
github = {
"parent": "66aa3e7c365a8d4c4eca6e23668f2988e714b493",
"message": "ARROW-12421: [Rust] [DataFusion] Disable repartition rule",
"date": datetime.datetime(2021, 4, 16, 17, 14, 16),
"author_name": "Andy Grove",
"author_login": "andygrove",
"author_avatar": "https://avatars.githubusercontent.com/u/934084?v=4",
}
commit_2 = Commit.create(
{
"sha": "9c1e5bd19347635ea9f373bcf93f2cea0231d50a",
"repository": repository,
"parent": github["parent"],
"timestamp": github["date"],
"message": github["message"],
"author_name": github["author_name"],
"author_login": github["author_login"],
"author_avatar": github["author_avatar"],
}
)

# assert before migration
assert commit_1.sha == "fdd6ab11a71d4c40b4d24afa8458fed3d4589980"
assert commit_1.parent is None
assert commit_1.author_name == "David Li"
assert commit_2.sha == "9c1e5bd19347635ea9f373bcf93f2cea0231d50a"
assert commit_2.parent == "66aa3e7c365a8d4c4eca6e23668f2988e714b493"
assert commit_2.author_name == "Andy Grove"

alembic_config = Config(config_path)
command.stamp(alembic_config, "782f4533db71")
command.upgrade(alembic_config, "662175f2e6c6")

Session.refresh(commit_1)
Session.refresh(commit_2)

# assert after migration
assert commit_1.sha == "fdd6ab11a71d4c40b4d24afa8458fed3d4589980"
assert commit_1.parent == "9c1e5bd19347635ea9f373bcf93f2cea0231d50a"
assert commit_1.author_name == "David Li"
assert commit_2.sha == "9c1e5bd19347635ea9f373bcf93f2cea0231d50a"
assert commit_2.parent == "66aa3e7c365a8d4c4eca6e23668f2988e714b493"
assert commit_2.author_name == "Andy Grove"
41 changes: 41 additions & 0 deletions migrations/versions/662175f2e6c6_backfill_parent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""backfill parent
Revision ID: 662175f2e6c6
Revises: 782f4533db71
Create Date: 2021-04-21 09:23:28.589522
"""
from alembic import op
import requests


from conbench.entities.commit import Commit


# revision identifiers, used by Alembic.
revision = "662175f2e6c6"
down_revision = "782f4533db71"
branch_labels = None
depends_on = None


def upgrade():
commit_table = Commit.__table__
connection = op.get_bind()

commits = connection.execute(
commit_table.select().where(commit_table.c.parent == None) # noqa
)
for commit in commits:
url = f"https://api.github.com/repos/apache/arrow/commits/{commit.sha}"
response = requests.get(url)
parent = response.json()["parents"][0]["sha"]
connection.execute(
commit_table.update()
.where(commit_table.c.sha == commit.sha)
.values(parent=parent)
)


def downgrade():
pass

0 comments on commit 7dce8ff

Please sign in to comment.