From d9f4021342c3114a676c60a167196be38596536d Mon Sep 17 00:00:00 2001 From: krateng Date: Tue, 15 Feb 2022 04:45:42 +0100 Subject: [PATCH] Fixed duplicate artist association rules --- maloja/database/associated.py | 2 +- maloja/database/sqldb.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/maloja/database/associated.py b/maloja/database/associated.py index f486cef..d3f233d 100644 --- a/maloja/database/associated.py +++ b/maloja/database/associated.py @@ -27,7 +27,7 @@ def load_associated_rules(): # write to db ops = [ - sqldb.DB['associated_artists'].insert().values(**r) + sqldb.DB['associated_artists'].insert().values(**r).prefix_with('OR IGNORE') for r in rules ] diff --git a/maloja/database/sqldb.py b/maloja/database/sqldb.py index b3817d2..c961e28 100644 --- a/maloja/database/sqldb.py +++ b/maloja/database/sqldb.py @@ -47,7 +47,8 @@ DB['trackartists'] = sql.Table( DB['associated_artists'] = sql.Table( 'associated_artists', meta, sql.Column('source_artist',sql.Integer,sql.ForeignKey('artists.id')), - sql.Column('target_artist',sql.Integer,sql.ForeignKey('artists.id')) + sql.Column('target_artist',sql.Integer,sql.ForeignKey('artists.id')), + sql.UniqueConstraint('source_artist', 'target_artist') ) meta.create_all(engine)