DROP INDEX `llm_providers_name_unique`;--> statement-breakpoint
DROP INDEX `llm_providers_slug_unique`;--> statement-breakpoint
DROP INDEX `idx_llm_provider_slug`;--> statement-breakpoint
ALTER TABLE `llm_providers` ADD `user_id` integer REFERENCES users(id);--> statement-breakpoint
UPDATE `llm_providers` SET `user_id` = (SELECT MIN(id) FROM `users`) WHERE `user_id` IS NULL;--> statement-breakpoint
CREATE TABLE `_llm_providers_tmp` (
  `id` integer PRIMARY KEY AUTOINCREMENT,
  `user_id` integer NOT NULL REFERENCES users(id),
  `name` text(100) NOT NULL,
  `slug` text(100) NOT NULL,
  `base_url` text(500),
  `parse_mode` text DEFAULT 'openai' NOT NULL,
  `api_key` text,
  `status` text DEFAULT 'active' NOT NULL,
  `description` text,
  `created_at` integer NOT NULL,
  `updated_at` integer NOT NULL
);--> statement-breakpoint
INSERT INTO `_llm_providers_tmp` SELECT `id`, `user_id`, `name`, `slug`, `base_url`, `parse_mode`, `api_key`, `status`, `description`, `created_at`, `updated_at` FROM `llm_providers`;--> statement-breakpoint
DROP TABLE `llm_providers`;--> statement-breakpoint
ALTER TABLE `_llm_providers_tmp` RENAME TO `llm_providers`;--> statement-breakpoint
CREATE UNIQUE INDEX `idx_llm_provider_user_slug` ON `llm_providers` (`user_id`,`slug`);--> statement-breakpoint
CREATE INDEX `idx_llm_provider_user` ON `llm_providers` (`user_id`);--> statement-breakpoint
CREATE INDEX `idx_llm_provider_status` ON `llm_providers` (`status`);
