From 45ab63c0d6e42acd98667b18cb7a16b74a8bd10d Mon Sep 17 00:00:00 2001 From: perf3ct Date: Sat, 14 Jun 2025 23:14:49 +0000 Subject: [PATCH] feat(db): don't use weird pgsql extension to generate uuids, require postgres 13+ --- migrations/20240101000000_initial_schema.sql | 7 +++---- migrations/20240101000001_add_ocr_queue.sql | 4 ++-- migrations/20240101000010_notifications.sql | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/migrations/20240101000000_initial_schema.sql b/migrations/20240101000000_initial_schema.sql index 4056df8..55ebf89 100644 --- a/migrations/20240101000000_initial_schema.sql +++ b/migrations/20240101000000_initial_schema.sql @@ -1,10 +1,9 @@ -- Create extensions -CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE EXTENSION IF NOT EXISTS "pg_trgm"; -- Create users table CREATE TABLE IF NOT EXISTS users ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), username VARCHAR(255) UNIQUE NOT NULL, email VARCHAR(255) UNIQUE NOT NULL, password_hash VARCHAR(255) NOT NULL, @@ -14,7 +13,7 @@ CREATE TABLE IF NOT EXISTS users ( -- Create documents table CREATE TABLE IF NOT EXISTS documents ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), filename VARCHAR(255) NOT NULL, original_filename VARCHAR(255) NOT NULL, file_path VARCHAR(500) NOT NULL, @@ -47,7 +46,7 @@ CREATE INDEX IF NOT EXISTS idx_documents_ocr_word_count ON documents(ocr_word_co -- Create settings table CREATE TABLE IF NOT EXISTS settings ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID REFERENCES users(id) ON DELETE CASCADE UNIQUE, ocr_language VARCHAR(10) DEFAULT 'eng', concurrent_ocr_jobs INT DEFAULT 4, diff --git a/migrations/20240101000001_add_ocr_queue.sql b/migrations/20240101000001_add_ocr_queue.sql index 3f4a19f..bc99add 100644 --- a/migrations/20240101000001_add_ocr_queue.sql +++ b/migrations/20240101000001_add_ocr_queue.sql @@ -1,6 +1,6 @@ -- Add OCR queue table for robust processing CREATE TABLE IF NOT EXISTS ocr_queue ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), document_id UUID REFERENCES documents(id) ON DELETE CASCADE, status VARCHAR(20) DEFAULT 'pending', priority INT DEFAULT 5, @@ -31,7 +31,7 @@ ALTER TABLE documents ADD COLUMN IF NOT EXISTS ocr_error TEXT; ALTER TABLE documents ADD COLUMN IF NOT EXISTS ocr_completed_at TIMESTAMPTZ; CREATE TABLE IF NOT EXISTS ocr_metrics ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), date DATE DEFAULT CURRENT_DATE, hour INT DEFAULT EXTRACT(HOUR FROM NOW()), total_processed INT DEFAULT 0, diff --git a/migrations/20240101000010_notifications.sql b/migrations/20240101000010_notifications.sql index 9121680..f71bb17 100644 --- a/migrations/20240101000010_notifications.sql +++ b/migrations/20240101000010_notifications.sql @@ -1,6 +1,6 @@ -- Create notifications table for backend-to-frontend notifications CREATE TABLE IF NOT EXISTS notifications ( - id UUID PRIMARY KEY DEFAULT uuid_generate_v4(), + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE, notification_type VARCHAR(20) NOT NULL CHECK (notification_type IN ('success', 'error', 'info', 'warning')), title VARCHAR(255) NOT NULL,