diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..f30fe032 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +.git +.indexion +.env +.env.* +!.env.example +**/node_modules +**/target +**/.output +**/.nitro +**/dist +db-data +backup +*.log diff --git a/.gitignore b/.gitignore index 40f5936a..19a1bb44 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,8 @@ backups/** # Temp gitignores -db-data/ +db-data*/ +backup/ # System Files .DS_Store diff --git a/Dockerfile b/Dockerfile index 8166ed17..bbe8a01b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,44 @@ FROM oven/bun:debian -# Install python3, ffmpeg, and ca-certificates for yt-dlp and media processing +# Install the native build toolchain, Python for the CPU ONNX Runtime package, +# ffmpeg, and certificates for media processing. RUN apt-get update && apt-get install -y --no-install-recommends \ - python3 \ - ffmpeg \ + build-essential \ ca-certificates \ + curl \ + ffmpeg \ + libssl-dev \ + pkg-config \ + python3 \ + python3-pip \ && rm -rf /var/lib/apt/lists/* +# dghs-imgutils-rs is a Rust N-API addon and requires a current Rust toolchain +# during bun install. The addon loads the runtime dynamically at application +# startup, so keep the compatible CPU runtime beside its provider library. +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \ + sh -s -- -y --profile minimal --default-toolchain stable +ENV PATH="/root/.cargo/bin:${PATH}" + +RUN python3 -m pip install --no-cache-dir --target /tmp/onnxruntime \ + onnxruntime==1.24.2 \ + && mkdir -p /usr/local/lib/onnxruntime \ + && find /tmp/onnxruntime/onnxruntime/capi -maxdepth 1 -type f \ + -name 'libonnxruntime*.so*' \ + -exec cp {} /usr/local/lib/onnxruntime/ \; \ + && test -f /usr/local/lib/onnxruntime/libonnxruntime.so.1.24.2 \ + && test -f /usr/local/lib/onnxruntime/libonnxruntime_providers_shared.so \ + && rm -rf /tmp/onnxruntime + +ENV ORT_DYLIB_PATH="/usr/local/lib/onnxruntime/libonnxruntime.so.1.24.2" +ENV LD_LIBRARY_PATH="/usr/local/lib/onnxruntime" +ENV DGHS_BACKEND="cpu" +ENV DGHS_PRECISION="fp32" + WORKDIR /app + +COPY . . + +RUN bun install --frozen-lockfile +RUN bun run --cwd apps/server validate:native +RUN bun run --cwd apps/server build diff --git a/README.md b/README.md index 249e95d5..765fd1e1 100644 --- a/README.md +++ b/README.md @@ -96,4 +96,5 @@ CPU のみで使用する場合は通常通り `bun install` してください - **Tauri SPA**: [`apps/tauri/src/`](./apps/tauri/src/)、Rust側 [`apps/tauri/src-tauri/`](./apps/tauri/src-tauri/) - **V2移行状況**: [REPORT.md](./REPORT.md) - **DBスキーマ**: `packages/db/src/schema.ts` +- **本番DB移行**: [PostgreSQL 18 / UUIDv7移行手順](./docs/operations/postgresql-18-uuidv7-migration.md) - **開発ルール**: [AGENTS.md](./AGENTS.md) diff --git a/apps/server/drizzle/0027_acoustic_impossible_man.sql b/apps/server/drizzle/0027_acoustic_impossible_man.sql new file mode 100644 index 00000000..732369fe --- /dev/null +++ b/apps/server/drizzle/0027_acoustic_impossible_man.sql @@ -0,0 +1,19 @@ +ALTER TABLE "author_accounts" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "authors" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "categories" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "ccip_embeddings" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "characters" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "collections" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "ips" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "jobs" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "media_regions" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "media_relations" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "media_sources" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "media_urls" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "media" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "projects" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "search_snapshots" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "similar_media" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "tags" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "users" ALTER COLUMN "id" SET DEFAULT uuidv7();--> statement-breakpoint +ALTER TABLE "view_history" ALTER COLUMN "id" SET DEFAULT uuidv7(); diff --git a/apps/server/drizzle/0028_free_human_robot.sql b/apps/server/drizzle/0028_free_human_robot.sql new file mode 100644 index 00000000..a646b350 --- /dev/null +++ b/apps/server/drizzle/0028_free_human_robot.sql @@ -0,0 +1,757 @@ +CREATE TABLE "uuidv7_migration_map" ( + "entity" text NOT NULL, + "old_id" uuid NOT NULL, + "new_id" uuid NOT NULL, + "source_timestamp" timestamp, + "migrated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "uuidv7_migration_map_entity_old_id_pk" PRIMARY KEY("entity","old_id"), + CONSTRAINT "uuidv7_migration_map_entity_new_id_unique" UNIQUE("entity","new_id") +); +--> statement-breakpoint +CREATE TEMP TABLE "_uuidv7_id_map" ( + "entity" text NOT NULL, + "old_id" uuid NOT NULL, + "new_id" uuid NOT NULL, + PRIMARY KEY ("entity", "old_id"), + UNIQUE ("entity", "new_id") +) ON COMMIT DROP; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'media_sources', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM media_sources; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'media', id, + uuidv7( + COALESCE( + NULLIF(created_at, TIMESTAMP '1970-01-01 00:00:00'), + NULLIF(modified_at, TIMESTAMP '1970-01-01 00:00:00'), + transaction_timestamp() AT TIME ZONE 'UTC' + ) + - (transaction_timestamp() AT TIME ZONE 'UTC') + ), + COALESCE( + NULLIF(created_at, TIMESTAMP '1970-01-01 00:00:00'), + NULLIF(modified_at, TIMESTAMP '1970-01-01 00:00:00'), + transaction_timestamp() AT TIME ZONE 'UTC' + ) +FROM media; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'media_regions', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM media_regions; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'ccip_embeddings', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM ccip_embeddings; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'tags', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM tags; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'categories', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM categories; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'projects', id, + uuidv7( + COALESCE(created_at, updated_at, transaction_timestamp() AT TIME ZONE 'UTC') + - (transaction_timestamp() AT TIME ZONE 'UTC') + ), + COALESCE(created_at, updated_at, transaction_timestamp() AT TIME ZONE 'UTC') +FROM projects; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'ips', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM ips; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'characters', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM characters; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'view_history', id, + uuidv7( + COALESCE(viewed_at, transaction_timestamp() AT TIME ZONE 'UTC') + - (transaction_timestamp() AT TIME ZONE 'UTC') + ), + COALESCE(viewed_at, transaction_timestamp() AT TIME ZONE 'UTC') +FROM view_history; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'similar_media', id, + uuidv7( + COALESCE(created_at, transaction_timestamp() AT TIME ZONE 'UTC') + - (transaction_timestamp() AT TIME ZONE 'UTC') + ), + COALESCE(created_at, transaction_timestamp() AT TIME ZONE 'UTC') +FROM similar_media; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'media_relations', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM media_relations; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'authors', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM authors; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'author_accounts', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM author_accounts; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'media_urls', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM media_urls; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'users', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM users; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'collections', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM collections; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'jobs', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM jobs; +--> statement-breakpoint +INSERT INTO "uuidv7_migration_map" ("entity", "old_id", "new_id", "source_timestamp") +SELECT 'search_snapshots', id, + uuidv7(created_at - (transaction_timestamp() AT TIME ZONE 'UTC')), + created_at +FROM search_snapshots; +--> statement-breakpoint +INSERT INTO "_uuidv7_id_map" ("entity", "old_id", "new_id") +SELECT "entity", "old_id", "new_id" +FROM "uuidv7_migration_map"; +--> statement-breakpoint +DO $$ +DECLARE + foreign_key record; +BEGIN + FOR foreign_key IN + SELECT namespace.nspname AS schema_name, relation.relname AS table_name, constraint_row.conname + FROM pg_constraint AS constraint_row + JOIN pg_class AS relation ON relation.oid = constraint_row.conrelid + JOIN pg_namespace AS namespace ON namespace.oid = relation.relnamespace + WHERE constraint_row.contype = 'f' + AND namespace.nspname = 'public' + LOOP + EXECUTE format( + 'ALTER TABLE %I.%I DROP CONSTRAINT %I', + foreign_key.schema_name, + foreign_key.table_name, + foreign_key.conname + ); + END LOOP; +END $$; +--> statement-breakpoint +UPDATE media_sources AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_sources' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE media AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE media_regions AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_regions' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE ccip_embeddings AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'ccip_embeddings' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE tags AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'tags' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE categories AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'categories' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE projects AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'projects' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE ips AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'ips' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE characters AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'characters' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE view_history AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'view_history' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE similar_media AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'similar_media' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE media_relations AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_relations' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE authors AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'authors' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE author_accounts AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'author_accounts' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE media_urls AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_urls' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE users AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'users' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE collections AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'collections' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE jobs AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'jobs' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE search_snapshots AS target +SET id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'search_snapshots' AND target.id = mapping.old_id; +--> statement-breakpoint +UPDATE categories AS target +SET parent_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'categories' AND target.parent_id = mapping.old_id; +--> statement-breakpoint +UPDATE collections AS target +SET user_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'users' AND target.user_id = mapping.old_id; +--> statement-breakpoint +UPDATE jobs AS target +SET source_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_sources' AND target.source_id = mapping.old_id; +--> statement-breakpoint +UPDATE jobs AS target +SET parent_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'jobs' AND target.parent_id = mapping.old_id; +--> statement-breakpoint +UPDATE media AS target +SET source_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_sources' AND target.source_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_regions AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE ccip_embeddings AS target +SET region_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_regions' AND target.region_id = mapping.old_id; +--> statement-breakpoint +UPDATE character_ips AS target +SET character_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'characters' AND target.character_id = mapping.old_id; +--> statement-breakpoint +UPDATE character_ips AS target +SET ip_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'ips' AND target.ip_id = mapping.old_id; +--> statement-breakpoint +UPDATE author_accounts AS target +SET author_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'authors' AND target.author_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_authors AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_authors AS target +SET author_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'authors' AND target.author_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_categories AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_categories AS target +SET category_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'categories' AND target.category_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_characters AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_characters AS target +SET character_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'characters' AND target.character_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_collections AS target +SET collection_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'collections' AND target.collection_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_collections AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_details AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_generation_info AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_ips AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_ips AS target +SET ip_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'ips' AND target.ip_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_projects AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_projects AS target +SET project_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'projects' AND target.project_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_relations AS target +SET parent_media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.parent_media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_relations AS target +SET child_media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.child_media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_sync AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_tags AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_tags AS target +SET tag_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'tags' AND target.tag_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_technical_info AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE media_urls AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +UPDATE tags AS target +SET author_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'authors' AND target.author_id = mapping.old_id; +--> statement-breakpoint +UPDATE similar_media AS target +SET media1_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media1_id = mapping.old_id; +--> statement-breakpoint +UPDATE similar_media AS target +SET media2_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media2_id = mapping.old_id; +--> statement-breakpoint +UPDATE view_history AS target +SET media_id = mapping.new_id +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media' AND target.media_id = mapping.old_id; +--> statement-breakpoint +CREATE OR REPLACE FUNCTION pg_temp.uuidv7_map_text(p_entity text, p_value text) +RETURNS text +LANGUAGE plpgsql +AS $$ +DECLARE + mapped_id uuid; +BEGIN + IF p_value IS NULL OR p_value !~* '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' THEN + RETURN p_value; + END IF; + + SELECT new_id + INTO mapped_id + FROM "_uuidv7_id_map" + WHERE entity = p_entity AND old_id = p_value::uuid; + + RETURN COALESCE(mapped_id::text, p_value); +END; +$$; +--> statement-breakpoint +CREATE OR REPLACE FUNCTION pg_temp.uuidv7_entity_for_key(p_key text) +RETURNS text +LANGUAGE sql +IMMUTABLE +AS $$ + SELECT CASE lower(replace(COALESCE(p_key, ''), '_', '')) + WHEN 'mediaid' THEN 'media' + WHEN 'mediaids' THEN 'media' + WHEN 'targetmediaid' THEN 'media' + WHEN 'anchormediaid' THEN 'media' + WHEN 'similarityanchormediaid' THEN 'media' + WHEN 'parentmediaid' THEN 'media' + WHEN 'childmediaid' THEN 'media' + WHEN 'media1id' THEN 'media' + WHEN 'media2id' THEN 'media' + WHEN 'media' THEN 'media' + WHEN 'mediasourceid' THEN 'media_sources' + WHEN 'sourceid' THEN 'media_sources' + WHEN 'selectedsource' THEN 'media_sources' + WHEN 'targetsourceid' THEN 'media_sources' + WHEN 'source' THEN 'media_sources' + WHEN 'jobid' THEN 'jobs' + WHEN 'jobids' THEN 'jobs' + WHEN 'parentid' THEN 'jobs' + WHEN 'authorid' THEN 'authors' + WHEN 'authorids' THEN 'authors' + WHEN 'author' THEN 'authors' + WHEN 'authors' THEN 'authors' + WHEN 'projectid' THEN 'projects' + WHEN 'projectids' THEN 'projects' + WHEN 'project' THEN 'projects' + WHEN 'projects' THEN 'projects' + WHEN 'ipid' THEN 'ips' + WHEN 'ipids' THEN 'ips' + WHEN 'ip' THEN 'ips' + WHEN 'ips' THEN 'ips' + WHEN 'characterid' THEN 'characters' + WHEN 'characterids' THEN 'characters' + WHEN 'character' THEN 'characters' + WHEN 'characters' THEN 'characters' + WHEN 'categoryid' THEN 'categories' + WHEN 'categoryids' THEN 'categories' + WHEN 'category' THEN 'categories' + WHEN 'categories' THEN 'categories' + WHEN 'tagid' THEN 'tags' + WHEN 'tagids' THEN 'tags' + WHEN 'tag' THEN 'tags' + WHEN 'tags' THEN 'tags' + WHEN 'collectionid' THEN 'collections' + WHEN 'collectionids' THEN 'collections' + WHEN 'collection' THEN 'collections' + WHEN 'collections' THEN 'collections' + WHEN 'userid' THEN 'users' + WHEN 'userids' THEN 'users' + ELSE NULL + END; +$$; +--> statement-breakpoint +CREATE OR REPLACE FUNCTION pg_temp.uuidv7_rewrite_jsonb(p_value jsonb, p_key text DEFAULT NULL) +RETURNS jsonb +LANGUAGE plpgsql +AS $$ +DECLARE + item record; + result jsonb; + entity_name text; + child_value jsonb; + value_text text; +BEGIN + IF p_value IS NULL THEN + RETURN NULL; + END IF; + + CASE jsonb_typeof(p_value) + WHEN 'object' THEN + result := '{}'::jsonb; + FOR item IN SELECT key, value FROM jsonb_each(p_value) + LOOP + IF item.key = 'value' AND p_value->>'type' = 'criterion' THEN + child_value := pg_temp.uuidv7_rewrite_jsonb(item.value, p_value->>'target'); + ELSE + child_value := pg_temp.uuidv7_rewrite_jsonb(item.value, item.key); + END IF; + result := result || jsonb_build_object(item.key, child_value); + END LOOP; + RETURN result; + WHEN 'array' THEN + SELECT COALESCE( + jsonb_agg(pg_temp.uuidv7_rewrite_jsonb(value, p_key) ORDER BY ordinal), + '[]'::jsonb + ) + INTO result + FROM jsonb_array_elements(p_value) WITH ORDINALITY AS elements(value, ordinal); + RETURN result; + WHEN 'string' THEN + entity_name := pg_temp.uuidv7_entity_for_key(p_key); + IF entity_name IS NULL THEN + RETURN p_value; + END IF; + value_text := p_value #>> '{}'; + RETURN to_jsonb(pg_temp.uuidv7_map_text(entity_name, value_text)); + ELSE + RETURN p_value; + END CASE; +END; +$$; +--> statement-breakpoint +UPDATE jobs +SET payload = pg_temp.uuidv7_rewrite_jsonb(payload) +WHERE payload IS NOT NULL; +--> statement-breakpoint +UPDATE jobs +SET result = pg_temp.uuidv7_rewrite_jsonb(result) +WHERE result IS NOT NULL; +--> statement-breakpoint +UPDATE search_snapshots +SET state = pg_temp.uuidv7_rewrite_jsonb(state) +WHERE state IS NOT NULL; +--> statement-breakpoint +UPDATE presets +SET value = pg_temp.uuidv7_rewrite_jsonb(value) +WHERE value IS NOT NULL; +--> statement-breakpoint +UPDATE jobs AS target +SET artifact_path = replace(target.artifact_path, mapping.old_id::text, mapping.new_id::text) +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'jobs' + AND target.id = mapping.new_id + AND target.artifact_path IS NOT NULL + AND target.artifact_path LIKE '%' || mapping.old_id::text || '%'; +--> statement-breakpoint +UPDATE jobs AS target +SET payload = jsonb_set( + target.payload, + '{inputPath}', + to_jsonb(replace(target.payload->>'inputPath', mapping.old_id::text, mapping.new_id::text)), + true +) +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'jobs' + AND target.id = mapping.new_id + AND target.payload ? 'inputPath' + AND target.payload->>'inputPath' LIKE '%' || mapping.old_id::text || '%'; +--> statement-breakpoint +UPDATE jobs AS target +SET artifact_file_name = replace(target.artifact_file_name, mapping.old_id::text, mapping.new_id::text) +FROM "_uuidv7_id_map" AS mapping +WHERE mapping.entity = 'media_sources' + AND target.artifact_file_name IS NOT NULL + AND target.artifact_file_name LIKE '%' || mapping.old_id::text || '%'; +--> statement-breakpoint +ALTER TABLE categories + ADD CONSTRAINT categories_parent_id_categories_id_fk + FOREIGN KEY (parent_id) REFERENCES categories(id) ON DELETE NO ACTION ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE collections + ADD CONSTRAINT collections_user_id_users_id_fk + FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE jobs + ADD CONSTRAINT jobs_source_id_media_sources_id_fk + FOREIGN KEY (source_id) REFERENCES media_sources(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE jobs + ADD CONSTRAINT jobs_parent_id_jobs_id_fk + FOREIGN KEY (parent_id) REFERENCES jobs(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_authors + ADD CONSTRAINT media_authors_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_authors + ADD CONSTRAINT media_authors_author_id_authors_id_fk + FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_categories + ADD CONSTRAINT media_categories_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_categories + ADD CONSTRAINT media_categories_category_id_categories_id_fk + FOREIGN KEY (category_id) REFERENCES categories(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_characters + ADD CONSTRAINT media_characters_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_characters + ADD CONSTRAINT media_characters_character_id_characters_id_fk + FOREIGN KEY (character_id) REFERENCES characters(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_collections + ADD CONSTRAINT media_collections_collection_id_collections_id_fk + FOREIGN KEY (collection_id) REFERENCES collections(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_collections + ADD CONSTRAINT media_collections_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_details + ADD CONSTRAINT media_details_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_generation_info + ADD CONSTRAINT media_generation_info_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_ips + ADD CONSTRAINT media_ips_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_ips + ADD CONSTRAINT media_ips_ip_id_ips_id_fk + FOREIGN KEY (ip_id) REFERENCES ips(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_projects + ADD CONSTRAINT media_projects_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_projects + ADD CONSTRAINT media_projects_project_id_projects_id_fk + FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_relations + ADD CONSTRAINT media_relations_parent_media_id_media_id_fk + FOREIGN KEY (parent_media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_relations + ADD CONSTRAINT media_relations_child_media_id_media_id_fk + FOREIGN KEY (child_media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_sync + ADD CONSTRAINT media_sync_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_tags + ADD CONSTRAINT media_tags_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_tags + ADD CONSTRAINT media_tags_tag_id_tags_id_fk + FOREIGN KEY (tag_id) REFERENCES tags(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_technical_info + ADD CONSTRAINT media_technical_info_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_urls + ADD CONSTRAINT media_urls_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media + ADD CONSTRAINT media_source_id_media_sources_id_fk + FOREIGN KEY (source_id) REFERENCES media_sources(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE similar_media + ADD CONSTRAINT similar_media_media1_id_media_id_fk + FOREIGN KEY (media1_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE similar_media + ADD CONSTRAINT similar_media_media2_id_media_id_fk + FOREIGN KEY (media2_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE tags + ADD CONSTRAINT tags_author_id_authors_id_fk + FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE SET NULL ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE view_history + ADD CONSTRAINT view_history_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE character_ips + ADD CONSTRAINT character_ips_character_id_characters_id_fk + FOREIGN KEY (character_id) REFERENCES characters(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE character_ips + ADD CONSTRAINT character_ips_ip_id_ips_id_fk + FOREIGN KEY (ip_id) REFERENCES ips(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE author_accounts + ADD CONSTRAINT author_accounts_author_id_authors_id_fk + FOREIGN KEY (author_id) REFERENCES authors(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE ccip_embeddings + ADD CONSTRAINT ccip_embeddings_region_id_media_regions_id_fk + FOREIGN KEY (region_id) REFERENCES media_regions(id) ON DELETE CASCADE ON UPDATE NO ACTION; +--> statement-breakpoint +ALTER TABLE media_regions + ADD CONSTRAINT media_regions_media_id_media_id_fk + FOREIGN KEY (media_id) REFERENCES media(id) ON DELETE CASCADE ON UPDATE NO ACTION; diff --git a/apps/server/drizzle/meta/0027_snapshot.json b/apps/server/drizzle/meta/0027_snapshot.json new file mode 100644 index 00000000..431648be --- /dev/null +++ b/apps/server/drizzle/meta/0027_snapshot.json @@ -0,0 +1,3391 @@ +{ + "id": "2b7f60d1-2079-4a0a-8311-0b28278cdaa3", + "prevId": "ed86b785-ed10-4de8-94e6-a389bee87ea7", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.author_accounts": { + "name": "author_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "author_platform", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "profile_url": { + "name": "profile_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_author_accounts_author_id": { + "name": "idx_author_accounts_author_id", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_author_accounts_platform_account_unique": { + "name": "idx_author_accounts_platform_account_unique", + "columns": [ + { + "expression": "platform", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "author_accounts_author_id_authors_id_fk": { + "name": "author_accounts_author_id_authors_id_fk", + "tableFrom": "author_accounts", + "tableTo": "authors", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.authors": { + "name": "authors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_authors_account_id": { + "name": "idx_authors_account_id", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_authors_name": { + "name": "idx_authors_name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.categories": { + "name": "categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'#808080'" + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "categories_parent_id_categories_id_fk": { + "name": "categories_parent_id_categories_id_fk", + "tableFrom": "categories", + "tableTo": "categories", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "categories_name_unique": { + "name": "categories_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ccip_embeddings": { + "name": "ccip_embeddings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "region_id": { + "name": "region_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "embedding": { + "name": "embedding", + "type": "vector(768)", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "embedding_version": { + "name": "embedding_version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "media_modified_at": { + "name": "media_modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "extracted_at": { + "name": "extracted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_ccip_embeddings_region_id": { + "name": "idx_ccip_embeddings_region_id", + "columns": [ + { + "expression": "region_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_ccip_embeddings_embedding_cosine": { + "name": "idx_ccip_embeddings_embedding_cosine", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + } + }, + "foreignKeys": { + "ccip_embeddings_region_id_media_regions_id_fk": { + "name": "ccip_embeddings_region_id_media_regions_id_fk", + "tableFrom": "ccip_embeddings", + "tableTo": "media_regions", + "columnsFrom": [ + "region_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uq_ccip_embeddings_region_model_version": { + "name": "uq_ccip_embeddings_region_model_version", + "nullsNotDistinct": false, + "columns": [ + "region_id", + "model", + "embedding_version" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.character_ips": { + "name": "character_ips", + "schema": "", + "columns": { + "character_id": { + "name": "character_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "ip_id": { + "name": "ip_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_character_ips_ip_id_character_id": { + "name": "idx_character_ips_ip_id_character_id", + "columns": [ + { + "expression": "ip_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "character_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "character_ips_character_id_characters_id_fk": { + "name": "character_ips_character_id_characters_id_fk", + "tableFrom": "character_ips", + "tableTo": "characters", + "columnsFrom": [ + "character_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "character_ips_ip_id_ips_id_fk": { + "name": "character_ips_ip_id_ips_id_fk", + "tableFrom": "character_ips", + "tableTo": "ips", + "columnsFrom": [ + "ip_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "character_ips_character_id_ip_id_pk": { + "name": "character_ips_character_id_ip_id_pk", + "columns": [ + "character_id", + "ip_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.characters": { + "name": "characters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "aliases": { + "name": "aliases", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "characters_name_unique": { + "name": "characters_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.collections": { + "name": "collections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "collections_user_id_users_id_fk": { + "name": "collections_user_id_users_id_fk", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ips": { + "name": "ips", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "ips_name_unique": { + "name": "ips_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.jobs": { + "name": "jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "job_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_requested_at": { + "name": "cancel_requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "artifact_path": { + "name": "artifact_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifact_file_name": { + "name": "artifact_file_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifact_content_type": { + "name": "artifact_content_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifact_size": { + "name": "artifact_size", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "artifact_expires_at": { + "name": "artifact_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_jobs_pending_import_request": { + "name": "idx_jobs_pending_import_request", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" = 'pending' AND \"jobs\".\"type\" = 'import_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_pending_created": { + "name": "idx_jobs_pending_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" = 'pending' AND \"jobs\".\"type\" <> 'import_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_pending_type_created": { + "name": "idx_jobs_pending_type_created", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" = 'pending' AND \"jobs\".\"type\" <> 'import_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_jobs_active_thumbnail": { + "name": "uq_jobs_active_thumbnail", + "columns": [ + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "(\"payload\"->>'mediaId')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "(\"payload\"->>'size')", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"jobs\".\"type\" = 'generate_thumbnail'\n\t\t\t\t\tAND \"jobs\".\"status\" IN ('pending', 'in_progress')\n\t\t\t\t\tAND \"jobs\".\"source_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_cancelable": { + "name": "idx_jobs_cancelable", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" IN ('pending', 'in_progress')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_artifact_expiry": { + "name": "idx_jobs_artifact_expiry", + "columns": [ + { + "expression": "artifact_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"artifact_path\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "jobs_source_id_media_sources_id_fk": { + "name": "jobs_source_id_media_sources_id_fk", + "tableFrom": "jobs", + "tableTo": "media_sources", + "columnsFrom": [ + "source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "jobs_parent_id_jobs_id_fk": { + "name": "jobs_parent_id_jobs_id_fk", + "tableFrom": "jobs", + "tableTo": "jobs", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_authors": { + "name": "media_authors", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_media_authors_author_id_media_id": { + "name": "idx_media_authors_author_id_media_id", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_authors_media_id_media_id_fk": { + "name": "media_authors_media_id_media_id_fk", + "tableFrom": "media_authors", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_authors_author_id_authors_id_fk": { + "name": "media_authors_author_id_authors_id_fk", + "tableFrom": "media_authors", + "tableTo": "authors", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_authors_media_id_author_id_pk": { + "name": "media_authors_media_id_author_id_pk", + "columns": [ + "media_id", + "author_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_categories": { + "name": "media_categories", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_media_categories_category_id_media_id": { + "name": "idx_media_categories_category_id_media_id", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_categories_media_id_media_id_fk": { + "name": "media_categories_media_id_media_id_fk", + "tableFrom": "media_categories", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_categories_category_id_categories_id_fk": { + "name": "media_categories_category_id_categories_id_fk", + "tableFrom": "media_categories", + "tableTo": "categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_categories_media_id_category_id_pk": { + "name": "media_categories_media_id_category_id_pk", + "columns": [ + "media_id", + "category_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_characters": { + "name": "media_characters", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "character_id": { + "name": "character_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_media_characters_character_id_media_id": { + "name": "idx_media_characters_character_id_media_id", + "columns": [ + { + "expression": "character_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_characters_media_id_media_id_fk": { + "name": "media_characters_media_id_media_id_fk", + "tableFrom": "media_characters", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_characters_character_id_characters_id_fk": { + "name": "media_characters_character_id_characters_id_fk", + "tableFrom": "media_characters", + "tableTo": "characters", + "columnsFrom": [ + "character_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_characters_media_id_character_id_pk": { + "name": "media_characters_media_id_character_id_pk", + "columns": [ + "media_id", + "character_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_collections": { + "name": "media_collections", + "schema": "", + "columns": { + "collection_id": { + "name": "collection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "display_order": { + "name": "display_order", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_media_collections_media_id": { + "name": "idx_media_collections_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_collections_collection_id_collections_id_fk": { + "name": "media_collections_collection_id_collections_id_fk", + "tableFrom": "media_collections", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_collections_media_id_media_id_fk": { + "name": "media_collections_media_id_media_id_fk", + "tableFrom": "media_collections", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_collections_collection_id_media_id_pk": { + "name": "media_collections_collection_id_media_id_pk", + "columns": [ + "collection_id", + "media_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_details": { + "name": "media_details", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "favorite": { + "name": "favorite", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "view_count": { + "name": "view_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_viewed_at": { + "name": "last_viewed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "'1970-01-01 00:00:00'" + } + }, + "indexes": { + "idx_media_details_rating": { + "name": "idx_media_details_rating", + "columns": [ + { + "expression": "rating", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_details_favorite": { + "name": "idx_media_details_favorite", + "columns": [ + { + "expression": "favorite", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_details_view_count": { + "name": "idx_media_details_view_count", + "columns": [ + { + "expression": "view_count", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_details_media_id_media_id_fk": { + "name": "media_details_media_id_media_id_fk", + "tableFrom": "media_details", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_generation_info": { + "name": "media_generation_info", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "negative_prompt": { + "name": "negative_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow": { + "name": "workflow", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "loras": { + "name": "loras", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "vae": { + "name": "vae", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hypernetworks": { + "name": "hypernetworks", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "embeddings": { + "name": "embeddings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "ai_generated": { + "name": "ai_generated", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "seed": { + "name": "seed", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": -1 + }, + "cfg_scale": { + "name": "cfg_scale", + "type": "real", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "steps": { + "name": "steps", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + } + }, + "indexes": { + "idx_media_generation_info_metadata": { + "name": "idx_media_generation_info_metadata", + "columns": [ + { + "expression": "metadata", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_generation_info_ai_generated": { + "name": "idx_media_generation_info_ai_generated", + "columns": [ + { + "expression": "ai_generated", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_generation_info_model_name": { + "name": "idx_media_generation_info_model_name", + "columns": [ + { + "expression": "model_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_generation_info_media_id_media_id_fk": { + "name": "media_generation_info_media_id_media_id_fk", + "tableFrom": "media_generation_info", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_ips": { + "name": "media_ips", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "ip_id": { + "name": "ip_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_media_ips_ip_id_media_id": { + "name": "idx_media_ips_ip_id_media_id", + "columns": [ + { + "expression": "ip_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_ips_media_id_media_id_fk": { + "name": "media_ips_media_id_media_id_fk", + "tableFrom": "media_ips", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_ips_ip_id_ips_id_fk": { + "name": "media_ips_ip_id_ips_id_fk", + "tableFrom": "media_ips", + "tableTo": "ips", + "columnsFrom": [ + "ip_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_ips_media_id_ip_id_pk": { + "name": "media_ips_media_id_ip_id_pk", + "columns": [ + "media_id", + "ip_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_projects": { + "name": "media_projects", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_media_projects_project_id_media_id": { + "name": "idx_media_projects_project_id_media_id", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_projects_media_id_media_id_fk": { + "name": "media_projects_media_id_media_id_fk", + "tableFrom": "media_projects", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_projects_project_id_projects_id_fk": { + "name": "media_projects_project_id_projects_id_fk", + "tableFrom": "media_projects", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_projects_media_id_project_id_pk": { + "name": "media_projects_media_id_project_id_pk", + "columns": [ + "media_id", + "project_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_regions": { + "name": "media_regions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "media_region_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "x": { + "name": "x", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "y": { + "name": "y", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source_modified_at": { + "name": "source_modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "detector": { + "name": "detector", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "detector_version": { + "name": "detector_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "score": { + "name": "score", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_media_regions_media_id": { + "name": "idx_media_regions_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_media_regions_full_media_id": { + "name": "uq_media_regions_full_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"media_regions\".\"kind\" = 'full'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_regions_media_id_media_id_fk": { + "name": "media_regions_media_id_media_id_fk", + "tableFrom": "media_regions", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "media_regions_bbox_by_kind": { + "name": "media_regions_bbox_by_kind", + "value": "(\n\t\t\t\t(\"media_regions\".\"kind\" = 'full' AND \"media_regions\".\"x\" IS NULL AND \"media_regions\".\"y\" IS NULL AND \"media_regions\".\"width\" IS NULL AND \"media_regions\".\"height\" IS NULL)\n\t\t\t\tOR\n\t\t\t\t(\"media_regions\".\"kind\" <> 'full' AND \"media_regions\".\"x\" IS NOT NULL AND \"media_regions\".\"y\" IS NOT NULL AND \"media_regions\".\"width\" IS NOT NULL AND \"media_regions\".\"height\" IS NOT NULL\n\t\t\t\t\tAND \"media_regions\".\"x\" >= 0 AND \"media_regions\".\"y\" >= 0 AND \"media_regions\".\"width\" > 0 AND \"media_regions\".\"height\" > 0\n\t\t\t\t\tAND \"media_regions\".\"x\" + \"media_regions\".\"width\" <= 1 AND \"media_regions\".\"y\" + \"media_regions\".\"height\" <= 1)\n\t\t\t)" + }, + "media_regions_score_range": { + "name": "media_regions_score_range", + "value": "\"media_regions\".\"score\" IS NULL OR (\"media_regions\".\"score\" >= 0 AND \"media_regions\".\"score\" <= 1)" + } + }, + "isRLSEnabled": false + }, + "public.media_relations": { + "name": "media_relations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "parent_media_id": { + "name": "parent_media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "child_media_id": { + "name": "child_media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "relation_type": { + "name": "relation_type", + "type": "media_relation_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "order_index": { + "name": "order_index", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_media_relations_child": { + "name": "idx_media_relations_child", + "columns": [ + { + "expression": "child_media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_relations_type": { + "name": "idx_media_relations_type", + "columns": [ + { + "expression": "relation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_relations_parent_media_id_media_id_fk": { + "name": "media_relations_parent_media_id_media_id_fk", + "tableFrom": "media_relations", + "tableTo": "media", + "columnsFrom": [ + "parent_media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_relations_child_media_id_media_id_fk": { + "name": "media_relations_child_media_id_media_id_fk", + "tableFrom": "media_relations", + "tableTo": "media", + "columnsFrom": [ + "child_media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "parent_child_type_unique": { + "name": "parent_child_type_unique", + "nullsNotDistinct": false, + "columns": [ + "parent_media_id", + "child_media_id", + "relation_type" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_sources": { + "name": "media_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "media_source_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "connection_info": { + "name": "connection_info", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "sync_status": { + "name": "sync_status", + "type": "media_source_sync_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'idle'" + }, + "last_sync_started_at": { + "name": "last_sync_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_completed_at": { + "name": "last_sync_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_sync": { + "name": "media_sync", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "sync_status": { + "name": "sync_status", + "type": "media_sync_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'synced'" + }, + "backup_urls": { + "name": "backup_urls", + "type": "text[]", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "sync_attempts": { + "name": "sync_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "media_sync_media_id_media_id_fk": { + "name": "media_sync_media_id_media_id_fk", + "tableFrom": "media_sync", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_tags": { + "name": "media_tags", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "tag_type": { + "name": "tag_type", + "type": "tag_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'positive'" + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_media_tags_tag_id_tag_type_media_id": { + "name": "idx_media_tags_tag_id_tag_type_media_id", + "columns": [ + { + "expression": "tag_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_tags_media_id_media_id_fk": { + "name": "media_tags_media_id_media_id_fk", + "tableFrom": "media_tags", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_tags_tag_id_tags_id_fk": { + "name": "media_tags_tag_id_tags_id_fk", + "tableFrom": "media_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_tags_media_id_tag_id_tag_type_pk": { + "name": "media_tags_media_id_tag_id_tag_type_pk", + "columns": [ + "media_id", + "tag_id", + "tag_type" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_technical_info": { + "name": "media_technical_info", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "color_profile": { + "name": "color_profile", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "exif_data": { + "name": "exif_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "hash_md5": { + "name": "hash_md5", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "hash_perceptual": { + "name": "hash_perceptual", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "duration_seconds": { + "name": "duration_seconds", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "frame_rate": { + "name": "frame_rate", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "bitrate_kbps": { + "name": "bitrate_kbps", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "video_codec": { + "name": "video_codec", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "audio_codec": { + "name": "audio_codec", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_media_technical_info_hash_md5": { + "name": "idx_media_technical_info_hash_md5", + "columns": [ + { + "expression": "hash_md5", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_technical_info_media_id_media_id_fk": { + "name": "media_technical_info_media_id_media_id_fk", + "tableFrom": "media_technical_info", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_urls": { + "name": "media_urls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_media_urls_media_id": { + "name": "idx_media_urls_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_urls_url": { + "name": "idx_media_urls_url", + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_urls_media_id_url_unique": { + "name": "idx_media_urls_media_id_url_unique", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_urls_media_id_media_id_fk": { + "name": "media_urls_media_id_media_id_fk", + "tableFrom": "media_urls", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media": { + "name": "media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "source_id": { + "name": "source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "media_type": { + "name": "media_type", + "type": "media_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified_at": { + "name": "modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "indexed_at": { + "name": "indexed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "status": { + "name": "status", + "type": "media_organization_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + } + }, + "indexes": { + "idx_media_source_id": { + "name": "idx_media_source_id", + "columns": [ + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_file_size": { + "name": "idx_media_file_size", + "columns": [ + { + "expression": "file_size", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_file_name": { + "name": "idx_media_file_name", + "columns": [ + { + "expression": "file_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_created_at": { + "name": "idx_media_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_description": { + "name": "idx_media_description", + "columns": [ + { + "expression": "description", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_source_id_media_sources_id_fk": { + "name": "media_source_id_media_sources_id_fk", + "tableFrom": "media", + "tableTo": "media_sources", + "columnsFrom": [ + "source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "source_id_file_path_unique": { + "name": "source_id_file_path_unique", + "nullsNotDistinct": false, + "columns": [ + "source_id", + "file_path" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.presets": { + "name": "presets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "sort": { + "name": "sort", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "order": { + "name": "order", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mode": { + "name": "mode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "presets_name_unique": { + "name": "presets_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_projects_name": { + "name": "idx_projects_name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "projects_name_unique": { + "name": "projects_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.search_snapshots": { + "name": "search_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_search_snapshots_created_at": { + "name": "idx_search_snapshots_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "search_snapshots_fingerprint_unique": { + "name": "search_snapshots_fingerprint_unique", + "nullsNotDistinct": false, + "columns": [ + "fingerprint" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.similar_media": { + "name": "similar_media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media1_id": { + "name": "media1_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "media2_id": { + "name": "media2_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "similarity_score": { + "name": "similarity_score", + "type": "real", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "algorithm": { + "name": "algorithm", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'perceptual'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_similar_media_score": { + "name": "idx_similar_media_score", + "columns": [ + { + "expression": "similarity_score", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "similar_media_media1_id_media_id_fk": { + "name": "similar_media_media1_id_media_id_fk", + "tableFrom": "similar_media", + "tableTo": "media", + "columnsFrom": [ + "media1_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "similar_media_media2_id_media_id_fk": { + "name": "similar_media_media2_id_media_id_fk", + "tableFrom": "similar_media", + "tableTo": "media", + "columnsFrom": [ + "media2_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "media1Id_media2Id_algorithm_unique": { + "name": "media1Id_media2Id_algorithm_unique", + "nullsNotDistinct": false, + "columns": [ + "media1_id", + "media2_id", + "algorithm" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attribute": { + "name": "attribute", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_tags_author_id": { + "name": "idx_tags_author_id", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tags_author_id_authors_id_fk": { + "name": "tags_author_id_authors_id_fk", + "tableFrom": "tags", + "tableTo": "authors", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tags_name_unique": { + "name": "tags_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_history": { + "name": "view_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "viewed_at": { + "name": "viewed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + } + }, + "indexes": {}, + "foreignKeys": { + "view_history_media_id_media_id_fk": { + "name": "view_history_media_id_media_id_fk", + "tableFrom": "view_history", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.author_platform": { + "name": "author_platform", + "schema": "public", + "values": [ + "twitter", + "pixiv-fanbox", + "danbooru" + ] + }, + "public.job_status": { + "name": "job_status", + "schema": "public", + "values": [ + "pending", + "in_progress", + "completed", + "failed", + "cancelled" + ] + }, + "public.media_organization_status": { + "name": "media_organization_status", + "schema": "public", + "values": [ + "active", + "archived", + "deleted" + ] + }, + "public.media_region_kind": { + "name": "media_region_kind", + "schema": "public", + "values": [ + "full", + "person", + "manual" + ] + }, + "public.media_relation_type": { + "name": "media_relation_type", + "schema": "public", + "values": [ + "variant", + "version", + "page", + "derivative", + "edit", + "source" + ] + }, + "public.media_source_sync_status": { + "name": "media_source_sync_status", + "schema": "public", + "values": [ + "idle", + "syncing", + "error" + ] + }, + "public.media_source_type": { + "name": "media_source_type", + "schema": "public", + "values": [ + "local", + "sftp", + "s3" + ] + }, + "public.media_sync_status": { + "name": "media_sync_status", + "schema": "public", + "values": [ + "synced", + "pending", + "failed" + ] + }, + "public.media_type": { + "name": "media_type", + "schema": "public", + "values": [ + "image", + "video", + "audio" + ] + }, + "public.tag_type": { + "name": "tag_type", + "schema": "public", + "values": [ + "positive", + "negative" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/apps/server/drizzle/meta/0028_snapshot.json b/apps/server/drizzle/meta/0028_snapshot.json new file mode 100644 index 00000000..4ecac0ea --- /dev/null +++ b/apps/server/drizzle/meta/0028_snapshot.json @@ -0,0 +1,3452 @@ +{ + "id": "737bc2cb-3279-4656-88aa-7d0072ecda50", + "prevId": "2b7f60d1-2079-4a0a-8311-0b28278cdaa3", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.author_accounts": { + "name": "author_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "author_platform", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "profile_url": { + "name": "profile_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_author_accounts_author_id": { + "name": "idx_author_accounts_author_id", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_author_accounts_platform_account_unique": { + "name": "idx_author_accounts_platform_account_unique", + "columns": [ + { + "expression": "platform", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "author_accounts_author_id_authors_id_fk": { + "name": "author_accounts_author_id_authors_id_fk", + "tableFrom": "author_accounts", + "tableTo": "authors", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.authors": { + "name": "authors", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_authors_account_id": { + "name": "idx_authors_account_id", + "columns": [ + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_authors_name": { + "name": "idx_authors_name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.categories": { + "name": "categories", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'#808080'" + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "categories_parent_id_categories_id_fk": { + "name": "categories_parent_id_categories_id_fk", + "tableFrom": "categories", + "tableTo": "categories", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "categories_name_unique": { + "name": "categories_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ccip_embeddings": { + "name": "ccip_embeddings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "region_id": { + "name": "region_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "embedding": { + "name": "embedding", + "type": "vector(768)", + "primaryKey": false, + "notNull": true + }, + "model": { + "name": "model", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "embedding_version": { + "name": "embedding_version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "media_modified_at": { + "name": "media_modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "extracted_at": { + "name": "extracted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_ccip_embeddings_region_id": { + "name": "idx_ccip_embeddings_region_id", + "columns": [ + { + "expression": "region_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_ccip_embeddings_embedding_cosine": { + "name": "idx_ccip_embeddings_embedding_cosine", + "columns": [ + { + "expression": "embedding", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + } + }, + "foreignKeys": { + "ccip_embeddings_region_id_media_regions_id_fk": { + "name": "ccip_embeddings_region_id_media_regions_id_fk", + "tableFrom": "ccip_embeddings", + "tableTo": "media_regions", + "columnsFrom": [ + "region_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "uq_ccip_embeddings_region_model_version": { + "name": "uq_ccip_embeddings_region_model_version", + "nullsNotDistinct": false, + "columns": [ + "region_id", + "model", + "embedding_version" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.character_ips": { + "name": "character_ips", + "schema": "", + "columns": { + "character_id": { + "name": "character_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "ip_id": { + "name": "ip_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_character_ips_ip_id_character_id": { + "name": "idx_character_ips_ip_id_character_id", + "columns": [ + { + "expression": "ip_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "character_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "character_ips_character_id_characters_id_fk": { + "name": "character_ips_character_id_characters_id_fk", + "tableFrom": "character_ips", + "tableTo": "characters", + "columnsFrom": [ + "character_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "character_ips_ip_id_ips_id_fk": { + "name": "character_ips_ip_id_ips_id_fk", + "tableFrom": "character_ips", + "tableTo": "ips", + "columnsFrom": [ + "ip_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "character_ips_character_id_ip_id_pk": { + "name": "character_ips_character_id_ip_id_pk", + "columns": [ + "character_id", + "ip_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.characters": { + "name": "characters", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "aliases": { + "name": "aliases", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "characters_name_unique": { + "name": "characters_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.collections": { + "name": "collections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "user_id": { + "name": "user_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "collections_user_id_users_id_fk": { + "name": "collections_user_id_users_id_fk", + "tableFrom": "collections", + "tableTo": "users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.ips": { + "name": "ips", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "ips_name_unique": { + "name": "ips_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.jobs": { + "name": "jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "job_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "parent_id": { + "name": "parent_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "cancel_requested_at": { + "name": "cancel_requested_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "cancelled_at": { + "name": "cancelled_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "artifact_path": { + "name": "artifact_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifact_file_name": { + "name": "artifact_file_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifact_content_type": { + "name": "artifact_content_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "artifact_size": { + "name": "artifact_size", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "artifact_expires_at": { + "name": "artifact_expires_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_jobs_pending_import_request": { + "name": "idx_jobs_pending_import_request", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" = 'pending' AND \"jobs\".\"type\" = 'import_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_pending_created": { + "name": "idx_jobs_pending_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" = 'pending' AND \"jobs\".\"type\" <> 'import_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_pending_type_created": { + "name": "idx_jobs_pending_type_created", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" = 'pending' AND \"jobs\".\"type\" <> 'import_request'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_jobs_active_thumbnail": { + "name": "uq_jobs_active_thumbnail", + "columns": [ + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "(\"payload\"->>'mediaId')", + "asc": true, + "isExpression": true, + "nulls": "last" + }, + { + "expression": "(\"payload\"->>'size')", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"jobs\".\"type\" = 'generate_thumbnail'\n\t\t\t\t\tAND \"jobs\".\"status\" IN ('pending', 'in_progress')\n\t\t\t\t\tAND \"jobs\".\"source_id\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_cancelable": { + "name": "idx_jobs_cancelable", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"status\" IN ('pending', 'in_progress')", + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_jobs_artifact_expiry": { + "name": "idx_jobs_artifact_expiry", + "columns": [ + { + "expression": "artifact_expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "where": "\"jobs\".\"artifact_path\" IS NOT NULL", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "jobs_source_id_media_sources_id_fk": { + "name": "jobs_source_id_media_sources_id_fk", + "tableFrom": "jobs", + "tableTo": "media_sources", + "columnsFrom": [ + "source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "jobs_parent_id_jobs_id_fk": { + "name": "jobs_parent_id_jobs_id_fk", + "tableFrom": "jobs", + "tableTo": "jobs", + "columnsFrom": [ + "parent_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_authors": { + "name": "media_authors", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_media_authors_author_id_media_id": { + "name": "idx_media_authors_author_id_media_id", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_authors_media_id_media_id_fk": { + "name": "media_authors_media_id_media_id_fk", + "tableFrom": "media_authors", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_authors_author_id_authors_id_fk": { + "name": "media_authors_author_id_authors_id_fk", + "tableFrom": "media_authors", + "tableTo": "authors", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_authors_media_id_author_id_pk": { + "name": "media_authors_media_id_author_id_pk", + "columns": [ + "media_id", + "author_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_categories": { + "name": "media_categories", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_media_categories_category_id_media_id": { + "name": "idx_media_categories_category_id_media_id", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_categories_media_id_media_id_fk": { + "name": "media_categories_media_id_media_id_fk", + "tableFrom": "media_categories", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_categories_category_id_categories_id_fk": { + "name": "media_categories_category_id_categories_id_fk", + "tableFrom": "media_categories", + "tableTo": "categories", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_categories_media_id_category_id_pk": { + "name": "media_categories_media_id_category_id_pk", + "columns": [ + "media_id", + "category_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_characters": { + "name": "media_characters", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "character_id": { + "name": "character_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_media_characters_character_id_media_id": { + "name": "idx_media_characters_character_id_media_id", + "columns": [ + { + "expression": "character_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_characters_media_id_media_id_fk": { + "name": "media_characters_media_id_media_id_fk", + "tableFrom": "media_characters", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_characters_character_id_characters_id_fk": { + "name": "media_characters_character_id_characters_id_fk", + "tableFrom": "media_characters", + "tableTo": "characters", + "columnsFrom": [ + "character_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_characters_media_id_character_id_pk": { + "name": "media_characters_media_id_character_id_pk", + "columns": [ + "media_id", + "character_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_collections": { + "name": "media_collections", + "schema": "", + "columns": { + "collection_id": { + "name": "collection_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "display_order": { + "name": "display_order", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_media_collections_media_id": { + "name": "idx_media_collections_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_collections_collection_id_collections_id_fk": { + "name": "media_collections_collection_id_collections_id_fk", + "tableFrom": "media_collections", + "tableTo": "collections", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_collections_media_id_media_id_fk": { + "name": "media_collections_media_id_media_id_fk", + "tableFrom": "media_collections", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_collections_collection_id_media_id_pk": { + "name": "media_collections_collection_id_media_id_pk", + "columns": [ + "collection_id", + "media_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_details": { + "name": "media_details", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "favorite": { + "name": "favorite", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "view_count": { + "name": "view_count", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_viewed_at": { + "name": "last_viewed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "'1970-01-01 00:00:00'" + } + }, + "indexes": { + "idx_media_details_rating": { + "name": "idx_media_details_rating", + "columns": [ + { + "expression": "rating", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_details_favorite": { + "name": "idx_media_details_favorite", + "columns": [ + { + "expression": "favorite", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_details_view_count": { + "name": "idx_media_details_view_count", + "columns": [ + { + "expression": "view_count", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_details_media_id_media_id_fk": { + "name": "media_details_media_id_media_id_fk", + "tableFrom": "media_details", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_generation_info": { + "name": "media_generation_info", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "prompt": { + "name": "prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "negative_prompt": { + "name": "negative_prompt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "workflow": { + "name": "workflow", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "loras": { + "name": "loras", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "vae": { + "name": "vae", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "hypernetworks": { + "name": "hypernetworks", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "embeddings": { + "name": "embeddings", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "ai_generated": { + "name": "ai_generated", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "model_name": { + "name": "model_name", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "seed": { + "name": "seed", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": -1 + }, + "cfg_scale": { + "name": "cfg_scale", + "type": "real", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "steps": { + "name": "steps", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + } + }, + "indexes": { + "idx_media_generation_info_metadata": { + "name": "idx_media_generation_info_metadata", + "columns": [ + { + "expression": "metadata", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_generation_info_ai_generated": { + "name": "idx_media_generation_info_ai_generated", + "columns": [ + { + "expression": "ai_generated", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_generation_info_model_name": { + "name": "idx_media_generation_info_model_name", + "columns": [ + { + "expression": "model_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_generation_info_media_id_media_id_fk": { + "name": "media_generation_info_media_id_media_id_fk", + "tableFrom": "media_generation_info", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_ips": { + "name": "media_ips", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "ip_id": { + "name": "ip_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_media_ips_ip_id_media_id": { + "name": "idx_media_ips_ip_id_media_id", + "columns": [ + { + "expression": "ip_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_ips_media_id_media_id_fk": { + "name": "media_ips_media_id_media_id_fk", + "tableFrom": "media_ips", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_ips_ip_id_ips_id_fk": { + "name": "media_ips_ip_id_ips_id_fk", + "tableFrom": "media_ips", + "tableTo": "ips", + "columnsFrom": [ + "ip_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_ips_media_id_ip_id_pk": { + "name": "media_ips_media_id_ip_id_pk", + "columns": [ + "media_id", + "ip_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_projects": { + "name": "media_projects", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "project_id": { + "name": "project_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "idx_media_projects_project_id_media_id": { + "name": "idx_media_projects_project_id_media_id", + "columns": [ + { + "expression": "project_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_projects_media_id_media_id_fk": { + "name": "media_projects_media_id_media_id_fk", + "tableFrom": "media_projects", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_projects_project_id_projects_id_fk": { + "name": "media_projects_project_id_projects_id_fk", + "tableFrom": "media_projects", + "tableTo": "projects", + "columnsFrom": [ + "project_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_projects_media_id_project_id_pk": { + "name": "media_projects_media_id_project_id_pk", + "columns": [ + "media_id", + "project_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_regions": { + "name": "media_regions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "media_region_kind", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "x": { + "name": "x", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "y": { + "name": "y", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "width": { + "name": "width", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source_modified_at": { + "name": "source_modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "detector": { + "name": "detector", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "detector_version": { + "name": "detector_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "score": { + "name": "score", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_media_regions_media_id": { + "name": "idx_media_regions_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "uq_media_regions_full_media_id": { + "name": "uq_media_regions_full_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"media_regions\".\"kind\" = 'full'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_regions_media_id_media_id_fk": { + "name": "media_regions_media_id_media_id_fk", + "tableFrom": "media_regions", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "media_regions_bbox_by_kind": { + "name": "media_regions_bbox_by_kind", + "value": "(\n\t\t\t\t(\"media_regions\".\"kind\" = 'full' AND \"media_regions\".\"x\" IS NULL AND \"media_regions\".\"y\" IS NULL AND \"media_regions\".\"width\" IS NULL AND \"media_regions\".\"height\" IS NULL)\n\t\t\t\tOR\n\t\t\t\t(\"media_regions\".\"kind\" <> 'full' AND \"media_regions\".\"x\" IS NOT NULL AND \"media_regions\".\"y\" IS NOT NULL AND \"media_regions\".\"width\" IS NOT NULL AND \"media_regions\".\"height\" IS NOT NULL\n\t\t\t\t\tAND \"media_regions\".\"x\" >= 0 AND \"media_regions\".\"y\" >= 0 AND \"media_regions\".\"width\" > 0 AND \"media_regions\".\"height\" > 0\n\t\t\t\t\tAND \"media_regions\".\"x\" + \"media_regions\".\"width\" <= 1 AND \"media_regions\".\"y\" + \"media_regions\".\"height\" <= 1)\n\t\t\t)" + }, + "media_regions_score_range": { + "name": "media_regions_score_range", + "value": "\"media_regions\".\"score\" IS NULL OR (\"media_regions\".\"score\" >= 0 AND \"media_regions\".\"score\" <= 1)" + } + }, + "isRLSEnabled": false + }, + "public.media_relations": { + "name": "media_relations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "parent_media_id": { + "name": "parent_media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "child_media_id": { + "name": "child_media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "relation_type": { + "name": "relation_type", + "type": "media_relation_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "order_index": { + "name": "order_index", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_media_relations_child": { + "name": "idx_media_relations_child", + "columns": [ + { + "expression": "child_media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_relations_type": { + "name": "idx_media_relations_type", + "columns": [ + { + "expression": "relation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_relations_parent_media_id_media_id_fk": { + "name": "media_relations_parent_media_id_media_id_fk", + "tableFrom": "media_relations", + "tableTo": "media", + "columnsFrom": [ + "parent_media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_relations_child_media_id_media_id_fk": { + "name": "media_relations_child_media_id_media_id_fk", + "tableFrom": "media_relations", + "tableTo": "media", + "columnsFrom": [ + "child_media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "parent_child_type_unique": { + "name": "parent_child_type_unique", + "nullsNotDistinct": false, + "columns": [ + "parent_media_id", + "child_media_id", + "relation_type" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_sources": { + "name": "media_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "media_source_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "connection_info": { + "name": "connection_info", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "sync_status": { + "name": "sync_status", + "type": "media_source_sync_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'idle'" + }, + "last_sync_started_at": { + "name": "last_sync_started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_completed_at": { + "name": "last_sync_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_sync": { + "name": "media_sync", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "sync_status": { + "name": "sync_status", + "type": "media_sync_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": false, + "default": "'synced'" + }, + "backup_urls": { + "name": "backup_urls", + "type": "text[]", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "sync_attempts": { + "name": "sync_attempts", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "media_sync_media_id_media_id_fk": { + "name": "media_sync_media_id_media_id_fk", + "tableFrom": "media_sync", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_tags": { + "name": "media_tags", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "tag_id": { + "name": "tag_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "tag_type": { + "name": "tag_type", + "type": "tag_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'positive'" + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + } + }, + "indexes": { + "idx_media_tags_tag_id_tag_type_media_id": { + "name": "idx_media_tags_tag_id_tag_type_media_id", + "columns": [ + { + "expression": "tag_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "tag_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_tags_media_id_media_id_fk": { + "name": "media_tags_media_id_media_id_fk", + "tableFrom": "media_tags", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "media_tags_tag_id_tags_id_fk": { + "name": "media_tags_tag_id_tags_id_fk", + "tableFrom": "media_tags", + "tableTo": "tags", + "columnsFrom": [ + "tag_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "media_tags_media_id_tag_id_tag_type_pk": { + "name": "media_tags_media_id_tag_id_tag_type_pk", + "columns": [ + "media_id", + "tag_id", + "tag_type" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_technical_info": { + "name": "media_technical_info", + "schema": "", + "columns": { + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": true, + "notNull": true + }, + "color_profile": { + "name": "color_profile", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "exif_data": { + "name": "exif_data", + "type": "jsonb", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "hash_md5": { + "name": "hash_md5", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "hash_perceptual": { + "name": "hash_perceptual", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "duration_seconds": { + "name": "duration_seconds", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "frame_rate": { + "name": "frame_rate", + "type": "real", + "primaryKey": false, + "notNull": false + }, + "bitrate_kbps": { + "name": "bitrate_kbps", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "video_codec": { + "name": "video_codec", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "audio_codec": { + "name": "audio_codec", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_media_technical_info_hash_md5": { + "name": "idx_media_technical_info_hash_md5", + "columns": [ + { + "expression": "hash_md5", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_technical_info_media_id_media_id_fk": { + "name": "media_technical_info_media_id_media_id_fk", + "tableFrom": "media_technical_info", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media_urls": { + "name": "media_urls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_media_urls_media_id": { + "name": "idx_media_urls_media_id", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_urls_url": { + "name": "idx_media_urls_url", + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_urls_media_id_url_unique": { + "name": "idx_media_urls_media_id_url_unique", + "columns": [ + { + "expression": "media_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_urls_media_id_media_id_fk": { + "name": "media_urls_media_id_media_id_fk", + "tableFrom": "media_urls", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.media": { + "name": "media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "source_id": { + "name": "source_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "file_path": { + "name": "file_path", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "file_name": { + "name": "file_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "media_type": { + "name": "media_type", + "type": "media_type", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "file_size": { + "name": "file_size", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "modified_at": { + "name": "modified_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "indexed_at": { + "name": "indexed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "status": { + "name": "status", + "type": "media_organization_status", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'active'" + } + }, + "indexes": { + "idx_media_source_id": { + "name": "idx_media_source_id", + "columns": [ + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_file_size": { + "name": "idx_media_file_size", + "columns": [ + { + "expression": "file_size", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_file_name": { + "name": "idx_media_file_name", + "columns": [ + { + "expression": "file_name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_created_at": { + "name": "idx_media_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "idx_media_description": { + "name": "idx_media_description", + "columns": [ + { + "expression": "description", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "media_source_id_media_sources_id_fk": { + "name": "media_source_id_media_sources_id_fk", + "tableFrom": "media", + "tableTo": "media_sources", + "columnsFrom": [ + "source_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "source_id_file_path_unique": { + "name": "source_id_file_path_unique", + "nullsNotDistinct": false, + "columns": [ + "source_id", + "file_path" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.presets": { + "name": "presets", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "sort": { + "name": "sort", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "order": { + "name": "order", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mode": { + "name": "mode", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "presets_name_unique": { + "name": "presets_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.projects": { + "name": "projects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "idx_projects_name": { + "name": "idx_projects_name", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "projects_name_unique": { + "name": "projects_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.search_snapshots": { + "name": "search_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "fingerprint": { + "name": "fingerprint", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_search_snapshots_created_at": { + "name": "idx_search_snapshots_created_at", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "search_snapshots_fingerprint_unique": { + "name": "search_snapshots_fingerprint_unique", + "nullsNotDistinct": false, + "columns": [ + "fingerprint" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.similar_media": { + "name": "similar_media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media1_id": { + "name": "media1_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "media2_id": { + "name": "media2_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "similarity_score": { + "name": "similarity_score", + "type": "real", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "algorithm": { + "name": "algorithm", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'perceptual'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": { + "idx_similar_media_score": { + "name": "idx_similar_media_score", + "columns": [ + { + "expression": "similarity_score", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "similar_media_media1_id_media_id_fk": { + "name": "similar_media_media1_id_media_id_fk", + "tableFrom": "similar_media", + "tableTo": "media", + "columnsFrom": [ + "media1_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "similar_media_media2_id_media_id_fk": { + "name": "similar_media_media2_id_media_id_fk", + "tableFrom": "similar_media", + "tableTo": "media", + "columnsFrom": [ + "media2_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "media1Id_media2Id_algorithm_unique": { + "name": "media1Id_media2Id_algorithm_unique", + "nullsNotDistinct": false, + "columns": [ + "media1_id", + "media2_id", + "algorithm" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.tags": { + "name": "tags", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attribute": { + "name": "attribute", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "author_id": { + "name": "author_id", + "type": "uuid", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_tags_author_id": { + "name": "idx_tags_author_id", + "columns": [ + { + "expression": "author_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "tags_author_id_authors_id_fk": { + "name": "tags_author_id_authors_id_fk", + "tableFrom": "tags", + "tableTo": "authors", + "columnsFrom": [ + "author_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "tags_name_unique": { + "name": "tags_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.uuidv7_migration_map": { + "name": "uuidv7_migration_map", + "schema": "", + "columns": { + "entity": { + "name": "entity", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "old_id": { + "name": "old_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "new_id": { + "name": "new_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "source_timestamp": { + "name": "source_timestamp", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "migrated_at": { + "name": "migrated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "uuidv7_migration_map_entity_old_id_pk": { + "name": "uuidv7_migration_map_entity_old_id_pk", + "columns": [ + "entity", + "old_id" + ] + } + }, + "uniqueConstraints": { + "uuidv7_migration_map_entity_new_id_unique": { + "name": "uuidv7_migration_map_entity_new_id_unique", + "nullsNotDistinct": false, + "columns": [ + "entity", + "new_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.view_history": { + "name": "view_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "uuidv7()" + }, + "media_id": { + "name": "media_id", + "type": "uuid", + "primaryKey": false, + "notNull": true + }, + "viewed_at": { + "name": "viewed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "''" + } + }, + "indexes": {}, + "foreignKeys": { + "view_history_media_id_media_id_fk": { + "name": "view_history_media_id_media_id_fk", + "tableFrom": "view_history", + "tableTo": "media", + "columnsFrom": [ + "media_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "public.author_platform": { + "name": "author_platform", + "schema": "public", + "values": [ + "twitter", + "pixiv-fanbox", + "danbooru" + ] + }, + "public.job_status": { + "name": "job_status", + "schema": "public", + "values": [ + "pending", + "in_progress", + "completed", + "failed", + "cancelled" + ] + }, + "public.media_organization_status": { + "name": "media_organization_status", + "schema": "public", + "values": [ + "active", + "archived", + "deleted" + ] + }, + "public.media_region_kind": { + "name": "media_region_kind", + "schema": "public", + "values": [ + "full", + "person", + "manual" + ] + }, + "public.media_relation_type": { + "name": "media_relation_type", + "schema": "public", + "values": [ + "variant", + "version", + "page", + "derivative", + "edit", + "source" + ] + }, + "public.media_source_sync_status": { + "name": "media_source_sync_status", + "schema": "public", + "values": [ + "idle", + "syncing", + "error" + ] + }, + "public.media_source_type": { + "name": "media_source_type", + "schema": "public", + "values": [ + "local", + "sftp", + "s3" + ] + }, + "public.media_sync_status": { + "name": "media_sync_status", + "schema": "public", + "values": [ + "synced", + "pending", + "failed" + ] + }, + "public.media_type": { + "name": "media_type", + "schema": "public", + "values": [ + "image", + "video", + "audio" + ] + }, + "public.tag_type": { + "name": "tag_type", + "schema": "public", + "values": [ + "positive", + "negative" + ] + } + }, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} diff --git a/apps/server/drizzle/meta/_journal.json b/apps/server/drizzle/meta/_journal.json index 8e9db3b5..6a290564 100644 --- a/apps/server/drizzle/meta/_journal.json +++ b/apps/server/drizzle/meta/_journal.json @@ -190,6 +190,20 @@ "when": 1787235852419, "tag": "0026_nebulous_metal_master", "breakpoints": true + }, + { + "idx": 27, + "version": "7", + "when": 1787481127595, + "tag": "0027_acoustic_impossible_man", + "breakpoints": true + }, + { + "idx": 28, + "version": "7", + "when": 1787481426956, + "tag": "0028_free_human_robot", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/server/package.json b/apps/server/package.json index 91c008a5..0e09a0a8 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -12,9 +12,11 @@ "start": "bun --bun .output/server/index.mjs", "db:generate": "drizzle-kit generate", "db:migrate": "drizzle-kit migrate", + "db:reconcile-uuidv7-paths": "bun scripts/reconcile-uuidv7-paths.ts", "db:push": "drizzle-kit push", "db:drop": "drizzle-kit drop", "db:studio": "drizzle-kit studio", + "validate:native": "bun scripts/validate-native-runtime.ts", "lint": "biome lint ./src", "format": "biome format --fix ./src", "check": "biome check --fix --unsafe ./src", @@ -55,7 +57,7 @@ "@tanstack/solid-start": "^1.168.19", "archiver": "^8.0.0", "chokidar": "^5.0.0", - "dghs-imgutils-rs": "github:hmjn023/dghs-imgutils-rs#v0.5.1", + "dghs-imgutils-rs": "github:hmjn023/dghs-imgutils-rs#457553648518c8df370391391443b6302e19b05a", "drizzle-orm": "^0.45.2", "ffmpeg-static": "^5.3.0", "fluent-ffmpeg": "^2.1.3", diff --git a/apps/server/scripts/reconcile-uuidv7-paths.ts b/apps/server/scripts/reconcile-uuidv7-paths.ts new file mode 100644 index 00000000..aec66ae8 --- /dev/null +++ b/apps/server/scripts/reconcile-uuidv7-paths.ts @@ -0,0 +1,188 @@ +import { readdir, rename, stat } from "node:fs/promises"; +import { readFile } from "node:fs/promises"; +import path from "node:path"; +import { Pool } from "pg"; +import { getJobTransferRoot } from "../src/infrastructure/services/job-transfer-storage"; + +type IdMapping = { + oldId: string; + newId: string; +}; + +type EntityIdMapping = IdMapping & { + entity: string; +}; + +const UUID_PATTERN = + /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; + +function getDatabasePool(): Pool { + const { DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_DATABASE } = process.env; + if (!(DB_HOST && DB_PORT && DB_USER && DB_PASSWORD && DB_DATABASE)) { + throw new Error( + "DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, and DB_DATABASE are required", + ); + } + + return new Pool({ + host: DB_HOST, + port: Number(DB_PORT), + user: DB_USER, + password: DB_PASSWORD, + database: DB_DATABASE, + }); +} + +async function pathExists(targetPath: string): Promise { + return await stat(targetPath) + .then(() => true) + .catch(() => false); +} + +async function renameIfNeeded(oldPath: string, newPath: string): Promise { + if (!(await pathExists(oldPath))) { + return false; + } + if (await pathExists(newPath)) { + throw new Error(`Refusing to overwrite existing path: ${newPath}`); + } + await rename(oldPath, newPath); + return true; +} + +async function reconcileDirectory( + directoryPath: string, + mappings: IdMapping[], +): Promise { + if (!(await pathExists(directoryPath))) { + return 0; + } + + const entries = await readdir(directoryPath, { withFileTypes: true }); + let renamedCount = 0; + for (const entry of entries) { + const matchingMapping = mappings.find(({ oldId }) => + entry.name.includes(oldId), + ); + if (!matchingMapping) { + continue; + } + + const oldPath = path.join(directoryPath, entry.name); + const newName = entry.name.replaceAll( + matchingMapping.oldId, + matchingMapping.newId, + ); + const newPath = path.join(directoryPath, newName); + if (oldPath === newPath) { + continue; + } + renamedCount += Number(await renameIfNeeded(oldPath, newPath)); + } + return renamedCount; +} + +async function reconcileFilesRecursively( + directoryPath: string, + mappings: IdMapping[], +): Promise { + if (!(await pathExists(directoryPath))) { + return 0; + } + + const entries = await readdir(directoryPath, { withFileTypes: true }); + let renamedCount = 0; + for (const entry of entries) { + const entryPath = path.join(directoryPath, entry.name); + if (entry.isDirectory()) { + renamedCount += await reconcileFilesRecursively(entryPath, mappings); + continue; + } + + const matchingMapping = mappings.find(({ oldId }) => + entry.name.includes(oldId), + ); + if (!matchingMapping) { + continue; + } + + const newPath = path.join( + directoryPath, + entry.name.replaceAll(matchingMapping.oldId, matchingMapping.newId), + ); + renamedCount += Number(await renameIfNeeded(entryPath, newPath)); + } + return renamedCount; +} + +function isRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null; +} + +async function getThumbnailRoot(): Promise { + const configuredPath = process.env.CONFIG_PATH + ? path.resolve(process.env.CONFIG_PATH) + : (await pathExists(path.resolve(process.cwd(), "apps/server"))) + ? path.resolve(process.cwd(), "apps/server/config.json") + : path.resolve(process.cwd(), "config.json"); + + let thumbnailDirectory = ".cache/thumbnails"; + try { + const parsed: unknown = JSON.parse(await readFile(configuredPath, "utf8")); + if (isRecord(parsed) && isRecord(parsed.storage)) { + const configuredThumbnailDirectory = parsed.storage.thumbnailDir; + if (typeof configuredThumbnailDirectory === "string") { + thumbnailDirectory = configuredThumbnailDirectory; + } + } + } catch { + // Use the same default as the thumbnail service when config is absent. + } + + return path.resolve(process.cwd(), thumbnailDirectory); +} + +const pool = getDatabasePool(); +try { + const result = await pool.query( + `SELECT entity, old_id::text AS "oldId", new_id::text AS "newId" + FROM uuidv7_migration_map + WHERE entity IN ('jobs', 'media_sources', 'media')`, + ); + const mappings = result.rows.filter( + ({ oldId, newId }) => + UUID_PATTERN.test(oldId) && UUID_PATTERN.test(newId), + ); + if (mappings.length === 0) { + process.stdout.write("No UUIDv7 job path mappings found.\n"); + } else { + const jobMappings = mappings.filter(({ entity }) => entity === "jobs"); + const sourceMappings = mappings.filter( + ({ entity }) => entity === "media_sources", + ); + const mediaMappings = mappings.filter(({ entity }) => entity === "media"); + const transferRoot = getJobTransferRoot(); + const directories = [ + path.join(transferRoot, "inputs"), + path.join(transferRoot, "artifacts"), + path.resolve(transferRoot, "..", "tar-staging"), + ]; + let renamedCount = 0; + for (const directoryPath of directories) { + renamedCount += await reconcileDirectory(directoryPath, jobMappings); + } + + const thumbnailRoot = await getThumbnailRoot(); + renamedCount += await reconcileDirectory(thumbnailRoot, sourceMappings); + renamedCount += await reconcileFilesRecursively( + thumbnailRoot, + mediaMappings, + ); + + process.stdout.write( + `Reconciled ${renamedCount} path(s) using ${mappings.length} mapping(s).\n`, + ); + } +} finally { + await pool.end(); +} diff --git a/apps/server/scripts/validate-native-runtime.ts b/apps/server/scripts/validate-native-runtime.ts new file mode 100644 index 00000000..39ca33c5 --- /dev/null +++ b/apps/server/scripts/validate-native-runtime.ts @@ -0,0 +1,11 @@ +import { probeInferenceBackends } from "dghs-imgutils-rs"; + +const cpuBackend = probeInferenceBackends({ + backend: "cpu", + precision: "fp32", +}).find((backend) => backend.backend === "cpu"); + +if (!cpuBackend?.available) { + const reason = cpuBackend?.reason ? `: ${cpuBackend.reason}` : ""; + throw new Error(`CPU ONNX Runtime provider is unavailable${reason}`); +} diff --git a/apps/server/src/infrastructure/api-clients/queries/index.ts b/apps/server/src/infrastructure/api-clients/queries/index.ts index d92c674b..4511d8fc 100644 --- a/apps/server/src/infrastructure/api-clients/queries/index.ts +++ b/apps/server/src/infrastructure/api-clients/queries/index.ts @@ -1,4 +1,5 @@ import { createORPCSolidQueryUtils } from "@orpc/solid-query"; +import type { JobListRequest } from "@solid-imager/core/domain/jobs/schemas"; import { authorsQueryKeys, charactersQueryKeys, @@ -8,6 +9,7 @@ import { defaultConfigQueryConfig, defaultIpsQueryConfig, defaultJobsQueryConfig, + defaultJobsQueryInput, defaultMediaDetailsQueryConfig, defaultProjectsQueryConfig, defaultSourcesQueryConfig, @@ -48,7 +50,9 @@ export const allIpsQueryOptions = () => ({ queryKey: ipsQueryKeys.all(), ...defaultIpsQueryConfig, }); -export const jobsQueryOptions = (input = { limit: 200, offset: 0 }) => ({ +export const jobsQueryOptions = ( + input: JobListRequest = defaultJobsQueryInput, +) => ({ ...utils.jobs.list.queryOptions({ input }), queryKey: jobsQueryKeys.list(input), ...defaultJobsQueryConfig, diff --git a/apps/server/src/infrastructure/api/routers/sources-router.ts b/apps/server/src/infrastructure/api/routers/sources-router.ts index e57779d4..312f0c31 100644 --- a/apps/server/src/infrastructure/api/routers/sources-router.ts +++ b/apps/server/src/infrastructure/api/routers/sources-router.ts @@ -1,3 +1,4 @@ +import { randomUUID } from "node:crypto"; import { implement, ORPCError } from "@orpc/server"; import { type SourceSyncResult, @@ -19,6 +20,7 @@ import { db } from "~/infrastructure/db"; import { medias } from "~/infrastructure/db/schema"; import { RealtimeEventBus } from "~/infrastructure/events/realtime-event-bus"; import { logger } from "~/infrastructure/logger"; +import { allocateJobId } from "~/infrastructure/repositories/job-repository"; import { services } from "~/infrastructure/service-registry"; import { BackupService } from "~/infrastructure/services/backup-service"; import { DirectorySyncService } from "~/infrastructure/services/directory-sync-service"; @@ -278,7 +280,6 @@ export const sourcesRouter = os.router({ * Imports a media source from a Tar file */ importZip: os.importZip.handler(async ({ input }) => { - const { randomUUID } = await import("node:crypto"); const path = await import("node:path"); const fs = await import("node:fs"); const { pipeline } = await import("node:stream/promises"); @@ -312,8 +313,7 @@ export const sourcesRouter = os.router({ }); } - const { randomUUID } = await import("node:crypto"); - const jobId = randomUUID(); + const jobId = await allocateJobId(); const inputPath = await persistJobInput(jobId, input.mode, input.file); try { const job = await services.getJobRepository().create({ @@ -337,7 +337,6 @@ export const sourcesRouter = os.router({ * Imports a media source from a streaming NDJSON file */ importNdjson: os.importNdjson.handler(async ({ input }) => { - const { randomUUID } = await import("node:crypto"); const path = await import("node:path"); const fs = await import("node:fs"); const { pipeline } = await import("node:stream/promises"); diff --git a/apps/server/src/infrastructure/repositories/job-repository.ts b/apps/server/src/infrastructure/repositories/job-repository.ts index c1de13b2..03b95505 100644 --- a/apps/server/src/infrastructure/repositories/job-repository.ts +++ b/apps/server/src/infrastructure/repositories/job-repository.ts @@ -1,5 +1,12 @@ import type { IJobRepository } from "@solid-imager/core/domain/repositories/job-repository"; -import { createJobRepository } from "@solid-imager/db/repositories/job-repository"; +import { + allocateJobId as allocateDbJobId, + createJobRepository, +} from "@solid-imager/db/repositories/job-repository"; import { getExecutor } from "~/infrastructure/db/executor"; export const JobRepository: IJobRepository = createJobRepository(getExecutor); + +export function allocateJobId(): Promise { + return allocateDbJobId(getExecutor); +} diff --git a/apps/server/src/routes/v2/jobs.tsx b/apps/server/src/routes/v2/jobs.tsx index 0c929061..5f62cdf3 100644 --- a/apps/server/src/routes/v2/jobs.tsx +++ b/apps/server/src/routes/v2/jobs.tsx @@ -1,11 +1,16 @@ import type { JobListResponse } from "@solid-imager/core/domain/jobs/schemas"; import { useJobEvents } from "@solid-imager/ui/hooks/use-job-events"; -import { jobsQueryKeys } from "@solid-imager/ui/query-options"; +import { + DEFAULT_JOBS_PAGE_SIZE, + jobsQueryKeys, + updateJobProgress, +} from "@solid-imager/ui/query-options"; import { toQueryUiState } from "@solid-imager/ui/query-state"; import { V2JobsScreen } from "@solid-imager/ui/screens/v2-jobs-screen"; import { toast } from "@solid-imager/ui/toast"; import { createQuery, useQueryClient } from "@tanstack/solid-query"; import { createFileRoute } from "@tanstack/solid-router"; +import { createSignal } from "solid-js"; import { orpc } from "~/infrastructure/api-clients/orpc-client"; import { jobsQueryOptions } from "~/infrastructure/api-clients/queries"; @@ -14,13 +19,34 @@ export const Route = createFileRoute("/v2/jobs")({ }); function V2JobsRoute() { - const jobsQuery = createQuery(() => jobsQueryOptions()); + const [pageIndex, setPageIndex] = createSignal(0); + const jobsQuery = createQuery(() => + jobsQueryOptions({ + limit: DEFAULT_JOBS_PAGE_SIZE, + offset: pageIndex() * DEFAULT_JOBS_PAGE_SIZE, + }), + ); const queryClient = useQueryClient(); + const pagination = () => { + const total = jobsQuery.data?.total ?? 0; + return { + canNext: (pageIndex() + 1) * DEFAULT_JOBS_PAGE_SIZE < total, + canPrevious: pageIndex() > 0, + current: pageIndex() + 1, + onNext: () => setPageIndex((current) => current + 1), + onPrevious: () => setPageIndex((current) => Math.max(0, current - 1)), + total: Math.max(1, Math.ceil(total / DEFAULT_JOBS_PAGE_SIZE)), + }; + }; useJobEvents( (signal) => orpc.jobs.events(undefined, { signal }), (event) => { if (event.event === "job-progress") { + queryClient.setQueriesData( + { queryKey: jobsQueryKeys.listPrefix() }, + (data) => updateJobProgress(data, event.data), + ); return; } void queryClient.invalidateQueries({ queryKey: jobsQueryKeys.all() }); @@ -72,6 +98,7 @@ function V2JobsRoute() { anchor.click(); anchor.remove(); }} + page={pagination} state={() => toQueryUiState(jobsQuery)} /> ); diff --git a/apps/tauri/src/queries/index.ts b/apps/tauri/src/queries/index.ts index 0a15e197..ac85ae9c 100644 --- a/apps/tauri/src/queries/index.ts +++ b/apps/tauri/src/queries/index.ts @@ -1,4 +1,5 @@ import { createORPCSolidQueryUtils } from "@orpc/solid-query"; +import type { JobListRequest } from "@solid-imager/core/domain/jobs/schemas"; import { authorsQueryKeys, charactersQueryKeys, @@ -8,6 +9,7 @@ import { defaultConfigQueryConfig, defaultIpsQueryConfig, defaultJobsQueryConfig, + defaultJobsQueryInput, defaultMediaDetailsQueryConfig, defaultProjectsQueryConfig, defaultSourcesQueryConfig, @@ -48,7 +50,9 @@ export const allIpsQueryOptions = () => ({ queryKey: ipsQueryKeys.all(), ...defaultIpsQueryConfig, }); -export const jobsQueryOptions = (input = { limit: 200, offset: 0 }) => ({ +export const jobsQueryOptions = ( + input: JobListRequest = defaultJobsQueryInput, +) => ({ ...utils.jobs.list.queryOptions({ input }), queryKey: jobsQueryKeys.list(input), ...defaultJobsQueryConfig, diff --git a/apps/tauri/src/routes/jobs.tsx b/apps/tauri/src/routes/jobs.tsx index 95131379..0cd41863 100644 --- a/apps/tauri/src/routes/jobs.tsx +++ b/apps/tauri/src/routes/jobs.tsx @@ -4,12 +4,17 @@ import type { JobListResponse, } from "@solid-imager/core/domain/jobs/schemas"; import { useJobEvents } from "@solid-imager/ui/hooks/use-job-events"; -import { jobsQueryKeys } from "@solid-imager/ui/query-options"; +import { + DEFAULT_JOBS_PAGE_SIZE, + jobsQueryKeys, + updateJobProgress, +} from "@solid-imager/ui/query-options"; import { toQueryUiState } from "@solid-imager/ui/query-state"; import { V2JobsScreen } from "@solid-imager/ui/screens/v2-jobs-screen"; import { toast } from "@solid-imager/ui/toast"; import { createQuery, useQueryClient } from "@tanstack/solid-query"; import { createFileRoute } from "@tanstack/solid-router"; +import { createSignal } from "solid-js"; import { orpc } from "~/infrastructure/api-clients/orpc-client"; import { jobsQueryOptions } from "~/queries"; @@ -43,13 +48,34 @@ async function downloadJobArtifact(job: JobDto): Promise { } function JobsRoute() { - const jobsQuery = createQuery(() => jobsQueryOptions()); + const [pageIndex, setPageIndex] = createSignal(0); + const jobsQuery = createQuery(() => + jobsQueryOptions({ + limit: DEFAULT_JOBS_PAGE_SIZE, + offset: pageIndex() * DEFAULT_JOBS_PAGE_SIZE, + }), + ); const queryClient = useQueryClient(); + const pagination = () => { + const total = jobsQuery.data?.total ?? 0; + return { + canNext: (pageIndex() + 1) * DEFAULT_JOBS_PAGE_SIZE < total, + canPrevious: pageIndex() > 0, + current: pageIndex() + 1, + onNext: () => setPageIndex((current) => current + 1), + onPrevious: () => setPageIndex((current) => Math.max(0, current - 1)), + total: Math.max(1, Math.ceil(total / DEFAULT_JOBS_PAGE_SIZE)), + }; + }; useJobEvents( (signal) => orpc.jobs.events(undefined, { signal }), (event) => { if (event.event === "job-progress") { + queryClient.setQueriesData( + { queryKey: jobsQueryKeys.listPrefix() }, + (data) => updateJobProgress(data, event.data), + ); return; } void queryClient.invalidateQueries({ queryKey: jobsQueryKeys.all() }); @@ -93,6 +119,7 @@ function JobsRoute() { } }} onDownload={downloadJobArtifact} + page={pagination} state={() => toQueryUiState(jobsQuery)} /> diff --git a/bun.lock b/bun.lock index 205f2ab4..772a2f89 100644 --- a/bun.lock +++ b/bun.lock @@ -61,7 +61,7 @@ "@tanstack/solid-start": "^1.168.19", "archiver": "^8.0.0", "chokidar": "^5.0.0", - "dghs-imgutils-rs": "github:hmjn023/dghs-imgutils-rs#v0.5.1", + "dghs-imgutils-rs": "github:hmjn023/dghs-imgutils-rs#457553648518c8df370391391443b6302e19b05a", "drizzle-orm": "^0.45.2", "ffmpeg-static": "^5.3.0", "fluent-ffmpeg": "^2.1.3", @@ -1131,7 +1131,7 @@ "devlop": ["devlop@1.1.0", "", { "dependencies": { "dequal": "^2.0.0" } }, "sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA=="], - "dghs-imgutils-rs": ["dghs-imgutils-rs@github:hmjn023/dghs-imgutils-rs#eee8d4b", { "dependencies": { "@napi-rs/cli": "^2.18.4" } }, "hmjn023-dghs-imgutils-rs-eee8d4b", "sha512-zqLnyNK55eD63UIUPj21//OC7W4yDUpvKAqMHqso5ooe2RIDz51sqy5jzIVsszN5bRtZmtZyGiiQL+Q4h6nzSw=="], + "dghs-imgutils-rs": ["dghs-imgutils-rs@github:hmjn023/dghs-imgutils-rs#4575536", { "dependencies": { "@napi-rs/cli": "^2.18.4" } }, "hmjn023-dghs-imgutils-rs-4575536", "sha512-sfqEBeXc7J71AeTa9EnBrurDh1mgt1EUf9BhOIZNemDHPPbtn9zhsLFV5yPH2QVn2b3kWyK5Adu9eKN48RyBVw=="], "diff": ["diff@7.0.0", "", {}, "sha512-PJWHUb1RFevKCwaFA9RlG5tCd+FO5iRh9A8HEtkmBH2Li03iJriB6m6JIN4rGz3K3JLawI7/veA1xzRKP6ISBw=="], diff --git a/compose.production.yml b/compose.production.yml index c2ff126d..1efff13c 100644 --- a/compose.production.yml +++ b/compose.production.yml @@ -15,9 +15,17 @@ services: DB_PASSWORD: ${DB_PASSWORD} NITRO_HOST: 0.0.0.0 PORT: 3000 - volumes: - - .:/app + ORT_DYLIB_PATH: /usr/local/lib/onnxruntime/libonnxruntime.so.1.24.2 + LD_LIBRARY_PATH: /usr/local/lib/onnxruntime + DGHS_BACKEND: cpu + DGHS_PRECISION: fp32 command: ["bun", "run", "start"] + healthcheck: + test: ["CMD", "bun", "run", "--cwd", "apps/server", "validate:native"] + interval: 30s + timeout: 10s + retries: 3 + start_period: 30s depends_on: - db diff --git a/compose.yml b/compose.yml index 422ee9fe..bf32312b 100644 --- a/compose.yml +++ b/compose.yml @@ -1,6 +1,6 @@ services: db: - image: pgvector/pgvector:pg17 + image: pgvector/pgvector:pg18 shm_size: 256mb restart: always environment: @@ -8,6 +8,6 @@ services: POSTGRES_PASSWORD: ${DB_PASSWORD} POSTGRES_DB: ${DB_DATABASE} volumes: - - ./db-data:/var/lib/postgresql/data + - ./db-data-pg18:/var/lib/postgresql ports: - ${DB_PORT}:5432 diff --git a/docs/operations/postgresql-18-uuidv7-migration.md b/docs/operations/postgresql-18-uuidv7-migration.md new file mode 100644 index 00000000..5b32538d --- /dev/null +++ b/docs/operations/postgresql-18-uuidv7-migration.md @@ -0,0 +1,174 @@ +# PostgreSQL 18 / UUIDv7 本番移行手順 + +本手順は、PostgreSQL 17 + `pgvector` から PostgreSQL 18 へ移行し、既存のUUIDv4をUUIDv7へ変換する際に使用する。 + +今回の移行では、メディアの `created_at` など既存の時刻情報を元にUUIDv7を生成する。メディアの `created_at` がUnix epochを未知値として使っている場合は `modified_at` をフォールバックにする。旧IDと新IDの対応は `uuidv7_migration_map` に保持され、ジョブ・検索履歴・プリセットなどのID参照を含むJSONBも移行対象となる。 + +## 事前確認 + +- 本番で使用するコミットを固定し、ローカルまたはステージングで同じdumpのリストアとmigrationを一度実施する。 +- `pgvector/pgvector:pg18` が取得でき、`vector` extensionを利用できることを確認する。 +- PostgreSQL 17のデータディレクトリは削除せず、移行完了まで保持する。 +- 実際に使用しているComposeの `-f` オプション、`.env`、`compose.production.override.yml` を確認する。 +- メディアソースのコンテナ内パスは変更しない。DBに保存されたパスとmount先が一致している必要がある。 + +## 移行手順 + +### 1. メンテナンス状態にする + +新規登録、インポート、ジョブ実行が発生しないようにする。現行Composeではworkerは `app` プロセス内で起動するため、`app` を停止するとworkerも停止する。別Composeや外部systemdでworkerを起動している場合は、それも停止する。 + +```bash +docker compose stop app nginx +docker compose ps --all +``` + +`app`、`nginx`、workerなどの書き込み元が停止していることを確認してから、バックアップへ進む。 + +### 2. PostgreSQL 17のバックアップを取得する + +DBが停止している必要はないが、アプリケーションの書き込みを止めてから取得する。 + +```bash +mkdir -p backup + +docker compose exec -T db sh -c \ + 'pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc' \ + > backup/solid-imager-pre-pg18.dump + +docker compose exec -T db sh -c \ + 'pg_dumpall -U "$POSTGRES_USER" --globals-only' \ + > backup/solid-imager-pre-pg18-globals.sql + +pg_restore --list backup/solid-imager-pre-pg18.dump \ + > backup/solid-imager-pre-pg18.list +sha256sum backup/solid-imager-pre-pg18.dump + +if [ -d .cache ]; then + tar -C . -czf backup/solid-imager-pre-pg18-runtime.tar.gz .cache +fi +``` + +`pg_dump` のcustom formatを使用しているため、リストアには `pg_restore` を使用する。追加ロールがある場合はglobalsも復元する。 + +DB以外に、次のデータもバックアップする。 + +- `config.json` または `CONFIG_PATH` で指定された設定ファイル +- `.cache/job-transfers` と `.cache/tar-staging` +- `.cache/thumbnails` +- メディアソースの実体、および本番Composeで指定している外部mount + +### 3. PostgreSQL 18用の新しいデータディレクトリを用意する + +PostgreSQLのmajor version間ではデータディレクトリを直接共有できない。既存の `db-data/` をPG18にmountして起動してはいけない。 + +まずDBコンテナを停止し、停止を確認してから現在の `db-data/` を `db-data-pg17/` などへ温存する。新しい空ディレクトリをPG18に割り当てる。 + +```bash +docker compose stop db +docker compose ps --all +``` + +`db` が停止していることを確認してから、データディレクトリを移動する。 + +```yaml +# compose.yml(このPR適用後の既定値) +services: + db: + image: pgvector/pgvector:pg18 + volumes: + - ./db-data-pg18:/var/lib/postgresql +``` + +PostgreSQL 18ではmount先も `/var/lib/postgresql` に変更されている。データ実体はコンテナ内の `/var/lib/postgresql/18/docker` に作成されるため、ホスト側では `db-data-pg18/18/docker/` がPG18のデータディレクトリになる。`docker compose down -v` や旧ディレクトリの削除は行わない。既存環境から移行する場合は、pull後にComposeが `db-data-pg18/` を `/var/lib/postgresql` にmountしていることを確認する。 + +### 4. PostgreSQL 18だけを起動する + +```bash +docker compose up -d db +docker compose exec -T db sh -c \ + 'pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB"' +``` + +新しいPG18コンテナで `vector` extensionが利用可能であることも確認する。 + +### 5. dumpをPG18へリストアする + +新しいDBへglobalsを必要に応じて復元した後、データベースdumpを戻す。 + +```bash +docker compose exec -T db sh -c \ + 'pg_restore -U "$POSTGRES_USER" -d "$POSTGRES_DB" --exit-on-error' \ + < backup/solid-imager-pre-pg18.dump +``` + +空のDBへリストアするため、通常は `--clean` は不要。ロール名が旧環境と異なる場合は `--no-owner` などを指定し、アプリのDBユーザーが所有権を持つようにする。 + +### 6. migrationを適用する + +dumpをリストアした後に、アプリケーションのmigrationを実行する。アプリ起動時には自動適用されないため、明示的に実行する。 + +```bash +docker compose run --rm app \ + bun --cwd apps/server run db:migrate +``` + +この処理で、UUIDv7のデフォルト、ID変換、外部キー、ジョブ/検索履歴/プリセットのJSONB参照が更新される。`uuidv7_migration_map` はパス整合処理と監査のため残す。 + +### 7. ファイルパスを整合させる + +DB migration後、appとworkerを起動する前に実行する。 + +```bash +docker compose run --rm app \ + bun --cwd apps/server run db:reconcile-uuidv7-paths +``` + +ジョブ入力、ジョブ成果物、tar staging、サムネイルキャッシュに含まれる旧UUIDを新UUIDへ変更する。対象ファイルが見つからない場合はスキップし、移行先が既に存在する場合は上書きせずエラーにする。 + +### 8. アプリケーションを起動する + +```bash +docker compose up -d app nginx +docker compose logs --tail=200 app +``` + +## 移行後の確認 + +DB側では、PG18、migration map、UUIDv7、時刻情報を確認する。 + +```bash +docker compose exec -T db sh -c \ + 'psql -U "$POSTGRES_USER" -d "$POSTGRES_DB" \ + -c "SELECT version();" \ + -c "SELECT count(*) FROM uuidv7_migration_map;" \ + -c "SELECT count(*) FROM media WHERE substring(id::text, 15, 1) = '\''7'\'';" \ + -c "SELECT min(created_at), max(created_at) FROM media;"' +``` + +アプリケーションでは、少なくとも次を確認する。 + +- ログイン、メディア一覧、検索、詳細表示 +- 既存メディアのサムネイル表示 +- import/xtractor経由の登録 +- ジョブのclaim、実行、成果物のダウンロード +- 検索履歴、プリセット、過去ジョブの詳細表示 + +## ロールバック + +移行後の新PG18 DBをUUIDv4へ戻すSQLは用意しない。問題があればapp/nginxを停止し、別workerがあればそれも停止する。新UUIDパスへ変更済みのキャッシュを旧アプリケーションが参照する前に、移行前に取得したファイルツリーを復元する。 + +```bash +docker compose stop app nginx + +# 別workerを運用している場合は、それも停止する。 +# 現在の失敗環境のキャッシュを退避してから移行前snapshotを戻す。 +if [ -d .cache ]; then + mv .cache .cache-pg18-failed +fi +tar -C . -xzf backup/solid-imager-pre-pg18-runtime.tar.gz +``` + +その後、旧アプリケーションのコミット、`pgvector/pg17`、温存したPG17のデータディレクトリを使って復旧する。外部メディアmountや設定ファイルを変更していた場合は、それらも移行前のsnapshotへ戻してから旧アプリケーションを起動する。 + +新環境での動作確認が完了するまで、旧データディレクトリ、dump、メディア、キャッシュを削除しない。 diff --git a/packages/core/src/domain/media/schemas.ts b/packages/core/src/domain/media/schemas.ts index f706ec15..e61484a7 100644 --- a/packages/core/src/domain/media/schemas.ts +++ b/packages/core/src/domain/media/schemas.ts @@ -24,7 +24,7 @@ export type AuthorPlatform = z.infer; * Ensures all required fields for new media are present and correctly formatted. */ export const addMediaRequestSchema = z.object({ - mediaSourceId: z.uuid({ version: "v4", message: "Invalid source ID format" }), + mediaSourceId: z.uuid({ message: "Invalid source ID format" }), filePath: z.string().min(1, "File path is required"), fileName: z.string().min(1, "File name is required"), fileSize: z.number().int().positive("File size must be a positive integer"), @@ -106,7 +106,6 @@ export type UpdateMediaRequest = z.infer; * Ensures the ID is a valid UUID format. */ export const mediaIdSchema = z.uuid({ - version: "v4", message: "Invalid media ID format", }); export type MediaId = z.infer; @@ -116,7 +115,6 @@ export type MediaId = z.infer; * Ensures the ID is a valid UUID format. */ export const mediaSourceIdSchema = z.uuid({ - version: "v4", message: "Invalid source ID format", }); export type SourceId = z.infer; @@ -145,8 +143,8 @@ export type ExtractedData = z.infer; // Base schemas mirroring database tables export const mediaSchema = z.object({ - id: z.uuid({ version: "v4" }), - mediaSourceId: z.uuid({ version: "v4" }), + id: z.uuid(), + mediaSourceId: z.uuid(), filePath: z.string(), fileName: z.string(), mediaType: mediaTypeSchema, @@ -179,7 +177,7 @@ export const mediaSafeSchema = mediaSchema.pick({ export type MediaSafe = z.infer; export const authorSchema = z.object({ - id: z.uuid({ version: "v4" }), + id: z.uuid(), name: z.string(), accountId: z.string().nullable(), createdAt: z.coerce.date(), @@ -197,8 +195,8 @@ export const newAuthorSchema = z.object({ export type NewAuthor = z.infer; export const mediaUrlSchema = z.object({ - id: z.uuid({ version: "v4" }), - mediaId: z.uuid({ version: "v4" }), + id: z.uuid(), + mediaId: z.uuid(), url: z.string().url(), createdAt: z.coerce.date(), updatedAt: z.coerce.date(), @@ -248,7 +246,7 @@ export const ipSchema = z.object({ export type MediaIp = z.infer; export const mediaGenerationInfoSchema = z.object({ - mediaId: z.uuid({ version: "v4" }), + mediaId: z.uuid(), metadata: z.any().nullable(), prompt: z.string().nullable(), negativePrompt: z.string().nullable(), @@ -543,7 +541,7 @@ export const pendingImportCountSchema = z.object({ export type PendingImportCount = z.infer; export const bulkDownloadRequestSchema = z.object({ - mediaSourceId: z.uuid({ version: "v4", message: "Invalid media source ID" }), + mediaSourceId: z.uuid({ message: "Invalid media source ID" }), items: z.array(downloadItemSchema).min(1, "At least one item is required"), }); @@ -568,7 +566,6 @@ export { export const copyMediaRequestSchema = z.object({ targetSourceId: z.uuid({ - version: "v4", message: "Invalid target source ID", }), }); @@ -622,8 +619,8 @@ export const duplicateReasonSchema = z.enum(["sourceUrl"]); export type DuplicateReason = z.infer; export const duplicateMediaItemSchema = z.object({ - id: z.uuid({ version: "v4" }), - mediaSourceId: z.uuid({ version: "v4" }), + id: z.uuid(), + mediaSourceId: z.uuid(), fileName: z.string(), filePath: z.string(), fileSize: z.number().nullable(), @@ -651,7 +648,7 @@ export type FindDuplicatesResponse = z.infer< >; export const findDuplicatesRequestSchema = z.object({ - mediaSourceId: z.uuid({ version: "v4" }).optional(), + mediaSourceId: z.uuid().optional(), }); export type FindDuplicatesRequest = z.infer; diff --git a/packages/core/src/domain/search/history.ts b/packages/core/src/domain/search/history.ts index 3fe69530..2dd02ddd 100644 --- a/packages/core/src/domain/search/history.ts +++ b/packages/core/src/domain/search/history.ts @@ -20,7 +20,7 @@ export type SearchSnapshotState = z.infer; export const searchSnapshotVersionSchema = z.literal(1); export const searchSnapshotSchema = z.object({ - id: z.uuid({ version: "v4" }), + id: z.uuid(), version: searchSnapshotVersionSchema, fingerprint: z.string().min(1), state: searchSnapshotStateSchema, @@ -59,7 +59,7 @@ export type SafeSearchSnapshotState = z.infer< >; export const safeSearchSnapshotSchema = z.object({ - id: z.uuid({ version: "v4" }), + id: z.uuid(), version: searchSnapshotVersionSchema, state: safeSearchSnapshotStateSchema, }); @@ -75,7 +75,7 @@ export type CaptureSearchSnapshotRequest = z.infer< >; export const captureSearchSnapshotResponseSchema = z.object({ - id: z.uuid({ version: "v4" }), + id: z.uuid(), }); export type CaptureSearchSnapshotResponse = z.infer< @@ -83,7 +83,7 @@ export type CaptureSearchSnapshotResponse = z.infer< >; export const getSearchSnapshotRequestSchema = z.object({ - id: z.uuid({ version: "v4" }), + id: z.uuid(), }); export type GetSearchSnapshotRequest = z.infer< diff --git a/packages/core/src/domain/shared/schemas.ts b/packages/core/src/domain/shared/schemas.ts index 2f872edc..b1f16478 100644 --- a/packages/core/src/domain/shared/schemas.ts +++ b/packages/core/src/domain/shared/schemas.ts @@ -1,6 +1,6 @@ import { z } from "zod"; -export const UuidSchema = z.uuid({ version: "v4" }); +export const UuidSchema = z.uuid(); export type UUID = z.infer; export const appConfigSchema = z @@ -59,7 +59,8 @@ export const userDataSchema = z.object({ export type UserData = z.infer; export const collectionDataSchema = z.object({ - userId: z.uuid({ version: "v4" }), // Assuming UUID for userId + userId: z.uuid(), + // Assuming UUID for userId name: z.string(), description: z.string().optional(), }); diff --git a/packages/core/src/domain/sources/schemas.ts b/packages/core/src/domain/sources/schemas.ts index 3aef16b6..a1e90c86 100644 --- a/packages/core/src/domain/sources/schemas.ts +++ b/packages/core/src/domain/sources/schemas.ts @@ -6,7 +6,6 @@ import { z } from "zod"; export const mediaSourceIdSchema = z.uuid({ - version: "v4", message: "Invalid source ID format", }); export type MedioaSourceId = z.infer; @@ -49,7 +48,7 @@ export const mediaSourceSyncStateSchema = z.enum(["idle", "syncing", "error"]); export type MediaSourceSyncState = z.infer; export const mediaSourceInfoSchema = z.object({ - id: z.uuid({ version: "v4" }).optional(), + id: z.uuid().optional(), name: z.string(), description: z.string().nullable(), type: mediaSourceTypeEnumSchema, diff --git a/packages/db/src/repositories/author-repository.ts b/packages/db/src/repositories/author-repository.ts index fa284dfc..ab0f9dbd 100644 --- a/packages/db/src/repositories/author-repository.ts +++ b/packages/db/src/repositories/author-repository.ts @@ -1,4 +1,3 @@ -import { randomUUID } from "node:crypto"; import { ResourceNotFoundError } from "@solid-imager/core/domain/errors"; import type { Author, @@ -161,7 +160,6 @@ async function findOrCreateAuthorsBulk( : new Set(); const accountsToInsert: (typeof authorAccounts.$inferInsert)[] = []; - const authorsToInsert: (typeof authors.$inferInsert)[] = []; const newlyCreatedAuthorByKey = new Map(); for (const [key, input] of unresolved) { const legacyByMatchingAccount = input.accountId @@ -174,22 +172,21 @@ async function findOrCreateAuthorsBulk( const canReuseLegacy = legacy && (!input.platform || !linkedLegacyAuthorIds.has(legacy.id)); - const author = - canReuseLegacy && legacy - ? legacy - : { - id: randomUUID(), - name: input.name, - accountId: input.accountId ?? null, - createdAt: new Date(), - updatedAt: new Date(), - }; - if (!canReuseLegacy) { - authorsToInsert.push({ - id: author.id, - name: author.name, - accountId: author.accountId, - }); + let author: typeof authors.$inferSelect; + if (canReuseLegacy && legacy) { + author = legacy; + } else { + const [createdAuthor] = await client + .insert(authors) + .values({ + name: input.name, + accountId: input.accountId ?? null, + }) + .returning(); + if (!createdAuthor) { + throw new Error(`Failed to create author for ${input.name}`); + } + author = createdAuthor; newlyCreatedAuthorByKey.set(key, author.id); } resolved.set(key, author); @@ -203,9 +200,6 @@ async function findOrCreateAuthorsBulk( } } - if (authorsToInsert.length > 0) { - await client.insert(authors).values(authorsToInsert); - } if (accountsToInsert.length > 0) { const insertedAccounts = await client .insert(authorAccounts) diff --git a/packages/db/src/repositories/job-repository.ts b/packages/db/src/repositories/job-repository.ts index fde09723..8291cb4a 100644 --- a/packages/db/src/repositories/job-repository.ts +++ b/packages/db/src/repositories/job-repository.ts @@ -453,6 +453,28 @@ export function createJobRepository( }; } +/** + * Allocates a UUIDv7 using the database function before a job row exists. + * Import uploads need the job ID to determine the input file path first. + */ +export async function allocateJobId( + getExecutor: (tx?: unknown) => DrizzleExecutor, +): Promise { + const rows = extractRows( + await getExecutor().execute(sql`SELECT uuidv7()::text AS id`), + ); + const row = rows[0]; + if ( + !row || + typeof row !== "object" || + !("id" in row) || + typeof row.id !== "string" + ) { + throw new Error("Failed to allocate a job ID"); + } + return row.id; +} + function buildSimpleClaimQuery(conditions: SQL[], limit: number, now: Date) { return sql` WITH next_jobs AS ( diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index 7369dfc8..c53dea3a 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -147,7 +147,7 @@ export const authorPlatformEnum = pgEnum("author_platform", [ * Stores information about different media sources configured in the system. */ export const mediaSources = pgTable("media_sources", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** 表示されるメディアソースの名前 */ name: text("name").notNull(), /** メディアソースの説明 */ @@ -179,7 +179,7 @@ export const mediaSources = pgTable("media_sources", { export const medias = pgTable( "media", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** どのメディアソースに属しているか */ mediaSourceId: uuid("source_id") .notNull() @@ -228,7 +228,7 @@ export const medias = pgTable( export const mediaRegions = pgTable( "media_regions", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), mediaId: uuid("media_id") .notNull() .references(() => medias.id, { onDelete: "cascade" }), @@ -273,7 +273,7 @@ export const mediaRegions = pgTable( export const ccipEmbeddings = pgTable( "ccip_embeddings", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), regionId: uuid("region_id") .notNull() .references(() => mediaRegions.id, { onDelete: "cascade" }), @@ -303,7 +303,7 @@ export const ccipEmbeddings = pgTable( export const tags = pgTable( "tags", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** タグの名前 (例: "blue eyes") */ name: text("name").notNull(), /** タグの詳細な説明 */ @@ -446,7 +446,7 @@ export const mediaGenerationInfo = pgTable( export const categories = pgTable( "categories", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** カテゴリ名 */ name: text("name").notNull(), /** カテゴリの説明 */ @@ -474,7 +474,7 @@ export const categories = pgTable( export const projects = pgTable( "projects", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** プロジェクト名 */ name: text("name").notNull(), /** プロジェクトの説明 */ @@ -499,7 +499,7 @@ export const projects = pgTable( export const ips = pgTable( "ips", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** IP(作品)名 */ name: text("name").notNull(), /** IP(作品)の説明 */ @@ -523,7 +523,7 @@ export const ips = pgTable( export const characters = pgTable( "characters", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** キャラクター名 */ name: text("name").notNull(), /** キャラクターの説明 */ @@ -738,7 +738,7 @@ export const mediaSync = pgTable("media_sync", { * Records user views of media items for analytics and personalized recommendations. */ export const viewHistory = pgTable("view_history", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** メディアID */ mediaId: uuid("media_id") .notNull() @@ -758,7 +758,7 @@ export const viewHistory = pgTable("view_history", { export const similarMedia = pgTable( "similar_media", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** メディア1のID */ media1Id: uuid("media1_id") .notNull() @@ -803,7 +803,7 @@ export const similarMedia = pgTable( export const mediaRelationsTable = pgTable( "media_relations", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** 親メディアID */ parentMediaId: uuid("parent_media_id") .notNull() @@ -841,7 +841,7 @@ export const mediaRelationsTable = pgTable( export const authors = pgTable( "authors", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** 表示名 */ name: text("name").notNull(), /** 外部ID (例: Twitter ID, Pixiv ID) */ @@ -864,7 +864,7 @@ export const authors = pgTable( export const authorAccounts = pgTable( "author_accounts", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), authorId: uuid("author_id") .notNull() .references(() => authors.id, { onDelete: "cascade" }), @@ -912,7 +912,7 @@ export const mediaAuthors = pgTable( export const mediaUrls = pgTable( "media_urls", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), mediaId: uuid("media_id") .notNull() .references(() => medias.id, { onDelete: "cascade" }), @@ -938,7 +938,7 @@ export const users = pgTable( "users", { /** ユーザーID */ - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** ユーザー名 */ name: text("name").notNull(), /** メールアドレス */ @@ -960,7 +960,7 @@ export const users = pgTable( * Stores user-created collections of media items. */ export const collections = pgTable("collections", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** どのユーザーのコレクションか (ユーザー管理を導入する場合) */ userId: uuid("user_id") .notNull() @@ -1007,7 +1007,7 @@ export const mediaCollections = pgTable( export const jobs = pgTable( "jobs", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), /** ジョブの種類 (例: "thumbnail_generation", "metadata_extraction", "auto_tagging") */ type: text("type").notNull(), /** 関連するメディアソースID (オプショナル) */ @@ -1126,7 +1126,7 @@ export const presets = pgTable("presets", { export const searchSnapshots = pgTable( "search_snapshots", { - id: uuid("id").primaryKey().default(sql`gen_random_uuid()`), + id: uuid("id").primaryKey().default(sql`uuidv7()`), version: integer("version").notNull().default(1), fingerprint: text("fingerprint").notNull().unique(), state: jsonb("state").notNull(), @@ -1139,6 +1139,28 @@ export const searchSnapshots = pgTable( }), ); +/** + * Audit mapping retained after the UUIDv4 -> UUIDv7 rekey migration. + * It is also used to reconcile filesystem paths that contain job or media IDs. + */ +export const uuidv7MigrationMap = pgTable( + "uuidv7_migration_map", + { + entity: text("entity").notNull(), + oldId: uuid("old_id").notNull(), + newId: uuid("new_id").notNull(), + sourceTimestamp: timestamp("source_timestamp"), + migratedAt: timestamp("migrated_at").notNull().defaultNow(), + }, + (table) => ({ + pk: primaryKey({ columns: [table.entity, table.oldId] }), + entityNewIdUnique: unique("uuidv7_migration_map_entity_new_id_unique").on( + table.entity, + table.newId, + ), + }), +); + // リレーション /** * Defines the relations for the media_sources table. diff --git a/packages/ui/src/hooks/use-search-history-persistence.ts b/packages/ui/src/hooks/use-search-history-persistence.ts index 725f610a..62f36ad5 100644 --- a/packages/ui/src/hooks/use-search-history-persistence.ts +++ b/packages/ui/src/hooks/use-search-history-persistence.ts @@ -64,8 +64,8 @@ function parseHistoryEntry(value: unknown): HistorySnapshotEntry | null { }; } -function readSnapshotState(): SearchSnapshotState { - return searchSnapshotStateSchema.parse({ +function readSnapshotState(): SearchSnapshotState | null { + const parsed = searchSnapshotStateSchema.safeParse({ mode: searchState.mode, searchQuery: searchState.searchQuery, selectedTags: [...searchState.selectedTags], @@ -83,6 +83,7 @@ function readSnapshotState(): SearchSnapshotState { sortBy: searchState.sortBy, sortOrder: searchState.sortOrder, }); + return parsed.success ? parsed.data : null; } function stateKey(state: SearchSnapshotState): string { @@ -260,6 +261,10 @@ export function useSearchHistoryPersistence( } const state = readSnapshotState(); + if (!state) { + setHistoryRestored(true); + return; + } skipNextCommitState = stateKey(state); const entry: HistorySnapshotEntry = { version: HISTORY_VERSION, @@ -282,6 +287,7 @@ export function useSearchHistoryPersistence( return; } const state = readSnapshotState(); + if (!state) return; const key = stateKey(state); if (skipNextCommitState === key) { skipNextCommitState = null; @@ -343,6 +349,7 @@ export function useSearchHistoryPersistence( createEffect(() => { if (isServer || !isRestored()) return; const state = readSnapshotState(); + if (!state) return; const key = stateKey(state); if (skipNextCommitState === key) { skipNextCommitState = null; diff --git a/packages/ui/src/query-options/index.ts b/packages/ui/src/query-options/index.ts index 81fd29f6..34dc9186 100644 --- a/packages/ui/src/query-options/index.ts +++ b/packages/ui/src/query-options/index.ts @@ -20,8 +20,11 @@ export { } from "./ips-query"; export { buildJobsQueryOptions, + DEFAULT_JOBS_PAGE_SIZE, defaultJobsQueryConfig, + defaultJobsQueryInput, jobsQueryKeys, + updateJobProgress, } from "./jobs-query"; export { buildMediaDetailsQueryOptions, diff --git a/packages/ui/src/query-options/jobs-query.test.ts b/packages/ui/src/query-options/jobs-query.test.ts new file mode 100644 index 00000000..6dd001d1 --- /dev/null +++ b/packages/ui/src/query-options/jobs-query.test.ts @@ -0,0 +1,53 @@ +import type { JobListResponse } from "@solid-imager/core/domain/jobs/schemas"; +import { describe, expect, it } from "vitest"; +import { updateJobProgress } from "./jobs-query"; + +const jobList: JobListResponse = { + items: [ + { + artifact: null, + attemptCount: 1, + cancelRequestedAt: null, + cancelledAt: null, + createdAt: new Date("2026-01-01T00:00:00.000Z"), + error: null, + finishedAt: null, + id: "00000000-0000-4000-8000-000000000001", + mediaSourceId: null, + parentId: null, + progress: { failed: 2, processed: 1, total: 10 }, + startedAt: new Date("2026-01-01T00:00:01.000Z"), + status: "in_progress", + targetMediaId: null, + type: "batch_tagging_parent", + updatedAt: new Date("2026-01-01T00:00:02.000Z"), + }, + ], + total: 1, +}; + +describe("updateJobProgress", () => { + it("updates a matching cached job while preserving failure counts", () => { + const updated = updateJobProgress(jobList, { + jobId: "00000000-0000-4000-8000-000000000001", + processed: 7, + total: 12, + }); + + expect(updated?.items[0]?.progress).toEqual({ + failed: 2, + processed: 7, + total: 12, + }); + }); + + it("does not replace a list that does not contain the event job", () => { + const updated = updateJobProgress(jobList, { + jobId: "00000000-0000-4000-8000-000000000002", + processed: 7, + total: 12, + }); + + expect(updated).toBe(jobList); + }); +}); diff --git a/packages/ui/src/query-options/jobs-query.ts b/packages/ui/src/query-options/jobs-query.ts index b84cf3ba..b8259dd6 100644 --- a/packages/ui/src/query-options/jobs-query.ts +++ b/packages/ui/src/query-options/jobs-query.ts @@ -2,10 +2,18 @@ import type { JobListRequest, JobListResponse, } from "@solid-imager/core/domain/jobs/schemas"; +import type { JobProgressEvent } from "@solid-imager/core/domain/sources/events"; import { queryOptions } from "@tanstack/solid-query"; +export const DEFAULT_JOBS_PAGE_SIZE = 200; +export const defaultJobsQueryInput = { + limit: DEFAULT_JOBS_PAGE_SIZE, + offset: 0, +} satisfies JobListRequest; + export const jobsQueryKeys = { all: () => ["jobs"] as const, + listPrefix: () => ["jobs", "list"] as const, list: (input: JobListRequest) => ["jobs", "list", input] as const, detail: (jobId: string) => ["jobs", "detail", jobId] as const, }; @@ -24,3 +32,26 @@ export function buildJobsQueryOptions( ...defaultJobsQueryConfig, }); } + +export function updateJobProgress( + data: JobListResponse | undefined, + event: JobProgressEvent, +): JobListResponse | undefined { + if (!data || !event.jobId) return data; + + let updated = false; + const items = data.items.map((job) => { + if (job.id !== event.jobId) return job; + updated = true; + return { + ...job, + progress: { + ...(job.progress ?? { failed: 0 }), + processed: event.processed, + total: event.total, + }, + }; + }); + + return updated ? { ...data, items } : data; +} diff --git a/packages/ui/src/screens/v2-jobs-screen.tsx b/packages/ui/src/screens/v2-jobs-screen.tsx index 23ed4c3c..3c05a95a 100644 --- a/packages/ui/src/screens/v2-jobs-screen.tsx +++ b/packages/ui/src/screens/v2-jobs-screen.tsx @@ -4,6 +4,8 @@ import { type JobListResponse, } from "@solid-imager/core/domain/jobs/schemas"; import Ban from "lucide-solid/icons/ban"; +import ChevronLeft from "lucide-solid/icons/chevron-left"; +import ChevronRight from "lucide-solid/icons/chevron-right"; import CircleAlert from "lucide-solid/icons/circle-alert"; import CircleCheck from "lucide-solid/icons/circle-check"; import Clock3 from "lucide-solid/icons/clock-3"; @@ -55,6 +57,15 @@ const JOB_FILTERS = [ type JobFilter = (typeof JOB_FILTERS)[number]["value"]; +export type V2JobsPagination = { + canNext: boolean; + canPrevious: boolean; + current: number; + onNext: () => void; + onPrevious: () => void; + total: number; +}; + export type V2JobsScreenProps = { isRefreshing: Accessor; jobs: Accessor; @@ -62,6 +73,7 @@ export type V2JobsScreenProps = { onRetry: (jobId: string) => void | Promise; onCancel: (jobId: string) => void | Promise; onDownload: (job: JobDto) => void | Promise; + page: Accessor; state: Accessor>; }; @@ -609,6 +621,53 @@ export function V2JobsScreen(props: V2JobsScreenProps) { )} + 1}> + + diff --git a/packages/ui/src/search-history-route.ts b/packages/ui/src/search-history-route.ts index d3672d4d..556f68a4 100644 --- a/packages/ui/src/search-history-route.ts +++ b/packages/ui/src/search-history-route.ts @@ -1,5 +1,5 @@ import { z } from "zod"; export const searchHistoryQuerySchema = z.object({ - search: z.uuid({ version: "v4" }).optional(), + search: z.uuid().optional(), });