feat(models): Tag.__table_args__ matches j26042101 indices

Drop unique=True on Tag.name (the migration replaced UNIQUE(name) with
four partial indices). Declare the partial indices in __table_args__ so
Alembic autogenerate stops seeing drift on future schema changes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-22 11:08:24 -04:00
parent c7e2605a10
commit 97ad60b973
+20 -1
View File
@@ -42,8 +42,27 @@ class ImageRecord(db.Model):
)
class Tag(db.Model):
__table_args__ = (
db.Index(
'tag_character_with_fandom_uniq', 'name', 'fandom_id',
unique=True,
postgresql_where=db.text("kind = 'character' AND fandom_id IS NOT NULL"),
),
db.Index(
'tag_character_null_fandom_uniq', 'name',
unique=True,
postgresql_where=db.text("kind = 'character' AND fandom_id IS NULL"),
),
db.Index(
'tag_other_kinds_uniq', 'name', 'kind',
unique=True,
postgresql_where=db.text("kind != 'character'"),
),
db.Index('tag_kind_idx', 'kind'),
)
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(255), unique=True, nullable=False)
name = db.Column(db.String(255), nullable=False)
kind = db.Column(db.String(64), nullable=True)
fandom_id = db.Column(db.Integer, db.ForeignKey("tag.id", ondelete="SET NULL"), nullable=True)
fandom = db.relationship("Tag", remote_side="Tag.id", foreign_keys=[fandom_id])