Files
descrybe/apps/api/sql/schema/004_processing.sql
T

61 lines
2.3 KiB
SQL
Raw Normal View History

-- +goose Up
CREATE TABLE processing_jobs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
company_id UUID NOT NULL REFERENCES companies(id) ON DELETE CASCADE,
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
status TEXT NOT NULL DEFAULT 'pending'
CHECK (status IN ('pending', 'running', 'completed', 'failed', 'cancelled')),
total_products INT NOT NULL DEFAULT 0,
processed_products INT NOT NULL DEFAULT 0,
error TEXT,
processing_type TEXT NOT NULL DEFAULT 'full',
priority INT NOT NULL DEFAULT 0,
estimated_tokens INT NOT NULL DEFAULT 0,
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX processing_jobs_company_id_idx ON processing_jobs(company_id);
CREATE INDEX processing_jobs_status_idx ON processing_jobs(status);
CREATE TABLE processing_job_products (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
job_id UUID NOT NULL REFERENCES processing_jobs(id) ON DELETE CASCADE,
raw_product_id UUID NOT NULL REFERENCES raw_products(id) ON DELETE CASCADE,
status TEXT NOT NULL DEFAULT 'pending'
CHECK (status IN ('pending', 'processing', 'processed', 'failed', 'cancelled')),
error TEXT,
processed_product_id UUID REFERENCES processed_products(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX processing_job_products_job_id_idx ON processing_job_products(job_id);
CREATE TABLE tasks (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
company_id UUID REFERENCES companies(id) ON DELETE CASCADE,
user_id UUID REFERENCES users(id) ON DELETE SET NULL,
task_name TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'pending',
start_time TIMESTAMPTZ DEFAULT now(),
end_time TIMESTAMPTZ,
log TEXT,
processing_products INT NOT NULL DEFAULT 0,
processed_products INT NOT NULL DEFAULT 0,
total_products INT NOT NULL DEFAULT 0,
error_products JSONB,
product_ids JSONB,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX tasks_company_id_idx ON tasks(company_id);
-- +goose Down
DROP TABLE IF EXISTS tasks;
DROP TABLE IF EXISTS processing_job_products;
DROP TABLE IF EXISTS processing_jobs;