Skip to content

Commit 13e3313

Browse files
Fotios Tsakiridisclaude
andcommitted
Fix migration 2.83.0 to be idempotent
Make ALTER TABLE check if columns exist before adding them Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 4f779c3 commit 13e3313

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

database/migrations/2.83.0_context_system.sql

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,26 @@
22
-- Adds global_context and project_context columns to projects table
33
-- for per-project customizable AI context
44

5-
-- Add context columns to projects table
6-
ALTER TABLE projects
7-
ADD COLUMN global_context TEXT COMMENT 'Customized global context for this project' AFTER context,
8-
ADD COLUMN project_context TEXT COMMENT 'Language-specific context for this project' AFTER global_context;
5+
-- Add context columns to projects table (if they don't exist)
6+
SET @dbname = DATABASE();
7+
8+
SELECT COUNT(*) INTO @col_exists FROM information_schema.columns
9+
WHERE table_schema = @dbname AND table_name = 'projects' AND column_name = 'global_context';
10+
SET @sql = IF(@col_exists = 0,
11+
'ALTER TABLE projects ADD COLUMN global_context TEXT COMMENT ''Customized global context for this project'' AFTER context',
12+
'SELECT 1');
13+
PREPARE stmt FROM @sql;
14+
EXECUTE stmt;
15+
DEALLOCATE PREPARE stmt;
16+
17+
SELECT COUNT(*) INTO @col_exists FROM information_schema.columns
18+
WHERE table_schema = @dbname AND table_name = 'projects' AND column_name = 'project_context';
19+
SET @sql = IF(@col_exists = 0,
20+
'ALTER TABLE projects ADD COLUMN project_context TEXT COMMENT ''Language-specific context for this project'' AFTER global_context',
21+
'SELECT 1');
22+
PREPARE stmt FROM @sql;
23+
EXECUTE stmt;
24+
DEALLOCATE PREPARE stmt;
925

1026
-- Update schema_migrations
1127
INSERT INTO schema_migrations (version) VALUES ('2.83.0')

0 commit comments

Comments
 (0)