87 lines
2.8 KiB
TypeScript
87 lines
2.8 KiB
TypeScript
import { sql } from "drizzle-orm";
|
|
import { pgTable, text, varchar, serial, timestamp, integer } from "drizzle-orm/pg-core";
|
|
import { createInsertSchema } from "drizzle-zod";
|
|
import { z } from "zod";
|
|
|
|
export const users = pgTable("users", {
|
|
id: varchar("id").primaryKey().default(sql`gen_random_uuid()`),
|
|
username: text("username").notNull().unique(),
|
|
password: text("password").notNull(),
|
|
});
|
|
|
|
export const playlists = pgTable("playlists", {
|
|
id: serial("id").primaryKey(),
|
|
name: text("name").notNull(),
|
|
description: text("description"),
|
|
coverUrl: text("cover_url"),
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
});
|
|
|
|
export const tracks = pgTable("tracks", {
|
|
id: serial("id").primaryKey(),
|
|
title: text("title").notNull(),
|
|
artist: text("artist").notNull(),
|
|
album: text("album"),
|
|
coverUrl: text("cover_url"),
|
|
duration: text("duration"),
|
|
navidromeId: text("navidrome_id"),
|
|
streamUrl: text("stream_url"),
|
|
createdAt: timestamp("created_at").defaultNow().notNull(),
|
|
});
|
|
|
|
export const playlistTracks = pgTable("playlist_tracks", {
|
|
id: serial("id").primaryKey(),
|
|
playlistId: integer("playlist_id").notNull().references(() => playlists.id, { onDelete: "cascade" }),
|
|
trackId: integer("track_id").notNull().references(() => tracks.id, { onDelete: "cascade" }),
|
|
position: integer("position").notNull().default(0),
|
|
addedAt: timestamp("added_at").defaultNow().notNull(),
|
|
});
|
|
|
|
export const settings = pgTable("settings", {
|
|
id: serial("id").primaryKey(),
|
|
navidromeUrl: text("navidrome_url"),
|
|
navidromeUsername: text("navidrome_username"),
|
|
navidromeToken: text("navidrome_token"),
|
|
updatedAt: timestamp("updated_at").defaultNow().notNull(),
|
|
});
|
|
|
|
export const insertUserSchema = createInsertSchema(users).pick({
|
|
username: true,
|
|
password: true,
|
|
});
|
|
|
|
export const insertPlaylistSchema = createInsertSchema(playlists).omit({
|
|
id: true,
|
|
createdAt: true,
|
|
});
|
|
|
|
export const insertTrackSchema = createInsertSchema(tracks).omit({
|
|
id: true,
|
|
createdAt: true,
|
|
});
|
|
|
|
export const insertPlaylistTrackSchema = createInsertSchema(playlistTracks).omit({
|
|
id: true,
|
|
addedAt: true,
|
|
});
|
|
|
|
export const insertSettingsSchema = createInsertSchema(settings).omit({
|
|
id: true,
|
|
updatedAt: true,
|
|
});
|
|
|
|
export type InsertUser = z.infer<typeof insertUserSchema>;
|
|
export type User = typeof users.$inferSelect;
|
|
|
|
export type InsertPlaylist = z.infer<typeof insertPlaylistSchema>;
|
|
export type Playlist = typeof playlists.$inferSelect;
|
|
|
|
export type InsertTrack = z.infer<typeof insertTrackSchema>;
|
|
export type Track = typeof tracks.$inferSelect;
|
|
|
|
export type InsertPlaylistTrack = z.infer<typeof insertPlaylistTrackSchema>;
|
|
export type PlaylistTrack = typeof playlistTracks.$inferSelect;
|
|
|
|
export type InsertSettings = z.infer<typeof insertSettingsSchema>;
|
|
export type Settings = typeof settings.$inferSelect;
|