mirror of
https://github.com/StarFleetCPTN/GoMFT.git
synced 2026-10-30 00:40:25 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3dea48c691 | ||
|
|
ef4bee88b8 | ||
|
|
08d5f0edfc | ||
|
|
1d43a7582d |
No files matched your search
@@ -60,29 +60,6 @@ func InitialSchema() *gormigrate.Migration {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Change the table name from job_histories to job_history
|
|
||||||
if err := tx.Raw("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='job_histories'").Scan(&count).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if count > 0 {
|
|
||||||
if err := tx.Exec("ALTER TABLE job_histories RENAME TO job_history").Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change the table name from password_histories to password_history
|
|
||||||
count = 0
|
|
||||||
if err := tx.Raw("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='password_histories'").Scan(&count).Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if count > 0 {
|
|
||||||
if err := tx.Exec("ALTER TABLE password_histories RENAME TO password_history").Error; err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Users table
|
// Create Users table
|
||||||
if err := tx.Exec(`CREATE TABLE IF NOT EXISTS users (
|
if err := tx.Exec(`CREATE TABLE IF NOT EXISTS users (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
@@ -101,7 +78,7 @@ func InitialSchema() *gormigrate.Migration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create PasswordHistory table
|
// Create PasswordHistory table
|
||||||
if err := tx.Exec(`CREATE TABLE IF NOT EXISTS password_history (
|
if err := tx.Exec(`CREATE TABLE IF NOT EXISTS password_histories (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
password_hash VARCHAR(255) NOT NULL,
|
password_hash VARCHAR(255) NOT NULL,
|
||||||
@@ -212,7 +189,7 @@ func InitialSchema() *gormigrate.Migration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create JobHistory table
|
// Create JobHistory table
|
||||||
if err := tx.Exec(`CREATE TABLE IF NOT EXISTS job_history (
|
if err := tx.Exec(`CREATE TABLE IF NOT EXISTS job_histories (
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
job_id INTEGER NOT NULL,
|
job_id INTEGER NOT NULL,
|
||||||
config_id INTEGER DEFAULT 0,
|
config_id INTEGER DEFAULT 0,
|
||||||
@@ -260,11 +237,11 @@ func InitialSchema() *gormigrate.Migration {
|
|||||||
// Drop tables in reverse order to handle foreign key constraints
|
// Drop tables in reverse order to handle foreign key constraints
|
||||||
tables := []string{
|
tables := []string{
|
||||||
"file_metadata",
|
"file_metadata",
|
||||||
"job_history",
|
"job_histories",
|
||||||
"jobs",
|
"jobs",
|
||||||
"transfer_configs",
|
"transfer_configs",
|
||||||
"password_reset_tokens",
|
"password_reset_tokens",
|
||||||
"password_history",
|
"password_histories",
|
||||||
"users",
|
"users",
|
||||||
}
|
}
|
||||||
for _, table := range tables {
|
for _, table := range tables {
|
||||||
|
|||||||
@@ -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'
|
// UpdateGDriveType updates the source_type and destination_type from 'google_drive' to 'gdrive'
|
||||||
func UpdateGDriveType() *gormigrate.Migration {
|
func UpdateGDriveType() *gormigrate.Migration {
|
||||||
return &gormigrate.Migration{
|
return &gormigrate.Migration{
|
||||||
ID: "003_update_gdrive_type",
|
ID: "002_update_gdrive_type",
|
||||||
Migrate: func(tx *gorm.DB) error {
|
Migrate: func(tx *gorm.DB) error {
|
||||||
// Update source_type
|
// Update source_type
|
||||||
if err := tx.Exec(`UPDATE transfer_configs SET source_type = 'gdrive' WHERE source_type = 'google_drive'`).Error; err != nil {
|
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 {
|
func InitMigrations(db *gorm.DB) *gormigrate.Gormigrate {
|
||||||
migrations := []*gormigrate.Migration{
|
migrations := []*gormigrate.Migration{
|
||||||
InitialSchema(),
|
InitialSchema(),
|
||||||
UpdateBuiltinAuthFields(),
|
|
||||||
UpdateGDriveType(),
|
UpdateGDriveType(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user