DB fejl
This commit is contained in:
@@ -155,58 +155,47 @@ def push(
|
|||||||
|
|
||||||
# ── Sang-dans tags (brugerens egne) ───────────────────────────────────────
|
# ── Sang-dans tags (brugerens egne) ───────────────────────────────────────
|
||||||
from app.models import SongDance, SongAltDance
|
from app.models import SongDance, SongAltDance
|
||||||
# Slet eksisterende song_dances for disse sange og genindsæt
|
# ── Sang-dans tags ────────────────────────────────────────────────────────
|
||||||
affected_song_ids = set(
|
from app.models import SongDance, SongAltDance
|
||||||
song_id_map[sd.song_local_id]
|
import sqlalchemy as _sa
|
||||||
for sd in payload.song_dances
|
|
||||||
if sd.song_local_id in song_id_map
|
|
||||||
)
|
|
||||||
if affected_song_ids:
|
|
||||||
db.query(SongDance).filter(
|
|
||||||
SongDance.song_id.in_(affected_song_ids)
|
|
||||||
).delete(synchronize_session=False)
|
|
||||||
db.flush()
|
|
||||||
|
|
||||||
with db.no_autoflush:
|
for sd in payload.song_dances:
|
||||||
for sd in payload.song_dances:
|
song_id = song_id_map.get(sd.song_local_id)
|
||||||
song_id = song_id_map.get(sd.song_local_id)
|
if not song_id:
|
||||||
if not song_id:
|
continue
|
||||||
continue
|
level_id = level_map.get(sd.level_name.lower()) if sd.level_name else None
|
||||||
level_id = level_map.get(sd.level_name.lower()) if sd.level_name else None
|
key = f"{sd.dance_name.lower()}|{level_id}"
|
||||||
key = f"{sd.dance_name.lower()}|{level_id}"
|
dance_id = dance_id_map.get(key)
|
||||||
dance_id = dance_id_map.get(key)
|
if not dance_id:
|
||||||
if not dance_id:
|
continue
|
||||||
continue
|
db.execute(_sa.text(
|
||||||
db.add(SongDance(
|
"INSERT IGNORE INTO song_dances (id, song_id, dance_id, dance_order) "
|
||||||
song_id=song_id, dance_id=dance_id,
|
"VALUES (:id, :song_id, :dance_id, :dance_order)"
|
||||||
dance_order=sd.dance_order,
|
), {
|
||||||
))
|
"id": str(__import__("uuid").uuid4()),
|
||||||
|
"song_id": song_id,
|
||||||
|
"dance_id": dance_id,
|
||||||
|
"dance_order": sd.dance_order,
|
||||||
|
})
|
||||||
|
|
||||||
affected_alt_ids = set(
|
for sa in payload.song_alts:
|
||||||
song_id_map[sa.song_local_id]
|
song_id = song_id_map.get(sa.song_local_id)
|
||||||
for sa in payload.song_alts
|
if not song_id:
|
||||||
if sa.song_local_id in song_id_map
|
continue
|
||||||
)
|
level_id = level_map.get(sa.level_name.lower()) if sa.level_name else None
|
||||||
if affected_alt_ids:
|
key = f"{sa.dance_name.lower()}|{level_id}"
|
||||||
db.query(SongAltDance).filter(
|
dance_id = dance_id_map.get(key)
|
||||||
SongAltDance.song_id.in_(affected_alt_ids)
|
if not dance_id:
|
||||||
).delete(synchronize_session=False)
|
continue
|
||||||
db.flush()
|
db.execute(_sa.text(
|
||||||
|
"INSERT IGNORE INTO song_alt_dances (id, song_id, dance_id, note) "
|
||||||
with db.no_autoflush:
|
"VALUES (:id, :song_id, :dance_id, :note)"
|
||||||
for sa in payload.song_alts:
|
), {
|
||||||
song_id = song_id_map.get(sa.song_local_id)
|
"id": str(__import__("uuid").uuid4()),
|
||||||
if not song_id:
|
"song_id": song_id,
|
||||||
continue
|
"dance_id": dance_id,
|
||||||
level_id = level_map.get(sa.level_name.lower()) if sa.level_name else None
|
"note": sa.note or "",
|
||||||
key = f"{sa.dance_name.lower()}|{level_id}"
|
})
|
||||||
dance_id = dance_id_map.get(key)
|
|
||||||
if not dance_id:
|
|
||||||
continue
|
|
||||||
db.add(SongAltDance(
|
|
||||||
song_id=song_id, dance_id=dance_id,
|
|
||||||
note=sa.note,
|
|
||||||
))
|
|
||||||
|
|
||||||
# ── Playlister ────────────────────────────────────────────────────────────
|
# ── Playlister ────────────────────────────────────────────────────────────
|
||||||
playlist_id_map = {}
|
playlist_id_map = {}
|
||||||
|
|||||||
Reference in New Issue
Block a user