Files
nekonest-cloud/drizzle/0003_medical_rocket_racer.sql

41 lines
3.1 KiB
SQL

ALTER TABLE `provisioning_operations` ADD `requested_by` text DEFAULT 'system:legacy' NOT NULL;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `reason` text DEFAULT 'legacy provisioning request' NOT NULL;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `lifecycle_before` text DEFAULT 'requested' NOT NULL;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `payload_version` integer DEFAULT 1 NOT NULL;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `lease_owner` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `lease_token_hash` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `lease_expires_at` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `attempt_count` integer DEFAULT 0 NOT NULL;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `max_attempts` integer DEFAULT 5 NOT NULL;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `started_at` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `completed_at` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `completion_hash` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `observed_generation` integer;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `result_runtime_ref` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `result_runtime_version` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `result_relay_origin` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `result_secret_bundle_ref` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `health_status` text;--> statement-breakpoint
ALTER TABLE `provisioning_operations` ADD `health_checked_at` text;--> statement-breakpoint
UPDATE `provisioning_operations`
SET `status` = 'canceled',
`error_code` = 'legacy_duplicate_active_operation',
`error_detail` = 'Migration kept only the newest active operation for this tenant.',
`completed_at` = CURRENT_TIMESTAMP,
`updated_at` = CURRENT_TIMESTAMP
WHERE `status` IN ('requested', 'leased')
AND `id` <> (
SELECT newer.`id`
FROM `provisioning_operations` AS newer
WHERE newer.`tenant_id` = `provisioning_operations`.`tenant_id`
AND newer.`status` IN ('requested', 'leased')
ORDER BY newer.`created_at` DESC, newer.`id` DESC
LIMIT 1
);--> statement-breakpoint
CREATE UNIQUE INDEX `idx_operations_one_active_tenant` ON `provisioning_operations` (`tenant_id`) WHERE "provisioning_operations"."status" IN ('requested', 'leased');--> statement-breakpoint
CREATE INDEX `idx_operations_lease_expiry` ON `provisioning_operations` (`status`,`lease_expires_at`);--> statement-breakpoint
ALTER TABLE `tenant_instances` ADD `runtime_ref` text;--> statement-breakpoint
ALTER TABLE `tenant_instances` ADD `relay_origin` text;--> statement-breakpoint
ALTER TABLE `tenant_instances` ADD `secret_bundle_ref` text;--> statement-breakpoint
ALTER TABLE `tenant_instances` ADD `relay_ready` integer DEFAULT false NOT NULL;