Restart database

It's been 0 days since I've last retsrated the database
This commit is contained in:
mitteneer 2025-02-17 23:05:56 -05:00
parent 010c72252d
commit 473abaf564
13 changed files with 93 additions and 264 deletions

View file

@ -1,190 +1,94 @@
const jetquery = @import("jetzig").jetquery; const jetquery = @import("jetzig").jetquery;
pub const AlbumSong = jetquery.Model(
@This(),
"album_songs",
struct {
id: i32,
album_id: i32,
song_id: i32,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{},
);
pub const Album = jetquery.Model( pub const Album = jetquery.Model(
@This(), @This(),
"albums", "albums",
struct {
id: i32,
title: []const u8,
song_num: i32,
length: f32,
play_count: i32,
holiday: bool,
compilation: bool,
deluxe: bool,
live: bool,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
.ratings = jetquery.hasMany(.Ratings, .{}),
.aliases = jetquery.hasMany(.Aliases, .{}),
.songs = jetquery.hasMany(.AlbumSongs, .{}),
.artists = jetquery.hasMany(.ArtistAlbums, .{}),
},
},
);
pub const ArtistAlbum = jetquery.Model(
@This(),
"artist_albums",
struct {
id: i32,
artist_id: i32,
album_id: i32,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{},
);
pub const ArtistSong = jetquery.Model(
@This(),
"artist_songs",
struct {
id: i32,
artist_id: i32,
song_id: i32,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{},
);
pub const Artist = jetquery.Model(
@This(),
"artists",
struct { struct {
id: i32, id: i32,
name: []const u8, name: []const u8,
album_num: i32, length: ?f32,
song_num: i32,
play_count: i32,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
.aliases = jetquery.hasMany(.Aliases, .{}),
.concerts = jetquery.hasMany(.Concerts, .{}),
.songs = jetquery.hasMany(.ArtistSongs, .{}),
.albums = jetquery.hasMany(.ArtistAlbums, .{}),
},
},
);
pub const Scrobble = jetquery.Model(
@This(),
"scrobbles",
struct {
id: i32,
date: jetquery.DateTime,
song_id: i32,
album_id: ?i32,
artist_id: i32,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.song = jetquery.belongsTo(.Song, .{}),
.album = jetquery.belongsTo(.Album, .{}),
.artist = jetquery.belongsTo(.Artist, .{}),
},
},
);
pub const Song = jetquery.Model(
@This(),
"songs",
struct {
id: i32,
title: []const u8,
length: f32,
hidden: bool,
holiday: bool,
play_count: i32,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{
.relations = .{
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
.ratings = jetquery.hasMany(.Ratings, .{}),
.aliases = jetquery.hasMany(.Aliases, .{}),
.artists = jetquery.hasMany(.ArtistSongs, .{}),
.albums = jetquery.hasMany(.AlbumSongs, .{}),
},
},
);
pub const Alias = jetquery.Model(
@This(),
"aliases",
struct {
id: i32,
reference_id: i32,
alias: []const u8,
created_at: jetquery.DateTime, created_at: jetquery.DateTime,
updated_at: jetquery.DateTime, updated_at: jetquery.DateTime,
}, },
.{}, .{},
); );
pub const Concert = jetquery.Model( pub const Alias = jetquery.Model(@This(), "aliases", struct {
@This(), id: i32,
"concerts", reference_id: i32,
struct { alias: []const u8,
id: i32, created_at: jetquery.DateTime,
location: []const u8, updated_at: jetquery.DateTime,
date: jetquery.DateTime, }, .{});
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
},
.{},
);
pub const Rating = jetquery.Model( pub const Artist = jetquery.Model(@This(), "artists", struct {
@This(), id: i32,
"ratings", name: []const u8,
struct { descriptive_string: []const u8,
id: i32, created_at: jetquery.DateTime,
reference_id: i32, updated_at: jetquery.DateTime,
score: f32, }, .{ .relations = .{
date: jetquery.DateTime, .scrobbles = jetquery.hasMany(.Scrobble, .{}),
created_at: jetquery.DateTime, .aliases = jetquery.hasMany(.Alias, .{}),
updated_at: jetquery.DateTime, .songs = jetquery.hasMany(.Song, .{}),
}, .albums = jetquery.hasMany(.Album, .{}),
.{}, } });
);
pub const RawScrobble = jetquery.Model( pub const Masteralbum = jetquery.Model(@This(), "masteralbums", struct {
@This(), id: i32,
"raw_scrobbles", name: []const u8,
struct { created_at: jetquery.DateTime,
id: i32, updated_at: jetquery.DateTime,
track: []const u8, }, .{ .relations = .{
artist: []const u8, .albums = jetquery.hasMny(.Album, .{}),
album: []const u8, } });
date: jetquery.DateTime,
created_at: jetquery.DateTime, pub const Mastersong = jetquery.Model(@This(), "mastersongs", struct {
updated_at: jetquery.DateTime, id: i32,
}, name: []const u8,
.{}, created_at: jetquery.DateTime,
); updated_at: jetquery.DateTime,
}, .{ .relations = .{
.songs = jetquery.hasMany(.Song, .{}),
} });
pub const Rating = jetquery.Model(@This(), "ratings", struct {
id: i32,
reference_id: i32,
score: f32,
date: jetquery.DateTime,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
}, .{ .relations = .{
.song = jetquery.belongsTo(.Song, .{}),
.album = jetquery.belongsTo(.Album, .{}),
.artist = jetquery.belongsTo(.Artist, .{}),
} });
pub const Scrobble = jetquery.Model(@This(), "scrobbles", struct {
id: i32,
song_id: i32,
album_id: ?i32,
date: jetquery.DateTime,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
}, .{ .relations = .{
.song = jetquery.belongsTo(.Song, .{}),
.album = jetquery.belongsTo(.Album, .{}),
.artists = jetquery.hasMany(.Artist, .{}),
} });
pub const Song = jetquery.Model(@This(), "songs", struct {
id: i32,
name: []const u8,
length: ?f32,
hidden: bool,
created_at: jetquery.DateTime,
updated_at: jetquery.DateTime,
}, .{ .relations = .{
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
.ratings = jetquery.hasMany(.Rating, .{}),
.aliases = jetquery.hasMany(.Alias, .{}),
.artists = jetquery.hasMany(.Artist, .{}),
.albums = jetquery.hasMany(.Album, .{}),
} });

View file

@ -1,20 +0,0 @@
const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;
pub fn up(repo: anytype) !void {
try repo.createTable(
"artist_albums",
&.{
t.primaryKey("id", .{}),
t.column("artist_id", .integer, .{}),
t.column("album_id", .integer, .{}),
t.timestamps(.{}),
},
.{},
);
}
pub fn down(repo: anytype) !void {
try repo.dropTable("artist_albums", .{});
}

View file

@ -1,26 +0,0 @@
const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;
pub fn up(repo: anytype) !void {
try repo.createTable(
"albums",
&.{
t.primaryKey("id", .{}),
t.column("title", .string, .{}),
t.column("song_num", .integer, .{}),
t.column("length", .float, .{}),
t.column("play_count", .integer, .{}),
t.column("holiday", .boolean, .{}),
t.column("compilation", .boolean, .{}),
t.column("deluxe", .boolean, .{}),
t.column("live", .boolean, .{}),
t.timestamps(.{}),
},
.{},
);
}
pub fn down(repo: anytype) !void {
try repo.dropTable("albums", .{});
}

View file

@ -1,22 +0,0 @@
const std = @import("std");
const jetquery = @import("jetquery");
const t = jetquery.schema.table;
pub fn up(repo: anytype) !void {
try repo.createTable(
"raw_scrobbles",
&.{
t.primaryKey("id", .{}),
t.column("track", .string, .{}),
t.column("artist", .string, .{}),
t.column("album", .string, .{}),
t.column("date", .datetime, .{}),
t.timestamps(.{}),
},
.{},
);
}
pub fn down(repo: anytype) !void {
try repo.dropTable("raw_scrobbles", .{});
}

View file

@ -4,11 +4,11 @@ const t = jetquery.schema.table;
pub fn up(repo: anytype) !void { pub fn up(repo: anytype) !void {
try repo.createTable( try repo.createTable(
"album_songs", "albums",
&.{ &.{
t.primaryKey("id", .{}), t.primaryKey("id", .{}),
t.column("album_id", .integer, .{}), t.column("name", .string, .{}),
t.column("song_id", .integer, .{}), t.column("length", .float, .{ .optional = true }),
t.timestamps(.{}), t.timestamps(.{}),
}, },
.{}, .{},
@ -16,5 +16,5 @@ pub fn up(repo: anytype) !void {
} }
pub fn down(repo: anytype) !void { pub fn down(repo: anytype) !void {
try repo.dropTable("album_songs", .{}); try repo.dropTable("albums", .{});
} }

View file

@ -8,9 +8,7 @@ pub fn up(repo: anytype) !void {
&.{ &.{
t.primaryKey("id", .{}), t.primaryKey("id", .{}),
t.column("name", .string, .{}), t.column("name", .string, .{}),
t.column("album_num", .integer, .{}), t.column("descriptive_string", .string, .{}),
t.column("song_num", .integer, .{}),
t.column("play_count", .integer, .{}),
t.timestamps(.{}), t.timestamps(.{}),
}, },
.{}, .{},

View file

@ -4,11 +4,10 @@ const t = jetquery.schema.table;
pub fn up(repo: anytype) !void { pub fn up(repo: anytype) !void {
try repo.createTable( try repo.createTable(
"concerts", "masteralbums",
&.{ &.{
t.primaryKey("id", .{}), t.primaryKey("id", .{}),
t.column("location", .string, .{}), t.column("name", .string, .{}),
t.column("date", .datetime, .{}),
t.timestamps(.{}), t.timestamps(.{}),
}, },
.{}, .{},
@ -16,5 +15,5 @@ pub fn up(repo: anytype) !void {
} }
pub fn down(repo: anytype) !void { pub fn down(repo: anytype) !void {
try repo.dropTable("concerts", .{}); try repo.dropTable("masteralbums", .{});
} }

View file

@ -4,11 +4,10 @@ const t = jetquery.schema.table;
pub fn up(repo: anytype) !void { pub fn up(repo: anytype) !void {
try repo.createTable( try repo.createTable(
"artist_songs", "mastersongs",
&.{ &.{
t.primaryKey("id", .{}), t.primaryKey("id", .{}),
t.column("artist_id", .integer, .{}), t.column("name", .string, .{}),
t.column("song_id", .integer, .{}),
t.timestamps(.{}), t.timestamps(.{}),
}, },
.{}, .{},
@ -16,5 +15,5 @@ pub fn up(repo: anytype) !void {
} }
pub fn down(repo: anytype) !void { pub fn down(repo: anytype) !void {
try repo.dropTable("artist_songs", .{}); try repo.dropTable("mastersongs", .{});
} }

View file

@ -7,10 +7,9 @@ pub fn up(repo: anytype) !void {
"scrobbles", "scrobbles",
&.{ &.{
t.primaryKey("id", .{}), t.primaryKey("id", .{}),
t.column("date", .datetime, .{}),
t.column("song_id", .integer, .{}), t.column("song_id", .integer, .{}),
t.column("album_id", .integer, .{ .optional = true }), t.column("album_id", .integer, .{ .optional = true }),
t.column("artist_id", .integer, .{}), t.column("date", .datetime, .{}),
t.timestamps(.{}), t.timestamps(.{}),
}, },
.{}, .{},

View file

@ -7,11 +7,9 @@ pub fn up(repo: anytype) !void {
"songs", "songs",
&.{ &.{
t.primaryKey("id", .{}), t.primaryKey("id", .{}),
t.column("title", .string, .{}), t.column("name", .string, .{}),
t.column("length", .float, .{}), t.column("length", .float, .{ .optional = true }),
t.column("hidden", .boolean, .{}), t.column("hidden", .boolean, .{}),
t.column("holiday", .boolean, .{}),
t.column("play_count", .integer, .{}),
t.timestamps(.{}), t.timestamps(.{}),
}, },
.{}, .{},

View file

@ -40,7 +40,7 @@ pub fn run(allocator: std.mem.Allocator, params: *jetzig.data.Value, env: jetzig
// name. As far as I can tell, this is only an // name. As far as I can tell, this is only an
// issue for Weezer. // issue for Weezer.
// Artist Artist hash. If two artists have the same name, // Artist: Artist hash. If two artists have the same name,
// then a descriptive string can be provided to // then a descriptive string can be provided to
// differentiate after the fact, or in a rule. // differentiate after the fact, or in a rule.
var album_id: u64 = 0; var album_id: u64 = 0;