mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-14 01:00:05 +08:00
make sure alembic migration works in both directions
This commit is contained in:
committed by
Andreas Köpf
parent
048802fa1a
commit
5f16a8f780
+38
-23
@@ -22,6 +22,7 @@ def upgrade() -> None:
|
||||
# clear DB
|
||||
op.execute("DELETE FROM journal;")
|
||||
op.execute("DELETE FROM work_package;")
|
||||
op.execute("DELETE FROM post_reaction;")
|
||||
op.execute("DELETE FROM post;")
|
||||
op.execute("DELETE FROM person_stats;")
|
||||
op.execute("DELETE FROM person;")
|
||||
@@ -175,24 +176,37 @@ def upgrade() -> None:
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# clear DB
|
||||
op.execute("DELETE FROM journal;")
|
||||
op.execute("DELETE FROM message_reaction;")
|
||||
op.execute("DELETE FROM task;")
|
||||
op.execute("DELETE FROM message;")
|
||||
op.execute("DELETE FROM user_stats;")
|
||||
op.execute('DELETE FROM "user";')
|
||||
op.execute("DELETE FROM text_labels;")
|
||||
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.add_column("text_labels", sa.Column("post_id", postgresql.UUID(), autoincrement=False, nullable=True))
|
||||
op.drop_constraint(None, "text_labels", type_="foreignkey")
|
||||
op.create_foreign_key("text_labels_post_id_fkey", "text_labels", "post", ["post_id"], ["id"])
|
||||
op.drop_constraint("text_labels_message_id_fkey", "text_labels", type_="foreignkey")
|
||||
|
||||
op.drop_column("text_labels", "message_id")
|
||||
op.add_column("journal", sa.Column("post_id", postgresql.UUID(), autoincrement=False, nullable=True))
|
||||
op.add_column("journal", sa.Column("person_id", postgresql.UUID(), autoincrement=False, nullable=True))
|
||||
op.drop_constraint(None, "journal", type_="foreignkey")
|
||||
op.drop_constraint(None, "journal", type_="foreignkey")
|
||||
op.create_foreign_key("journal_person_id_fkey", "journal", "person", ["person_id"], ["id"])
|
||||
op.create_foreign_key("journal_post_id_fkey", "journal", "post", ["post_id"], ["id"])
|
||||
op.drop_constraint("journal_message_id_fkey", "journal", type_="foreignkey")
|
||||
op.drop_constraint("journal_user_id_fkey", "journal", type_="foreignkey")
|
||||
|
||||
op.drop_index(op.f("ix_journal_user_id"), table_name="journal")
|
||||
op.create_index("ix_journal_person_id", "journal", ["person_id"], unique=False)
|
||||
op.drop_column("journal", "message_id")
|
||||
op.drop_column("journal", "user_id")
|
||||
|
||||
op.create_table(
|
||||
"post_reaction",
|
||||
sa.Column("person_id", postgresql.UUID(), autoincrement=False, nullable=False),
|
||||
"person",
|
||||
sa.Column(
|
||||
"id", postgresql.UUID(), server_default=sa.text("gen_random_uuid()"), autoincrement=False, nullable=False
|
||||
),
|
||||
sa.Column("username", sa.VARCHAR(length=128), autoincrement=False, nullable=False),
|
||||
sa.Column("display_name", sa.VARCHAR(length=256), autoincrement=False, nullable=False),
|
||||
sa.Column(
|
||||
"created_date",
|
||||
postgresql.TIMESTAMP(),
|
||||
@@ -200,13 +214,10 @@ def downgrade() -> None:
|
||||
autoincrement=False,
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("payload_type", sa.VARCHAR(length=200), autoincrement=False, nullable=False),
|
||||
sa.Column("payload", postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=False),
|
||||
sa.Column("api_client_id", postgresql.UUID(), autoincrement=False, nullable=False),
|
||||
sa.Column("work_package_id", postgresql.UUID(), autoincrement=False, nullable=False),
|
||||
sa.ForeignKeyConstraint(["api_client_id"], ["api_client.id"], name="post_reaction_api_client_id_fkey"),
|
||||
sa.ForeignKeyConstraint(["person_id"], ["person.id"], name="post_reaction_person_id_fkey"),
|
||||
sa.ForeignKeyConstraint(["work_package_id"], ["work_package.id"], name="post_reaction_work_package_id_fkey"),
|
||||
sa.Column("auth_method", sa.VARCHAR(length=128), autoincrement=False, nullable=False),
|
||||
sa.ForeignKeyConstraint(["api_client_id"], ["api_client.id"], name="person_api_client_id_fkey"),
|
||||
sa.PrimaryKeyConstraint("id", name="person_pkey"),
|
||||
)
|
||||
op.create_table(
|
||||
"person_stats",
|
||||
@@ -289,13 +300,10 @@ def downgrade() -> None:
|
||||
op.create_index("ix_post_thread_id", "post", ["thread_id"], unique=False)
|
||||
op.create_index("ix_post_person_id", "post", ["person_id"], unique=False)
|
||||
op.create_index("ix_post_frontend_post_id", "post", ["api_client_id", "frontend_post_id"], unique=False)
|
||||
|
||||
op.create_table(
|
||||
"person",
|
||||
sa.Column(
|
||||
"id", postgresql.UUID(), server_default=sa.text("gen_random_uuid()"), autoincrement=False, nullable=False
|
||||
),
|
||||
sa.Column("username", sa.VARCHAR(length=128), autoincrement=False, nullable=False),
|
||||
sa.Column("display_name", sa.VARCHAR(length=256), autoincrement=False, nullable=False),
|
||||
"post_reaction",
|
||||
sa.Column("person_id", postgresql.UUID(), autoincrement=False, nullable=False),
|
||||
sa.Column(
|
||||
"created_date",
|
||||
postgresql.TIMESTAMP(),
|
||||
@@ -303,13 +311,20 @@ def downgrade() -> None:
|
||||
autoincrement=False,
|
||||
nullable=False,
|
||||
),
|
||||
sa.Column("payload_type", sa.VARCHAR(length=200), autoincrement=False, nullable=False),
|
||||
sa.Column("payload", postgresql.JSONB(astext_type=sa.Text()), autoincrement=False, nullable=False),
|
||||
sa.Column("api_client_id", postgresql.UUID(), autoincrement=False, nullable=False),
|
||||
sa.Column("auth_method", sa.VARCHAR(length=128), autoincrement=False, nullable=False),
|
||||
sa.ForeignKeyConstraint(["api_client_id"], ["api_client.id"], name="person_api_client_id_fkey"),
|
||||
sa.PrimaryKeyConstraint("id", name="person_pkey"),
|
||||
sa.Column("work_package_id", postgresql.UUID(), autoincrement=False, nullable=False),
|
||||
sa.ForeignKeyConstraint(["api_client_id"], ["api_client.id"], name="post_reaction_api_client_id_fkey"),
|
||||
sa.ForeignKeyConstraint(["person_id"], ["person.id"], name="post_reaction_person_id_fkey"),
|
||||
sa.ForeignKeyConstraint(["work_package_id"], ["work_package.id"], name="post_reaction_work_package_id_fkey"),
|
||||
)
|
||||
|
||||
op.create_index("ix_person_username", "person", ["api_client_id", "username", "auth_method"], unique=False)
|
||||
op.create_foreign_key("text_labels_post_id_fkey", "text_labels", "post", ["post_id"], ["id"])
|
||||
op.create_foreign_key("journal_person_id_fkey", "journal", "person", ["person_id"], ["id"])
|
||||
op.create_foreign_key("journal_post_id_fkey", "journal", "post", ["post_id"], ["id"])
|
||||
|
||||
op.drop_table("message_reaction")
|
||||
op.drop_table("user_stats")
|
||||
op.drop_index(op.f("ix_task_user_id"), table_name="task")
|
||||
|
||||
Reference in New Issue
Block a user