"""A library can hold articles as well as questions. Collections were questions only, so the reading side of the site had no way to put anything aside — the bookmark on an article had nowhere to write. Its own table rather than a nullable column beside `question_id`, so a row cannot claim to be both kinds or neither. Revision ID: c5d6e7f8091a Revises: b4c5d6e7f809 """ import sqlalchemy as sa from alembic import op revision = "c5d6e7f8091a" down_revision = "b4c5d6e7f809" branch_labels = None depends_on = None def upgrade(): # `Base.metadata.create_all()` still runs at startup and creates missing # tables, so on a box that has already booted this code the table is here # before the migration is. Checked rather than assumed, or the upgrade # fails on exactly the machines that are up to date. if "user_collection_articles" in sa.inspect(op.get_bind()).get_table_names(): return op.create_table( "user_collection_articles", sa.Column("id", sa.Integer(), primary_key=True, index=True), sa.Column("collection_id", sa.Integer(), sa.ForeignKey("user_collections.id", ondelete="CASCADE"), nullable=False), sa.Column("article_id", sa.Integer(), sa.ForeignKey("articles.id", ondelete="CASCADE"), nullable=False), sa.UniqueConstraint("collection_id", "article_id", name="uq_collection_article"), ) op.create_index("ix_user_collection_articles_collection", "user_collection_articles", ["collection_id"]) def downgrade(): if "user_collection_articles" not in sa.inspect(op.get_bind()).get_table_names(): return op.drop_index("ix_user_collection_articles_collection", table_name="user_collection_articles") op.drop_table("user_collection_articles")