fixes unique constraint issues for archives containing the same url in archive_urls

This commit is contained in:
msramalho
2023-12-20 18:38:28 +00:00
parent cff6f713bd
commit c058bfd067
3 changed files with 56 additions and 1 deletions

View File

@@ -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")

View File

@@ -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"])

View File

@@ -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