kemono2/db/migrations/20210529_01_LO1OU-add-primary-keys-to-discord-posts.py
2024-07-04 21:57:05 +02:00

22 lines
478 B
Python

"""
Add primary keys to discord_posts
"""
from yoyo import step
__depends__ = {"20210328_01_8tlz4-add-indexes-to-favorites-tables"}
steps = [
step(
"""
DELETE FROM discord_posts a
USING discord_posts b
WHERE a.ctid < b.ctid
AND a.id = b.id
AND a.server = b.server
AND a.channel = b.channel;
"""
),
step("ALTER TABLE discord_posts ADD PRIMARY KEY (id, server, channel); "),
]