fix(backend): Handle duplicates in songs and tours imports
Some checks failed
Deploy Fediversion / deploy (push) Failing after 1s
Some checks failed
Deploy Fediversion / deploy (push) Failing after 1s
This commit is contained in:
parent
be5921b6ee
commit
dd5d513534
1 changed files with 14 additions and 4 deletions
|
|
@ -165,10 +165,14 @@ def import_songs(session, vertical_id):
|
|||
|
||||
song_map = {}
|
||||
for s in songs_data:
|
||||
slug = generate_slug(s['name'])
|
||||
# Check if song exists
|
||||
existing = session.exec(
|
||||
select(Song).where(
|
||||
or_(
|
||||
Song.title == s['name'],
|
||||
Song.slug == slug
|
||||
),
|
||||
Song.vertical_id == vertical_id
|
||||
)
|
||||
).first()
|
||||
|
|
@ -178,7 +182,7 @@ def import_songs(session, vertical_id):
|
|||
else:
|
||||
song = Song(
|
||||
title=s['name'],
|
||||
slug=generate_slug(s['name']),
|
||||
slug=slug,
|
||||
original_artist=s.get('original_artist'),
|
||||
vertical_id=vertical_id
|
||||
# API doesn't include debut_date or times_played in base response
|
||||
|
|
@ -217,8 +221,14 @@ def import_shows(session, vertical_id, venue_map):
|
|||
if s.get('tour_id') and s['tour_id'] != 1: # 1 = "Not Part of a Tour"
|
||||
if s['tour_id'] not in tour_map:
|
||||
# Check if tour exists
|
||||
slug = generate_slug(s['tourname'])
|
||||
existing_tour = session.exec(
|
||||
select(Tour).where(Tour.name == s['tourname'])
|
||||
select(Tour).where(
|
||||
or_(
|
||||
Tour.name == s['tourname'],
|
||||
Tour.slug == slug
|
||||
)
|
||||
)
|
||||
).first()
|
||||
|
||||
if existing_tour:
|
||||
|
|
@ -226,7 +236,7 @@ def import_shows(session, vertical_id, venue_map):
|
|||
else:
|
||||
tour = Tour(
|
||||
name=s['tourname'],
|
||||
slug=generate_slug(s['tourname'])
|
||||
slug=slug
|
||||
)
|
||||
session.add(tour)
|
||||
session.commit()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue