diff --git a/src/db/models.py b/src/db/models.py index 9cddc7f..604bbcc 100644 --- a/src/db/models.py +++ b/src/db/models.py @@ -45,8 +45,8 @@ class ArchiveUrl(Base): __tablename__ = "archive_urls" url = Column(String, primary_key=True, index=True) + archive_id = Column(String, ForeignKey("archives.id"), primary_key=True) key = Column(String, default=None) - archive_id = Column(String, ForeignKey("archives.id")) archive = relationship("Archive", back_populates="urls") diff --git a/src/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py b/src/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py new file mode 100644 index 0000000..a2b708a --- /dev/null +++ b/src/migrations/versions/9369a264945b_modify_archive_url_to_have_uuid_id_.py @@ -0,0 +1,27 @@ +"""modify archive url to have uuid id instead of url unique constraint + +Revision ID: 9369a264945b +Revises: +Create Date: 2023-12-20 17:24:59.320691 + +""" +from alembic import op + +# revision identifiers, used by Alembic. +revision = '9369a264945b' +down_revision = None +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # since the primary key constraint is not named, we have to recreate it first + with op.batch_alter_table("archive_urls") as batch_op: + batch_op.create_primary_key("pk_url", ["url"]) + batch_op.drop_constraint("pk_url", type_='primary') + batch_op.create_primary_key("pk_url_archive_id", ["url", "archive_id"]) + +def downgrade() -> None: + with op.batch_alter_table("archive_urls") as batch_op: + batch_op.drop_constraint("pk_url_archive_id", type_='primary') + batch_op.create_primary_key("url", ["url"]) diff --git a/src/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py b/src/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py new file mode 100644 index 0000000..6b8d8d2 --- /dev/null +++ b/src/migrations/versions/93a611e4c066_vacuum_database_if_there_s_enough_space.py @@ -0,0 +1,28 @@ +"""vacuum database (if there's enough space) + +Revision ID: 93a611e4c066 +Revises: 9369a264945b +Create Date: 2023-12-20 18:33:27.132566 + +""" +from alembic import op + + +# revision identifiers, used by Alembic. +revision = '93a611e4c066' +down_revision = '9369a264945b' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + try: + with op.get_context().autocommit_block(): + op.execute("VACUUM") + except Exception as e: + print("Unable to run vacuum, maybe there's not enough disk space. it should be 2x the size of the database") + print(e) + + +def downgrade() -> None: + pass