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 = {}
|
song_map = {}
|
||||||
for s in songs_data:
|
for s in songs_data:
|
||||||
|
slug = generate_slug(s['name'])
|
||||||
# Check if song exists
|
# Check if song exists
|
||||||
existing = session.exec(
|
existing = session.exec(
|
||||||
select(Song).where(
|
select(Song).where(
|
||||||
|
or_(
|
||||||
Song.title == s['name'],
|
Song.title == s['name'],
|
||||||
|
Song.slug == slug
|
||||||
|
),
|
||||||
Song.vertical_id == vertical_id
|
Song.vertical_id == vertical_id
|
||||||
)
|
)
|
||||||
).first()
|
).first()
|
||||||
|
|
@ -178,7 +182,7 @@ def import_songs(session, vertical_id):
|
||||||
else:
|
else:
|
||||||
song = Song(
|
song = Song(
|
||||||
title=s['name'],
|
title=s['name'],
|
||||||
slug=generate_slug(s['name']),
|
slug=slug,
|
||||||
original_artist=s.get('original_artist'),
|
original_artist=s.get('original_artist'),
|
||||||
vertical_id=vertical_id
|
vertical_id=vertical_id
|
||||||
# API doesn't include debut_date or times_played in base response
|
# 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.get('tour_id') and s['tour_id'] != 1: # 1 = "Not Part of a Tour"
|
||||||
if s['tour_id'] not in tour_map:
|
if s['tour_id'] not in tour_map:
|
||||||
# Check if tour exists
|
# Check if tour exists
|
||||||
|
slug = generate_slug(s['tourname'])
|
||||||
existing_tour = session.exec(
|
existing_tour = session.exec(
|
||||||
select(Tour).where(Tour.name == s['tourname'])
|
select(Tour).where(
|
||||||
|
or_(
|
||||||
|
Tour.name == s['tourname'],
|
||||||
|
Tour.slug == slug
|
||||||
|
)
|
||||||
|
)
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
if existing_tour:
|
if existing_tour:
|
||||||
|
|
@ -226,7 +236,7 @@ def import_shows(session, vertical_id, venue_map):
|
||||||
else:
|
else:
|
||||||
tour = Tour(
|
tour = Tour(
|
||||||
name=s['tourname'],
|
name=s['tourname'],
|
||||||
slug=generate_slug(s['tourname'])
|
slug=slug
|
||||||
)
|
)
|
||||||
session.add(tour)
|
session.add(tour)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue