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)