Skip to content

Commit 36c8bce

Browse files
committed
Migration to create the ModerationLog table
1 parent a0f47d4 commit 36c8bce

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Create the moderation log table."""
2+
3+
import sqlalchemy as sa
4+
from alembic import op
5+
from sqlalchemy.dialects import postgresql
6+
7+
from h.db.types import URLSafeUUID
8+
9+
revision = "2aacaede8542"
10+
down_revision = "bd0cc0e6ed54"
11+
12+
13+
def upgrade() -> None:
14+
moderation_status_type = postgresql.ENUM(
15+
name="moderationstatus",
16+
create_type=False,
17+
)
18+
19+
op.create_table(
20+
"moderation_log",
21+
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
22+
sa.Column("moderator_id", sa.Integer(), nullable=False),
23+
sa.Column("annotation_id", URLSafeUUID(), nullable=False),
24+
sa.Column("old_moderation_status", moderation_status_type, nullable=True),
25+
sa.Column("new_moderation_status", moderation_status_type, nullable=False),
26+
sa.Column(
27+
"created", sa.DateTime(), server_default=sa.text("now()"), nullable=False
28+
),
29+
sa.ForeignKeyConstraint(
30+
["annotation_id"],
31+
["annotation.id"],
32+
name=op.f("fk__moderation_log__annotation_id__annotation"),
33+
ondelete="CASCADE",
34+
),
35+
sa.ForeignKeyConstraint(
36+
["moderator_id"],
37+
["user.id"],
38+
name=op.f("fk__moderation_log__moderator_id_user"),
39+
ondelete="CASCADE",
40+
),
41+
sa.PrimaryKeyConstraint("id", name=op.f("pk__moderation_log")),
42+
)
43+
op.create_index(
44+
op.f("ix__moderation_log_annotation_id"),
45+
"moderation_log",
46+
["annotation_id"],
47+
unique=False,
48+
)
49+
50+
51+
def downgrade() -> None:
52+
op.drop_index(op.f("ix__moderation_log_annotation_id"), table_name="moderation_log")
53+
op.drop_table("moderation_log")

0 commit comments

Comments
 (0)