mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-09-08 15:41:20 +02:00
refactor: Remove outdated migration for built-in auth fields and add new migration for updating Google Drive type
- Deleted the migration that updated the use_builtin_auth field to separate source and destination fields. - Introduced a new migration to update source_type and destination_type from 'google_drive' to 'gdrive' in transfer_configs.
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
package migrations
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// UpdateBuiltinAuthFields updates the use_builtin_auth field to separate source and destination fields
|
||||
func UpdateBuiltinAuthFields() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "002_update_builtin_auth_fields",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
// First, add the new columns
|
||||
if err := tx.Exec(`ALTER TABLE transfer_configs ADD COLUMN use_builtin_auth_source BOOLEAN`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Exec(`ALTER TABLE transfer_configs ADD COLUMN use_builtin_auth_dest BOOLEAN`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy the old value to both new columns
|
||||
if err := tx.Exec(`UPDATE transfer_configs SET
|
||||
use_builtin_auth_source = use_builtin_auth,
|
||||
use_builtin_auth_dest = use_builtin_auth`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Drop the old column
|
||||
return tx.Exec(`ALTER TABLE transfer_configs DROP COLUMN use_builtin_auth`).Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
// Add back the original column
|
||||
if err := tx.Exec(`ALTER TABLE transfer_configs ADD COLUMN use_builtin_auth BOOLEAN`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Copy the source value back (could also use dest, they should be the same)
|
||||
if err := tx.Exec(`UPDATE transfer_configs SET use_builtin_auth = use_builtin_auth_source`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Drop the new columns
|
||||
if err := tx.Exec(`ALTER TABLE transfer_configs DROP COLUMN use_builtin_auth_source`).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Exec(`ALTER TABLE transfer_configs DROP COLUMN use_builtin_auth_dest`).Error
|
||||
},
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
||||
// UpdateGDriveType updates the source_type and destination_type from 'google_drive' to 'gdrive'
|
||||
func UpdateGDriveType() *gormigrate.Migration {
|
||||
return &gormigrate.Migration{
|
||||
ID: "003_update_gdrive_type",
|
||||
ID: "002_update_gdrive_type",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
// Update source_type
|
||||
if err := tx.Exec(`UPDATE transfer_configs SET source_type = 'gdrive' WHERE source_type = 'google_drive'`).Error; err != nil {
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
func InitMigrations(db *gorm.DB) *gormigrate.Gormigrate {
|
||||
migrations := []*gormigrate.Migration{
|
||||
InitialSchema(),
|
||||
UpdateBuiltinAuthFields(),
|
||||
UpdateGDriveType(),
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user