Add views and begin database
This commit is contained in:
parent
348545949a
commit
a15db5fb31
68 changed files with 709 additions and 90 deletions
130
src/app/database/Schema.zig
Normal file
130
src/app/database/Schema.zig
Normal file
|
|
@ -0,0 +1,130 @@
|
|||
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(
|
||||
@This(),
|
||||
"albums",
|
||||
struct {
|
||||
id: i32,
|
||||
title: []const u8,
|
||||
song_num: i32,
|
||||
length: f64,
|
||||
play_count: i32,
|
||||
score: f64,
|
||||
avg_song_score: f64,
|
||||
url: []const u8,
|
||||
holiday: bool,
|
||||
compilation: bool,
|
||||
collaboration: bool,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
},
|
||||
.{
|
||||
.relations = .{
|
||||
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
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 {
|
||||
id: i32,
|
||||
name: []const u8,
|
||||
album_num: i32,
|
||||
song_num: i32,
|
||||
play_count: i32,
|
||||
avg_album_score: f64,
|
||||
avg_song_score: f64,
|
||||
url: []const u8,
|
||||
aliased: bool,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
},
|
||||
.{
|
||||
.relations = .{
|
||||
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
pub const Scrobble = jetquery.Model(
|
||||
@This(),
|
||||
"scrobbles",
|
||||
struct {
|
||||
id: i32,
|
||||
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 Song = jetquery.Model(
|
||||
@This(),
|
||||
"songs",
|
||||
struct {
|
||||
id: i32,
|
||||
name: []const u8,
|
||||
play_count: i32,
|
||||
length: f64,
|
||||
score: f64,
|
||||
url: []const u8,
|
||||
aliased: bool,
|
||||
track_num: i32,
|
||||
hidden: bool,
|
||||
holiday: bool,
|
||||
created_at: jetquery.DateTime,
|
||||
updated_at: jetquery.DateTime,
|
||||
},
|
||||
.{
|
||||
.relations = .{
|
||||
.scrobbles = jetquery.hasMany(.Scrobble, .{}),
|
||||
},
|
||||
},
|
||||
);
|
||||
Binary file not shown.
|
|
@ -0,0 +1,26 @@
|
|||
const std = @import("std");
|
||||
const jetquery = @import("jetquery");
|
||||
const t = jetquery.schema.table;
|
||||
|
||||
pub fn up(repo: anytype) !void {
|
||||
try repo.createTable(
|
||||
"artists",
|
||||
&.{
|
||||
t.primaryKey("id", .{}),
|
||||
t.column("name", .string, .{}),
|
||||
t.column("album_num", .integer, .{}),
|
||||
t.column("song_num", .integer, .{}),
|
||||
t.column("play_count", .integer, .{}),
|
||||
t.column("avg_album_score", .float, .{}),
|
||||
t.column("avg_song_score", .float, .{}),
|
||||
t.column("url", .string, .{}),
|
||||
t.column("aliased", .boolean, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("artists", .{});
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
const std = @import("std");
|
||||
const jetquery = @import("jetquery");
|
||||
const t = jetquery.schema.table;
|
||||
|
||||
pub fn up(repo: anytype) !void {
|
||||
try repo.createTable(
|
||||
"songs",
|
||||
&.{
|
||||
t.primaryKey("id", .{}),
|
||||
t.column("name", .string, .{}),
|
||||
t.column("play_count", .integer, .{}),
|
||||
t.column("length", .float, .{}),
|
||||
t.column("score", .float, .{}),
|
||||
t.column("url", .string, .{}),
|
||||
t.column("aliased", .boolean, .{}),
|
||||
t.column("track_num", .integer, .{}),
|
||||
t.column("hidden", .boolean, .{}),
|
||||
t.column("holiday", .boolean, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("songs", .{});
|
||||
}
|
||||
|
|
@ -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(
|
||||
"artist_songs",
|
||||
&.{
|
||||
t.primaryKey("id", .{}),
|
||||
t.column("artist_id", .integer, .{}),
|
||||
t.column("song_id", .integer, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("artist_songs", .{});
|
||||
}
|
||||
|
|
@ -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(
|
||||
"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", .{});
|
||||
}
|
||||
|
|
@ -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(
|
||||
"album_songs",
|
||||
&.{
|
||||
t.primaryKey("id", .{}),
|
||||
t.column("album_id", .integer, .{}),
|
||||
t.column("song_id", .integer, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("album_songs", .{});
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
const std = @import("std");
|
||||
const jetquery = @import("jetquery");
|
||||
const t = jetquery.schema.table;
|
||||
|
||||
pub fn up(repo: anytype) !void {
|
||||
try repo.createTable(
|
||||
"scrobbles",
|
||||
&.{
|
||||
t.primaryKey("id", .{}),
|
||||
t.column("date", .datetime, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("scrobbles", .{});
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
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("score", .float, .{}),
|
||||
t.column("avg_song_score", .float, .{}),
|
||||
t.column("url", .string, .{}),
|
||||
t.column("holiday", .boolean, .{}),
|
||||
t.column("compilation", .boolean, .{}),
|
||||
t.column("collaboration", .boolean, .{}),
|
||||
t.timestamps(.{}),
|
||||
},
|
||||
.{},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn down(repo: anytype) !void {
|
||||
try repo.dropTable("albums", .{});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue