feat: monitoring data model (WatchedArtist, MonitoredRelease, Request link)
This commit is contained in:
@@ -12,6 +12,8 @@ def conn():
|
||||
with connection.cursor() as cur:
|
||||
cur.execute('DELETE FROM "Job"')
|
||||
cur.execute('DELETE FROM "Request"')
|
||||
cur.execute('DELETE FROM "MonitoredRelease"')
|
||||
cur.execute('DELETE FROM "WatchedArtist"')
|
||||
cur.execute('DELETE FROM "Config"')
|
||||
connection.commit()
|
||||
yield connection
|
||||
@@ -19,6 +21,8 @@ def conn():
|
||||
with connection.cursor() as cur:
|
||||
cur.execute('DELETE FROM "Job"')
|
||||
cur.execute('DELETE FROM "Request"')
|
||||
cur.execute('DELETE FROM "MonitoredRelease"')
|
||||
cur.execute('DELETE FROM "WatchedArtist"')
|
||||
cur.execute('DELETE FROM "Config"')
|
||||
connection.commit()
|
||||
connection.close()
|
||||
@@ -41,3 +45,41 @@ def insert_request(conn, artist="Artist", album="Album"):
|
||||
job_id = cur.fetchone()[0]
|
||||
conn.commit()
|
||||
return job_id
|
||||
|
||||
|
||||
def insert_watched_artist(conn, mbid="mbid", name="Artist", auto_monitor_future=False,
|
||||
monitor_from_sql="now()", last_polled_sql="NULL"):
|
||||
"""Insert a WatchedArtist; monitor_from_sql / last_polled_sql are raw SQL time expressions."""
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
'INSERT INTO "WatchedArtist" (id, mbid, name, "autoMonitorFuture", '
|
||||
f'"monitorFrom", "lastPolledAt", "createdAt") '
|
||||
f"VALUES (gen_random_uuid()::text, %s, %s, %s, {monitor_from_sql}, {last_polled_sql}, now()) "
|
||||
"RETURNING id",
|
||||
(mbid, name, auto_monitor_future),
|
||||
)
|
||||
artist_id = cur.fetchone()[0]
|
||||
conn.commit()
|
||||
return artist_id
|
||||
|
||||
|
||||
def insert_monitored_release(conn, watched_artist_id=None, artist_mbid="mbid", artist_name="Artist",
|
||||
rg_mbid="rg", album="Album", primary_type=None, secondary_types=None,
|
||||
first_release_date=None, monitored=False, state="wanted",
|
||||
current_quality_class=None, first_grabbed_sql="NULL",
|
||||
last_searched_sql="NULL"):
|
||||
"""Insert a MonitoredRelease; *_sql args are raw SQL time expressions."""
|
||||
with conn.cursor() as cur:
|
||||
cur.execute(
|
||||
'INSERT INTO "MonitoredRelease" (id, "watchedArtistId", "artistMbid", "artistName", '
|
||||
'"rgMbid", album, "primaryType", "secondaryTypes", "firstReleaseDate", monitored, '
|
||||
f'state, "currentQualityClass", "firstGrabbedAt", "lastSearchedAt", "createdAt") '
|
||||
f"VALUES (gen_random_uuid()::text, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, "
|
||||
f"{first_grabbed_sql}, {last_searched_sql}, now()) RETURNING id",
|
||||
(watched_artist_id, artist_mbid, artist_name, rg_mbid, album, primary_type,
|
||||
secondary_types if secondary_types is not None else [], first_release_date,
|
||||
monitored, state, current_quality_class),
|
||||
)
|
||||
rel_id = cur.fetchone()[0]
|
||||
conn.commit()
|
||||
return rel_id
|
||||
|
||||
Reference in New Issue
Block a user