Files
sori.studio/db/migrations/070_post_import_jobs.sql

49 lines
2.1 KiB
SQL

CREATE TABLE IF NOT EXISTS post_import_jobs (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
requested_by UUID REFERENCES users(id) ON DELETE SET NULL,
requested_email TEXT NOT NULL DEFAULT '',
original_file_name TEXT NOT NULL DEFAULT '',
zip_file_path TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'queued',
total_count INTEGER NOT NULL DEFAULT 0,
processed_count INTEGER NOT NULL DEFAULT 0,
imported_count INTEGER NOT NULL DEFAULT 0,
skipped_count INTEGER NOT NULL DEFAULT 0,
failed_count INTEGER NOT NULL DEFAULT 0,
asset_count INTEGER NOT NULL DEFAULT 0,
reused_asset_count INTEGER NOT NULL DEFAULT 0,
warning_count INTEGER NOT NULL DEFAULT 0,
message TEXT NOT NULL DEFAULT '',
error_detail TEXT NOT NULL DEFAULT '',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
started_at TIMESTAMPTZ,
completed_at TIMESTAMPTZ,
CONSTRAINT post_import_jobs_status_check CHECK (status IN ('queued', 'processing', 'ready', 'failed'))
);
CREATE INDEX IF NOT EXISTS post_import_jobs_status_created_at_idx
ON post_import_jobs (status, created_at DESC);
CREATE TABLE IF NOT EXISTS post_import_items (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
job_id UUID NOT NULL REFERENCES post_import_jobs(id) ON DELETE CASCADE,
item_index INTEGER NOT NULL,
title TEXT NOT NULL DEFAULT '',
slug TEXT NOT NULL DEFAULT '',
source_path TEXT NOT NULL DEFAULT '',
status TEXT NOT NULL DEFAULT 'pending',
progress INTEGER NOT NULL DEFAULT 0,
message TEXT NOT NULL DEFAULT '',
post_id UUID REFERENCES posts(id) ON DELETE SET NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
completed_at TIMESTAMPTZ,
CONSTRAINT post_import_items_status_check CHECK (status IN ('pending', 'processing', 'ready', 'skipped', 'failed')),
CONSTRAINT post_import_items_progress_check CHECK (progress >= 0 AND progress <= 100),
CONSTRAINT post_import_items_job_index_unique UNIQUE (job_id, item_index)
);
CREATE INDEX IF NOT EXISTS post_import_items_job_id_item_index_idx
ON post_import_items (job_id, item_index ASC);