Make squashed baseline migrations idempotent

Use CREATE TABLE IF NOT EXISTS and CREATE UNIQUE INDEX IF NOT
EXISTS so the squashed baseline can run against actors that
already have tables from the pre-squash migration sequence.
This fixes the "table already exists" error when org workspace
actors wake up with stale migration journals.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nathan Flurry 2026-03-12 22:28:55 -07:00
parent c410e24057
commit 356c146035
5 changed files with 22 additions and 22 deletions

View file

@ -1,4 +1,4 @@
CREATE TABLE `events` (
CREATE TABLE IF NOT EXISTS `events` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`task_id` text,
`branch_name` text,

View file

@ -1,4 +1,4 @@
CREATE TABLE `branches` (
CREATE TABLE IF NOT EXISTS `branches` (
`branch_name` text PRIMARY KEY NOT NULL,
`commit_sha` text NOT NULL,
`parent_branch` text,
@ -11,7 +11,7 @@ CREATE TABLE `branches` (
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `pr_cache` (
CREATE TABLE IF NOT EXISTS `pr_cache` (
`branch_name` text PRIMARY KEY NOT NULL,
`pr_number` integer NOT NULL,
`state` text NOT NULL,
@ -26,13 +26,13 @@ CREATE TABLE `pr_cache` (
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `repo_meta` (
CREATE TABLE IF NOT EXISTS `repo_meta` (
`id` integer PRIMARY KEY NOT NULL,
`remote_url` text NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `task_index` (
CREATE TABLE IF NOT EXISTS `task_index` (
`task_id` text PRIMARY KEY NOT NULL,
`branch_name` text,
`created_at` integer NOT NULL,

View file

@ -1,11 +1,11 @@
CREATE TABLE `sandbox_instance` (
CREATE TABLE IF NOT EXISTS `sandbox_instance` (
`id` integer PRIMARY KEY NOT NULL,
`metadata_json` text NOT NULL,
`status` text NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `sandbox_session_events` (
CREATE TABLE IF NOT EXISTS `sandbox_session_events` (
`id` text PRIMARY KEY NOT NULL,
`session_id` text NOT NULL,
`event_index` integer NOT NULL,
@ -15,8 +15,8 @@ CREATE TABLE `sandbox_session_events` (
`payload_json` text NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `sandbox_session_events_session_id_event_index_unique` ON `sandbox_session_events` (`session_id`,`event_index`);--> statement-breakpoint
CREATE TABLE `sandbox_sessions` (
CREATE UNIQUE INDEX IF NOT EXISTS `sandbox_session_events_session_id_event_index_unique` ON `sandbox_session_events` (`session_id`,`event_index`);--> statement-breakpoint
CREATE TABLE IF NOT EXISTS `sandbox_sessions` (
`id` text PRIMARY KEY NOT NULL,
`agent` text NOT NULL,
`agent_session_id` text NOT NULL,

View file

@ -1,4 +1,4 @@
CREATE TABLE `task` (
CREATE TABLE IF NOT EXISTS `task` (
`id` integer PRIMARY KEY NOT NULL,
`branch_name` text,
`title` text,
@ -12,7 +12,7 @@ CREATE TABLE `task` (
CONSTRAINT "task_singleton_id_check" CHECK("task"."id" = 1)
);
--> statement-breakpoint
CREATE TABLE `task_runtime` (
CREATE TABLE IF NOT EXISTS `task_runtime` (
`id` integer PRIMARY KEY NOT NULL,
`active_sandbox_id` text,
`active_session_id` text,
@ -23,7 +23,7 @@ CREATE TABLE `task_runtime` (
CONSTRAINT "task_runtime_singleton_id_check" CHECK("task_runtime"."id" = 1)
);
--> statement-breakpoint
CREATE TABLE `task_sandboxes` (
CREATE TABLE IF NOT EXISTS `task_sandboxes` (
`sandbox_id` text PRIMARY KEY NOT NULL,
`provider_id` text NOT NULL,
`sandbox_actor_id` text,
@ -34,7 +34,7 @@ CREATE TABLE `task_sandboxes` (
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `task_workbench_sessions` (
CREATE TABLE IF NOT EXISTS `task_workbench_sessions` (
`session_id` text PRIMARY KEY NOT NULL,
`session_name` text NOT NULL,
`model` text NOT NULL,

View file

@ -1,4 +1,4 @@
CREATE TABLE `app_sessions` (
CREATE TABLE IF NOT EXISTS `app_sessions` (
`id` text PRIMARY KEY NOT NULL,
`current_user_id` text,
`current_user_name` text,
@ -18,7 +18,7 @@ CREATE TABLE `app_sessions` (
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `invoices` (
CREATE TABLE IF NOT EXISTS `invoices` (
`id` text PRIMARY KEY NOT NULL,
`label` text NOT NULL,
`issued_at` text NOT NULL,
@ -27,7 +27,7 @@ CREATE TABLE `invoices` (
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `organization_members` (
CREATE TABLE IF NOT EXISTS `organization_members` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`email` text NOT NULL,
@ -36,7 +36,7 @@ CREATE TABLE `organization_members` (
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `organization_profile` (
CREATE TABLE IF NOT EXISTS `organization_profile` (
`id` text PRIMARY KEY NOT NULL,
`kind` text NOT NULL,
`github_account_id` text NOT NULL,
@ -67,31 +67,31 @@ CREATE TABLE `organization_profile` (
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `provider_profiles` (
CREATE TABLE IF NOT EXISTS `provider_profiles` (
`provider_id` text PRIMARY KEY NOT NULL,
`profile_json` text NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `repos` (
CREATE TABLE IF NOT EXISTS `repos` (
`repo_id` text PRIMARY KEY NOT NULL,
`remote_url` text NOT NULL,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `seat_assignments` (
CREATE TABLE IF NOT EXISTS `seat_assignments` (
`email` text PRIMARY KEY NOT NULL,
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `stripe_lookup` (
CREATE TABLE IF NOT EXISTS `stripe_lookup` (
`lookup_key` text PRIMARY KEY NOT NULL,
`organization_id` text NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `task_lookup` (
CREATE TABLE IF NOT EXISTS `task_lookup` (
`task_id` text PRIMARY KEY NOT NULL,
`repo_id` text NOT NULL
);