diff --git a/app/models/packages.py b/app/models/packages.py index 4cf6683e..f6fa0a48 100644 --- a/app/models/packages.py +++ b/app/models/packages.py @@ -365,6 +365,8 @@ class Package(db.Model): search_vector = db.Column(TSVectorType("name", "title", "short_desc", "desc", weights={ "name": "A", "title": "B", "short_desc": "C" })) + __table_args__ = (db.UniqueConstraint("author_id", "name", name="_package_uc"),) + license_id = db.Column(db.Integer, db.ForeignKey("license.id"), nullable=False, default=1) license = db.relationship("License", foreign_keys=[license_id]) media_license_id = db.Column(db.Integer, db.ForeignKey("license.id"), nullable=False, default=1) diff --git a/migrations/versions/49105d276908_.py b/migrations/versions/49105d276908_.py new file mode 100644 index 00000000..84de4a8d --- /dev/null +++ b/migrations/versions/49105d276908_.py @@ -0,0 +1,26 @@ +"""empty message + +Revision ID: 49105d276908 +Revises: 7a749a6c8c3a +Create Date: 2023-10-01 23:25:24.870407 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '49105d276908' +down_revision = '7a749a6c8c3a' +branch_labels = None +depends_on = None + + +def upgrade(): + with op.batch_alter_table('package', schema=None) as batch_op: + batch_op.create_unique_constraint('_package_uc', ['author_id', 'name']) + + +def downgrade(): + with op.batch_alter_table('package', schema=None) as batch_op: + batch_op.drop_constraint('_package_uc', type_='unique')