Skip to content

Commit

Permalink
Fix update ordering regression
Browse files Browse the repository at this point in the history
  • Loading branch information
jamespfennell committed Mar 21, 2020
1 parent 57f17a8 commit e3f9740
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 92 deletions.
2 changes: 1 addition & 1 deletion tests/endtoend/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def delete():
time.sleep(0.6)
assert response.json()["status"] == expected_status

# request.addfinalizer(delete)
request.addfinalizer(delete)

return install

Expand Down
112 changes: 22 additions & 90 deletions transiter/alembic/versions/b521e2a9055a_feed_update_auditing.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,26 @@


def upgrade():
# (1) Remove indices
op.drop_index("feed_updates_last_successful_idx", table_name="feed_update")
op.drop_index("ix_feed_update_last_action_time", table_name="feed_update")

# (2) Remove existing columns
op.drop_column("feed_update", "failure_message")
op.drop_column("feed_update", "execution_duration")
op.drop_column("feed_update", "feed_time")
op.drop_column("feed_update", "explanation")
op.drop_column("feed_update", "raw_data_hash")

# (3) Rename last_action_time to completed_at
op.alter_column(
"feed_update",
"last_action_time",
new_column_name="completed_at",
server_default=None,
)

# (4) Add new columns
op.add_column(
"feed_update",
sa.Column("content_created_at", sa.TIMESTAMP(timezone=True), nullable=True),
Expand Down Expand Up @@ -60,103 +78,17 @@ def upgrade():
sa.Column("scheduled_at", sa.TIMESTAMP(timezone=True), nullable=True),
)
op.add_column("feed_update", sa.Column("total_duration", sa.Float(), nullable=True))
op.alter_column(
"feed_update",
"last_action_time",
new_column_name="completed_at",
server_default=None,
)

# (5) Add multi-column indices
op.create_index(
"feed_update_success_pk_completed_at_idx",
"feed_update",
["feed_pk", "completed_at"],
unique=False,
postgresql_where=sa.text("status = 'SUCCESS'"),
)
op.drop_column("feed_update", "failure_message")
op.drop_column("feed_update", "execution_duration")
op.drop_column("feed_update", "feed_time")
op.drop_column("feed_update", "explanation")
op.drop_column("feed_update", "raw_data_hash")
op.create_index('feed_update_feed_pk_feed_update_pk_idx', 'feed_update', ['feed_pk', 'pk'], unique=False)


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"feed_update",
sa.Column("raw_data_hash", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.add_column(
"feed_update",
sa.Column(
"explanation",
postgresql.ENUM(
"UPDATED",
"NOT_NEEDED",
"PARSE_ERROR",
"DOWNLOAD_ERROR",
"INVALID_PARSER",
"EMPTY_FEED",
"SYNC_ERROR",
"UNEXPECTED_ERROR",
name="explanation",
),
autoincrement=False,
nullable=True,
),
)
op.add_column(
"feed_update",
sa.Column(
"last_action_time",
postgresql.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
autoincrement=False,
nullable=True,
),
)
op.add_column(
"feed_update",
sa.Column(
"feed_time",
postgresql.TIMESTAMP(timezone=True),
autoincrement=False,
nullable=True,
),
)
op.add_column(
"feed_update",
sa.Column(
"execution_duration",
postgresql.DOUBLE_PRECISION(precision=53),
autoincrement=False,
nullable=True,
),
)
op.add_column(
"feed_update",
sa.Column("failure_message", sa.VARCHAR(), autoincrement=False, nullable=True),
)
op.create_index(
"ix_feed_update_last_action_time",
"feed_update",
["last_action_time"],
unique=False,
)
op.create_index(
"feed_updates_last_successful_idx",
"feed_update",
["feed_pk", "last_action_time", "status"],
unique=False,
)
op.drop_index("feed_update_success_pk_completed_at_idx", table_name="feed_update")
op.drop_column("feed_update", "total_duration")
op.drop_column("feed_update", "scheduled_at")
op.drop_column("feed_update", "result_message")
op.drop_column("feed_update", "num_synced_entities")
op.drop_column("feed_update", "num_parsed_entities")
op.drop_column("feed_update", "feed_update_result")
op.drop_column("feed_update", "download_duration")
op.drop_column("feed_update", "content_hash")
op.drop_column("feed_update", "content_created_at")
op.drop_column("feed_update", "completed_at")
pass
2 changes: 1 addition & 1 deletion transiter/data/dams/feeddam.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def list_updates_in_feed(feed_pk):
query = (
session.query(models.FeedUpdate)
.filter(models.FeedUpdate.feed_pk == feed_pk)
.order_by(models.FeedUpdate.completed_at.desc())
.order_by(models.FeedUpdate.pk.desc())
.limit(100)
)
return query.all()
Expand Down
5 changes: 5 additions & 0 deletions transiter/models/feedupdate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class Result(enum.Enum):
completed_at,
postgresql_where=(status == Status.SUCCESS),
),
Index(
"feed_update_feed_pk_feed_update_pk_idx",
feed_pk,
pk
),
)

__dict_columns__ = [
Expand Down

0 comments on commit e3f9740

Please sign in to comment.