Make rating data optional

Use HTML to enfore at least one of the two fields has a value, but I don't want to require both
This commit is contained in:
mitteneer 2025-06-23 16:47:46 -04:00
parent b7e625dd98
commit 996022fe5f
4 changed files with 16 additions and 22 deletions

View file

@ -153,17 +153,15 @@ pub const Albumrating = jetquery.Model(
struct {
id: i32,
album: i64,
rating: i16,
rating_text: []const u8,
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",
}),
.album = jetquery.belongsTo(.Album, .{ .foreign_key = "album" }),
},
},
);
@ -174,17 +172,15 @@ pub const Artistrating = jetquery.Model(
struct {
id: i32,
artist: i64,
rating: i16,
rating_text: []const u8,
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",
}),
.artist = jetquery.belongsTo(.Artist, .{ .foreign_key = "artist" }),
},
},
);
@ -195,17 +191,15 @@ pub const Songrating = jetquery.Model(
struct {
id: i32,
song: i64,
rating: i16,
rating_text: []const u8,
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",
}),
.albumsong = jetquery.belongsTo(.Albumsong, .{ .foreign_key = "song" }),
},
},
);

View file

@ -7,9 +7,9 @@ pub fn up(repo: anytype) !void {
"songratings",
&.{
t.primaryKey("id", .{}),
t.column("song", .bigint, .{ .reference = .{ "albumsongs", "id" } }),
t.column("rating", .smallint, .{}),
t.column("rating_text", .text, .{}),
t.column("song", .bigint, .{ .reference = .{ "songs", "id" } }),
t.column("rating", .smallint, .{ .optional = true }),
t.column("rating_text", .text, .{ .optional = true }),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},

View file

@ -8,8 +8,8 @@ pub fn up(repo: anytype) !void {
&.{
t.primaryKey("id", .{}),
t.column("album", .bigint, .{ .reference = .{ "albums", "id" } }),
t.column("rating", .smallint, .{}),
t.column("rating_text", .text, .{}),
t.column("rating", .smallint, .{ .optional = true }),
t.column("rating_text", .text, .{ .optional = true }),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},

View file

@ -8,8 +8,8 @@ pub fn up(repo: anytype) !void {
&.{
t.primaryKey("id", .{}),
t.column("artist", .bigint, .{ .reference = .{ "artists", "id" } }),
t.column("rating", .smallint, .{}),
t.column("rating_text", .text, .{}),
t.column("rating", .smallint, .{ .optional = true }),
t.column("rating_text", .text, .{ .optional = true }),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},