Create ratings tables

This commit is contained in:
mitteneer 2025-06-22 14:37:10 -04:00
parent 9c90c683c6
commit 77a9c24dab
4 changed files with 130 additions and 1 deletions

View file

@ -97,7 +97,7 @@ pub const Scrobble = jetquery.Model(
@This(),
"scrobbles",
struct {
id: i64,
id: i32,
albumsong: i64,
datetime: jetquery.DateTime,
created_at: jetquery.DateTime,
@ -146,3 +146,66 @@ pub const Artistsong = jetquery.Model(
},
},
);
pub const Albumrating = jetquery.Model(
@This(),
"albumratings",
struct {
id: i32,
album: i64,
rating: i16,
rating_text: []const u8,
date: jetquery.DateTime,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.album = jetquery.belongsTo(.Album, .{
.foreign_key = "album",
}),
},
},
);
pub const Artistrating = jetquery.Model(
@This(),
"artistratings",
struct {
id: i32,
artist: i64,
rating: i16,
rating_text: []const u8,
date: jetquery.DateTime,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.artist = jetquery.belongsTo(.Artist, .{
.foreign_key = "artist",
}),
},
},
);
pub const Songrating = jetquery.Model(
@This(),
"songratings",
struct {
id: i32,
song: i64,
rating: i16,
rating_text: []const u8,
date: jetquery.DateTime,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.albumsong = jetquery.belongsTo(.Albumsong, .{
.foreign_key = "song",
}),
},
},
);

View file

@ -0,0 +1,22 @@
const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;
pub fn up(repo: anytype) !void {
try repo.createTable(
"songratings",
&.{
t.primaryKey("id", .{}),
t.column("song", .bigint, .{ .reference = .{ "albumsongs", "id" } }),
t.column("rating", .smallint, .{}),
t.column("rating_text", .text, .{}),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},
.{},
);
}
pub fn down(repo: anytype) !void {
try repo.dropTable("songratings", .{});
}

View file

@ -0,0 +1,22 @@
const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;
pub fn up(repo: anytype) !void {
try repo.createTable(
"albumratings",
&.{
t.primaryKey("id", .{}),
t.column("album", .bigint, .{ .reference = .{ "albums", "id" } }),
t.column("rating", .smallint, .{}),
t.column("rating_text", .text, .{}),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},
.{},
);
}
pub fn down(repo: anytype) !void {
try repo.dropTable("albumratings", .{});
}

View file

@ -0,0 +1,22 @@
const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;
pub fn up(repo: anytype) !void {
try repo.createTable(
"artistratings",
&.{
t.primaryKey("id", .{}),
t.column("artist", .bigint, .{ .reference = .{ "artists", "id" } }),
t.column("rating", .smallint, .{}),
t.column("rating_text", .text, .{}),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},
.{},
);
}
pub fn down(repo: anytype) !void {
try repo.dropTable("artistratings", .{});
}