createTempTable creates a temporary table for migration
()
| 404 | |
| 405 | // createTempTable creates a temporary table for migration |
| 406 | func (cmd *MigrateKeysCommand) createTempTable() error { |
| 407 | logrus.Info("Creating temporary migration table...") |
| 408 | |
| 409 | // Drop existing temp table if exists |
| 410 | if err := cmd.db.Exec("DROP TABLE IF EXISTS temp_migration").Error; err != nil { |
| 411 | logrus.WithError(err).Warn("Failed to drop existing temp table, continuing anyway") |
| 412 | } |
| 413 | |
| 414 | dbType := cmd.db.Dialector.Name() |
| 415 | var createTableSQL string |
| 416 | |
| 417 | // Use database-specific syntax for better compatibility |
| 418 | switch dbType { |
| 419 | case "mysql": |
| 420 | createTableSQL = ` |
| 421 | CREATE TABLE temp_migration ( |
| 422 | id BIGINT PRIMARY KEY, |
| 423 | key_value_new TEXT, |
| 424 | key_hash_new VARCHAR(255) |
| 425 | ) |
| 426 | ` |
| 427 | case "postgres": |
| 428 | createTableSQL = ` |
| 429 | CREATE TABLE temp_migration ( |
| 430 | id BIGINT PRIMARY KEY, |
| 431 | key_value_new TEXT, |
| 432 | key_hash_new VARCHAR(255) |
| 433 | ) |
| 434 | ` |
| 435 | case "sqlite": |
| 436 | // SQLite uses INTEGER for primary key |
| 437 | createTableSQL = ` |
| 438 | CREATE TABLE temp_migration ( |
| 439 | id INTEGER PRIMARY KEY, |
| 440 | key_value_new TEXT, |
| 441 | key_hash_new VARCHAR(255) |
| 442 | ) |
| 443 | ` |
| 444 | default: |
| 445 | // Fallback to generic syntax |
| 446 | createTableSQL = ` |
| 447 | CREATE TABLE temp_migration ( |
| 448 | id INTEGER PRIMARY KEY, |
| 449 | key_value_new TEXT, |
| 450 | key_hash_new VARCHAR(255) |
| 451 | ) |
| 452 | ` |
| 453 | } |
| 454 | |
| 455 | // Create temp table with minimal structure |
| 456 | if err := cmd.db.Exec(createTableSQL).Error; err != nil { |
| 457 | return fmt.Errorf("failed to create temp_migration table: %w", err) |
| 458 | } |
| 459 | |
| 460 | // Create index for better UPDATE performance (not needed for PRIMARY KEY but helps with JOIN) |
| 461 | // Skip index creation since id is already PRIMARY KEY which creates an implicit index |
| 462 | |
| 463 | return nil |
no test coverage detected