Move scrobble ownership to associative tables in db

This commit is contained in:
mitteneer 2025-03-28 17:07:12 -04:00
parent 29f8837f19
commit 9760ca7fbc
3 changed files with 11 additions and 8 deletions

View file

@ -15,7 +15,7 @@ pub const database = .{
.port = 5432,
.username = "postgres",
.password = "postgres",
.database = "zuletzt_dev",
.database = "zuletzt_aos_dev",
.pool_size = 16,
},

View file

@ -13,7 +13,6 @@ pub const Album = jetquery.Model(
.{
.relations = .{
.masteralbum = jetquery.belongsTo(.Masteralbum, .{}),
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
.ratings = jetquery.hasMany(.Rating, .{}),
.aliases = jetquery.hasMany(.Alias, .{}),
.albumsongs = jetquery.hasMany(.Albumsong, .{}),
@ -114,8 +113,9 @@ pub const Scrobble = jetquery.Model(
"scrobbles",
struct {
id: i32,
song_id: i32,
album_id: i32,
albumartists_id: i32,
songsartists_id: i32,
albumsongs_id: i32,
date: jetquery.DateTime,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
@ -124,7 +124,7 @@ pub const Scrobble = jetquery.Model(
.relations = .{
.song = jetquery.belongsTo(.Song, .{}),
.album = jetquery.belongsTo(.Album, .{}),
.scrobbleartists = jetquery.hasMany(.Scrobbleartist, .{}),
//.scrobbleartists = jetquery.hasMany(.Scrobbleartist, .{}),
},
},
);
@ -143,7 +143,6 @@ pub const Song = jetquery.Model(
.{
.relations = .{
.mastersong = jetquery.belongsTo(.Mastersong, .{}),
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
.ratings = jetquery.hasMany(.Rating, .{}),
.aliases = jetquery.hasMany(.Alias, .{}),
.songartists = jetquery.hasMany(.Songartist, .{}),
@ -166,6 +165,7 @@ pub const Albumartist = jetquery.Model(
.relations = .{
.album = jetquery.belongsTo(.Album, .{}),
.artist = jetquery.belongsTo(.Artist, .{}),
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
},
},
);
@ -184,6 +184,7 @@ pub const Songartist = jetquery.Model(
.relations = .{
.song = jetquery.belongsTo(.Song, .{}),
.artist = jetquery.belongsTo(.Artist, .{}),
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
},
},
);
@ -202,6 +203,7 @@ pub const Albumsong = jetquery.Model(
.relations = .{
.album = jetquery.belongsTo(.Album, .{}),
.song = jetquery.belongsTo(.Song, .{}),
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
},
},
);

View file

@ -7,8 +7,9 @@ pub fn up(repo: anytype) !void {
"scrobbles",
&.{
t.primaryKey("id", .{}),
t.column("song_id", .integer, .{}),
t.column("album_id", .integer, .{}),
t.column("albumartists_id", .integer, .{}),
t.column("songsartists_id", .integer, .{}),
t.column("albumsongs_id", .integer, .{}),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},