From 7b2608fee949a917d68efd05f368a1d559dae5b5 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Fri, 25 Jul 2025 17:46:28 -0400 Subject: [PATCH] Migration changes --- .sqlxconfig | 8 ++++ src/main.rs | 2 +- test_migrations/20250725213944_init.sql | 64 +++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 .sqlxconfig create mode 100644 test_migrations/20250725213944_init.sql diff --git a/.sqlxconfig b/.sqlxconfig new file mode 100644 index 0000000..10ce579 --- /dev/null +++ b/.sqlxconfig @@ -0,0 +1,8 @@ +{ + "dev": { + "migrations": "./migrations" + }, + "test": { + "migrations": "./test_migrations" + } +} diff --git a/src/main.rs b/src/main.rs index 61638db..e77c5f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1826,7 +1826,7 @@ mod tests { } let pool = super::db_mgr::connect_to_db(&db_name).await.unwrap(); - super::super::db::migrations(&pool).await; + // super::super::db::migrations(&pool).await; super::db_mgr::migrations(&pool).await; let _app = super::init::app(pool).await; diff --git a/test_migrations/20250725213944_init.sql b/test_migrations/20250725213944_init.sql new file mode 100644 index 0000000..448e908 --- /dev/null +++ b/test_migrations/20250725213944_init.sql @@ -0,0 +1,64 @@ +-- Add migration script here +CREATE EXTENSION IF NOT EXISTS pgcrypto; + +-- Table to store queued songs to process +CREATE TABLE IF NOT EXISTS "songQueue" ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + filename TEXT NOT NULL, + status TEXT CHECK (status IN ('pending', 'ready', 'processing', 'done')), + data BYTEA NULL, + user_id UUID NULL +); + +-- Table to store queued metadata +CREATE TABLE IF NOT EXISTS "metadataQueue" ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + metadata jsonb NOT NULL, + created_at timestamptz DEFAULT now(), + song_queue_id UUID NOT NULL +); + +-- Table to store queued coverart +CREATE TABLE IF NOT EXISTS "coverartQueue" ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + data BYTEA NULL, + song_queue_id UUID NULL +); + +-- Create an index for better query performance +CREATE INDEX metadata_queue_data_metadata ON "metadataQueue" USING gin (metadata); + +-- Table to store a song's info +CREATE TABLE IF NOT EXISTS "song" ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + title TEXT NOT NULL, + artist TEXT NOT NULL, + album_artist TEXT NOT NULL, + album TEXT NOT NULL, + genre TEXT NOT NULL, + year INT NOT NULL, + track INT NOT NULL, + disc INT NOT NULL, + track_count INT NOT NULL, + disc_count INT NOT NULL, + duration INT NOT NULL, + audio_type TEXT NOT NULL, + date_created timestamptz DEFAULT now(), + filename TEXT NOT NULL, + directory TEXT NOT NULL, + user_id UUID NULL +); + + +CREATE TABLE IF NOT EXISTS "coverart" ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + title TEXT NOT NULL, + path TEXT NOT NULL, + song_id UUID NOT NULL +); + +INSERT INTO "song" (id, title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, date_created, filename, directory, user_id) VALUES('44cf7940-34ff-489f-9124-d0ec90a55af9', 'Hypocrite Like The Rest', 'Kuoth', 'Kuoth', 'I', 'Alternative Hip-Hop', 2020, 1, 1, 9, 1, 139, 'flac', '2020-01-01 13:00:00-05', 'track01.flac', 'tests/I', '47491f9b-725a-4ba4-b9a5-711e1be46670'); +-- Might not to disable constraints on fields +-- INSERT INTO "song" (id, title, artist, album_artist, album, genre, year, track, disc, track_count, disc_count, duration, audio_type, date_created, filename, directory, user_id) VALUES('44cf7940-34ff-489f-9124-d0ec90a55af9', 'Hypocrite Like The Rest', 'Kuoth', 'Kuoth', 'I', 'Alternative Hip-Hop', 2020, 1, 1, 9, 1, 139, 'flac', '2020-01-01 13:00:00-05', 'track01.flac', 'tests/I', '47491f9b-725a-4ba4-b9a5-711e1be46670'); +-- INSERT INTO "coverart" VALUES('', 'I', 'tests/I/Coverart.jpg', '44cf7940-34ff-489f-9124-d0ec90a55af9'); +-- Re-enable the constraints on the fields