c10fa98d0a
Restore original migrations (001-120) to fix schema_migrations version mismatch * Restore original migrations (001-120) to fix schema_migrations version mismatch The previous migration collapse broke deployed databases because: - Dev database was at version 120 (the real remove_text_extraction migration) - Main had collapsed migrations (001-012) + stub files (119_stub, 120_stub) - The migrate tool couldn't find version 119/120 with matching content This commit restores the original 27 migrations (versions 001-120) from before the collapse, ensuring backward compatibility with existing databases.
44 lines
1.6 KiB
SQL
44 lines
1.6 KiB
SQL
-- 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
|
|
CREATE TABLE batch_uploads (
|
|
id uuid PRIMARY KEY DEFAULT uuid_generate_v7(),
|
|
client_id varchar(255) NOT NULL,
|
|
original_filename text NOT NULL,
|
|
|
|
-- 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,
|
|
|
|
-- Status and progress
|
|
status batch_status NOT NULL DEFAULT 'processing',
|
|
progress_percent integer NOT NULL DEFAULT 0,
|
|
|
|
-- Failed document filenames (JSON array)
|
|
failed_filenames jsonb DEFAULT '[]'::jsonb,
|
|
|
|
-- Timestamps
|
|
created_at timestamp NOT NULL DEFAULT NOW(),
|
|
completed_at timestamp,
|
|
|
|
FOREIGN KEY (client_id) REFERENCES clients(clientId)
|
|
);
|
|
|
|
-- 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);
|
|
|
|
-- Add batch_id to documents table
|
|
ALTER TABLE documents ADD COLUMN batch_id uuid NULL;
|
|
ALTER TABLE documents ADD FOREIGN KEY (batch_id) REFERENCES batch_uploads(id);
|
|
|
|
-- Create index on batch_id for efficient batch document queries
|
|
CREATE INDEX idx_documents_batch_id ON documents(batch_id); |