diff --git a/src/app/database/Schema.zig b/src/app/database/Schema.zig index eeec984..0a30a19 100644 --- a/src/app/database/Schema.zig +++ b/src/app/database/Schema.zig @@ -4,7 +4,7 @@ pub const Album = jetquery.Model( @This(), "albums", struct { - id: i32, + id: i64, name: []const u8, length: ?f32, created_at: jetquery.DateTime, @@ -22,9 +22,9 @@ pub const Albumsong = jetquery.Model( @This(), "albumsongs", struct { - id: i32, - song_id: i32, - album_id: i32, + id: i64, + song_id: i64, + album_id: i64, created_at: jetquery.DateTime, updated_at: jetquery.DateTime, }, @@ -32,9 +32,7 @@ pub const Albumsong = jetquery.Model( .relations = .{ .song = jetquery.belongsTo(.Song, .{}), .album = jetquery.belongsTo(.Album, .{}), - .scrobbles = jetquery.hasMany(.Scrobble, .{ - .foreign_key = "albumsong", - }), + .scrobbles = jetquery.hasMany(.Scrobble, .{ .foreign_key = "albumsong" }), .albumsongsartists = jetquery.hasMany(.Albumsongsartist, .{}), }, }, @@ -44,9 +42,9 @@ pub const Albumsongsartist = jetquery.Model( @This(), "albumsongsartists", struct { - id: i32, - albumsong_id: i32, - artist_id: i32, + id: i64, + albumsong_id: i64, + artist_id: i64, created_at: jetquery.DateTime, updated_at: jetquery.DateTime, }, @@ -62,9 +60,9 @@ pub const Artistalbum = jetquery.Model( @This(), "artistalbums", struct { - id: i32, - album_id: i32, - artist_id: i32, + id: i64, + album_id: i64, + artist_id: i64, created_at: jetquery.DateTime, updated_at: jetquery.DateTime, }, @@ -80,7 +78,7 @@ pub const Artist = jetquery.Model( @This(), "artists", struct { - id: i32, + id: i64, name: []const u8, disambiguation: ?[]const u8, created_at: jetquery.DateTime, @@ -90,6 +88,7 @@ pub const Artist = jetquery.Model( .relations = .{ .albumsongsartists = jetquery.hasMany(.Albumsongsartist, .{}), .artistalbums = jetquery.hasMany(.Artistalbum, .{}), + .artistsongs = jetquery.hasMany(.Artistsong, .{}), }, }, ); @@ -98,17 +97,15 @@ pub const Scrobble = jetquery.Model( @This(), "scrobbles", struct { - id: i32, - albumsong: i32, + id: i64, + albumsong: i64, datetime: jetquery.DateTime, created_at: jetquery.DateTime, updated_at: jetquery.DateTime, }, .{ .relations = .{ - .albumsong = jetquery.belongsTo(.Albumsong, .{ - .foreign_key = "albumsong", - }), + .albumsong = jetquery.belongsTo(.Albumsong, .{ .foreign_key = "albumsong" }), }, }, ); @@ -117,7 +114,7 @@ pub const Song = jetquery.Model( @This(), "songs", struct { - id: i32, + id: i64, name: []const u8, length: ?f32, hidden: bool, @@ -127,6 +124,25 @@ pub const Song = jetquery.Model( .{ .relations = .{ .albumsongs = jetquery.hasMany(.Albumsong, .{}), + .artistsongs = jetquery.hasMany(.Artistsong, .{}), + }, + }, +); + +pub const Artistsong = jetquery.Model( + @This(), + "artistsongs", + struct { + id: i64, + artist_id: i64, + song_id: i64, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{ + .relations = .{ + .artist = jetquery.belongsTo(.Artist, .{}), + .song = jetquery.belongsTo(.Song, .{}), }, }, ); diff --git a/src/app/database/migrations/2025-06-06_19-46-32_create_artistsongs.zig b/src/app/database/migrations/2025-06-06_19-46-32_create_artistsongs.zig new file mode 100644 index 0000000..7d0a6c1 --- /dev/null +++ b/src/app/database/migrations/2025-06-06_19-46-32_create_artistsongs.zig @@ -0,0 +1,20 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "artistsongs", + &.{ + t.primaryKey("id", .{ .type = .bigint }), + t.column("artist_id", .bigint, .{ .reference = .{ "artists", "id" } }), + t.column("song_id", .bigint, .{ .reference = .{ "songs", "id" } }), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("artistsongs", .{}); +}