tubearr/drizzle/0012_adhoc_nullable_channel.sql
jlightner 8150b1f6cf chore: Made content_items.channelId nullable via SQLite table recreatio…
- "src/db/schema/content.ts"
- "src/types/index.ts"
- "src/db/repositories/content-repository.ts"
- "src/services/queue.ts"
- "drizzle/0012_adhoc_nullable_channel.sql"
- "drizzle/meta/_journal.json"

GSD-Task: S01/T01
2026-04-04 05:03:40 +00:00

43 lines
1.6 KiB
SQL

-- Make content_items.channel_id nullable to support ad-hoc URL downloads without a channel.
-- SQLite cannot ALTER COLUMN to remove NOT NULL, so we recreate the table.
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `content_items_new` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`channel_id` integer,
`title` text NOT NULL,
`platform_content_id` text NOT NULL,
`url` text NOT NULL,
`content_type` text NOT NULL,
`duration` integer,
`file_path` text,
`file_size` integer,
`format` text,
`quality_metadata` text,
`status` text DEFAULT 'monitored' NOT NULL,
`thumbnail_url` text,
`published_at` text,
`downloaded_at` text,
`monitored` integer DEFAULT true NOT NULL,
`created_at` text DEFAULT (datetime('now')) NOT NULL,
`updated_at` text DEFAULT (datetime('now')) NOT NULL,
FOREIGN KEY (`channel_id`) REFERENCES `channels`(`id`) ON UPDATE no action ON DELETE cascade
);--> statement-breakpoint
INSERT INTO `content_items_new`
SELECT `id`, `channel_id`, `title`, `platform_content_id`, `url`, `content_type`,
`duration`, `file_path`, `file_size`, `format`, `quality_metadata`, `status`,
`thumbnail_url`, `published_at`, `downloaded_at`, `monitored`,
`created_at`, `updated_at`
FROM `content_items`;--> statement-breakpoint
DROP TABLE `content_items`;--> statement-breakpoint
ALTER TABLE `content_items_new` RENAME TO `content_items`;--> statement-breakpoint
PRAGMA foreign_keys=ON;--> statement-breakpoint
-- Seed ad-hoc download setting (enabled by default)
INSERT OR IGNORE INTO `system_config` (`key`, `value`, `created_at`, `updated_at`)
VALUES ('adhoc.enabled', 'true', datetime('now'), datetime('now'));