Files
query-orchestration/internal/database/migrations_collapsed/00000000000004_batch_uploads.up.sql
T

53 lines
1.8 KiB
SQL
Raw Normal View History

-- Migration 004: Batch Uploads
-- Batch upload tracking for ZIP file uploads
-- Merges original migrations 103 + 104
2025-08-04 10:54:22 -07:00
-- Create batch status ENUM type
CREATE TYPE batch_status AS ENUM (
'processing', -- Currently processing
'completed', -- All documents processed (may have individual failures)
'failed', -- Batch-level failure (ZIP corrupt, etc.)
'cancelled' -- Cancelled by user
);
-- Create batch uploads table with all columns
2025-08-04 10:54:22 -07:00
CREATE TABLE batch_uploads (
id uuid PRIMARY KEY DEFAULT uuid_generate_v7(),
client_id varchar(255) NOT NULL,
original_filename text NOT NULL,
2025-08-04 10:54:22 -07:00
-- Essential batch metrics
total_documents integer NOT NULL,
processed_documents integer NOT NULL DEFAULT 0,
failed_documents integer NOT NULL DEFAULT 0,
invalid_type_documents integer NOT NULL DEFAULT 0,
2025-08-04 10:54:22 -07:00
-- Status and progress
status batch_status NOT NULL DEFAULT 'processing',
progress_percent integer NOT NULL DEFAULT 0,
2025-08-04 10:54:22 -07:00
-- Failed document filenames (JSON array)
failed_filenames jsonb DEFAULT '[]'::jsonb,
2025-08-04 10:54:22 -07:00
-- Timestamps
created_at timestamp NOT NULL DEFAULT NOW(),
completed_at timestamp,
-- Storage metadata (from migration 104)
archive_bucket text,
archive_key text,
file_size_bytes bigint,
FOREIGN KEY (client_id) REFERENCES clients(clientId),
-- Constraint: storage metadata consistency
CONSTRAINT batch_storage_consistent CHECK (
(archive_bucket IS NULL AND archive_key IS NULL AND file_size_bytes IS NULL) OR
(archive_bucket IS NOT NULL AND archive_key IS NOT NULL)
)
2025-08-04 10:54:22 -07:00
);
-- Create indexes for efficient queries
CREATE INDEX idx_batch_uploads_client_id ON batch_uploads(client_id);
CREATE INDEX idx_batch_uploads_status ON batch_uploads(status);