From eafe0f9fe411f3236c7272891148fcbe83be1da5 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Mon, 16 Mar 2026 22:45:34 -0700 Subject: [PATCH] fix(foundry): use IF NOT EXISTS in org migration to handle pre-existing auth tables Some org actors had auth tables created outside the migration system (by earlier queue-based auth code). Migration m0001 fails with "table auth_session_index already exists" on those actors, preventing them from starting. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../db/drizzle/0001_add_auth_and_task_tables.sql | 12 ++++++------ .../backend/src/actors/organization/db/migrations.ts | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/foundry/packages/backend/src/actors/organization/db/drizzle/0001_add_auth_and_task_tables.sql b/foundry/packages/backend/src/actors/organization/db/drizzle/0001_add_auth_and_task_tables.sql index 74d63ef..fcd1b60 100644 --- a/foundry/packages/backend/src/actors/organization/db/drizzle/0001_add_auth_and_task_tables.sql +++ b/foundry/packages/backend/src/actors/organization/db/drizzle/0001_add_auth_and_task_tables.sql @@ -1,4 +1,4 @@ -CREATE TABLE `auth_session_index` ( +CREATE TABLE IF NOT EXISTS `auth_session_index` ( `session_id` text PRIMARY KEY NOT NULL, `session_token` text NOT NULL, `user_id` text NOT NULL, @@ -6,13 +6,13 @@ CREATE TABLE `auth_session_index` ( `updated_at` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE `auth_email_index` ( +CREATE TABLE IF NOT EXISTS `auth_email_index` ( `email` text PRIMARY KEY NOT NULL, `user_id` text NOT NULL, `updated_at` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE `auth_account_index` ( +CREATE TABLE IF NOT EXISTS `auth_account_index` ( `id` text PRIMARY KEY NOT NULL, `provider_id` text NOT NULL, `account_id` text NOT NULL, @@ -20,7 +20,7 @@ CREATE TABLE `auth_account_index` ( `updated_at` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE `auth_verification` ( +CREATE TABLE IF NOT EXISTS `auth_verification` ( `id` text PRIMARY KEY NOT NULL, `identifier` text NOT NULL, `value` text NOT NULL, @@ -29,7 +29,7 @@ CREATE TABLE `auth_verification` ( `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, `repo_id` text NOT NULL, `branch_name` text, @@ -37,7 +37,7 @@ CREATE TABLE `task_index` ( `updated_at` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE `task_summaries` ( +CREATE TABLE IF NOT EXISTS `task_summaries` ( `task_id` text PRIMARY KEY NOT NULL, `repo_id` text NOT NULL, `title` text NOT NULL, diff --git a/foundry/packages/backend/src/actors/organization/db/migrations.ts b/foundry/packages/backend/src/actors/organization/db/migrations.ts index 6a19075..2e8570b 100644 --- a/foundry/packages/backend/src/actors/organization/db/migrations.ts +++ b/foundry/packages/backend/src/actors/organization/db/migrations.ts @@ -121,7 +121,7 @@ CREATE TABLE \`stripe_lookup\` ( \`updated_at\` integer NOT NULL ); `, - m0001: `CREATE TABLE \`auth_session_index\` ( + m0001: `CREATE TABLE IF NOT EXISTS \`auth_session_index\` ( \`session_id\` text PRIMARY KEY NOT NULL, \`session_token\` text NOT NULL, \`user_id\` text NOT NULL, @@ -129,13 +129,13 @@ CREATE TABLE \`stripe_lookup\` ( \`updated_at\` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE \`auth_email_index\` ( +CREATE TABLE IF NOT EXISTS \`auth_email_index\` ( \`email\` text PRIMARY KEY NOT NULL, \`user_id\` text NOT NULL, \`updated_at\` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE \`auth_account_index\` ( +CREATE TABLE IF NOT EXISTS \`auth_account_index\` ( \`id\` text PRIMARY KEY NOT NULL, \`provider_id\` text NOT NULL, \`account_id\` text NOT NULL, @@ -143,7 +143,7 @@ CREATE TABLE \`auth_account_index\` ( \`updated_at\` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE \`auth_verification\` ( +CREATE TABLE IF NOT EXISTS \`auth_verification\` ( \`id\` text PRIMARY KEY NOT NULL, \`identifier\` text NOT NULL, \`value\` text NOT NULL, @@ -152,7 +152,7 @@ CREATE TABLE \`auth_verification\` ( \`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, \`repo_id\` text NOT NULL, \`branch_name\` text, @@ -160,7 +160,7 @@ CREATE TABLE \`task_index\` ( \`updated_at\` integer NOT NULL ); --> statement-breakpoint -CREATE TABLE \`task_summaries\` ( +CREATE TABLE IF NOT EXISTS \`task_summaries\` ( \`task_id\` text PRIMARY KEY NOT NULL, \`repo_id\` text NOT NULL, \`title\` text NOT NULL,