diff --git a/app/models.py b/app/models.py index 1717225..4469777 100644 --- a/app/models.py +++ b/app/models.py @@ -508,7 +508,7 @@ class Tracks(Base): start_gap = Column(Integer, index=False) fade_at = Column(Integer, index=False) silence_at = Column(Integer, index=False) - path = Column(String(2048), index=False, nullable=False) + path = Column(String(2048), index=False, nullable=False, unique=True) mtime = Column(Float, index=True) playlistrows = relationship("PlaylistRows", back_populates="track") playlists = association_proxy("playlistrows", "playlist") diff --git a/migrations/versions/fe2e127b3332_don_t_allow_duplicate_track_paths.py b/migrations/versions/fe2e127b3332_don_t_allow_duplicate_track_paths.py new file mode 100644 index 0000000..4f515c3 --- /dev/null +++ b/migrations/versions/fe2e127b3332_don_t_allow_duplicate_track_paths.py @@ -0,0 +1,28 @@ +"""Don't allow duplicate track paths + +Revision ID: fe2e127b3332 +Revises: 0c604bf490f8 +Create Date: 2022-08-21 19:46:35.768659 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'fe2e127b3332' +down_revision = '0c604bf490f8' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_unique_constraint(None, 'tracks', ['path']) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint(None, 'tracks', type_='unique') + # ### end Alembic commands ###