Add Artistsongs table
Whether or not a song is covered, there was an original artist who originally performed the song. The only issue is that an Artistsongs table will almost be the exact same as the Albumsongsartists table, since most songs aren't covered. So, it may be better not to populate that table by default, and then if two albumsongs with different artists share the same song, then fill the Artistsongs table.
This commit is contained in:
parent
162341fb5f
commit
85552f39c1
2 changed files with 56 additions and 20 deletions
|
|
@ -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, .{}),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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", .{});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue