kopia lustrzana https://github.com/bugout-dev/moonstream
Modified alembic migration to downgrade properly
Previously, the downgrade was hitting a violation of the old unique constraint on leaderboard_scores if multiple versions of scores were stored for the same address. The modified downgrade only retains the score for each address on the latest publich version of each leaderboard.pull/966/head
rodzic
de2afed559
commit
71e2ffbed3
|
@ -105,6 +105,23 @@ def upgrade():
|
|||
|
||||
|
||||
def downgrade():
|
||||
op.execute(
|
||||
"""
|
||||
WITH latest_version_for_leaderboard AS (
|
||||
SELECT leaderboard_id, MAX(version_number) AS latest_version
|
||||
FROM leaderboard_versions WHERE published = true
|
||||
GROUP BY leaderboard_id
|
||||
)
|
||||
DELETE FROM leaderboard_scores WHERE
|
||||
(leaderboard_id, leaderboard_version_number) NOT IN (
|
||||
SELECT
|
||||
leaderboard_id,
|
||||
latest_version AS leaderboard_version_number
|
||||
FROM
|
||||
latest_version_for_leaderboard
|
||||
)
|
||||
"""
|
||||
)
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(
|
||||
op.f("fk_leaderboard_scores_leaderboard_id_leaderboard_versions"),
|
||||
|
|
Ładowanie…
Reference in New Issue