-
-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔖 chore: Modify the key field data type in the channel table.
- Loading branch information
Showing
5 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package model | ||
|
||
import ( | ||
"one-api/common" | ||
|
||
"github.com/go-gormigrate/gormigrate/v2" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func removeKeyIndexMigration() *gormigrate.Migration { | ||
return &gormigrate.Migration{ | ||
ID: "202405152141", | ||
Migrate: func(tx *gorm.DB) error { | ||
dialect := tx.Dialector.Name() | ||
if dialect == "sqlite" { | ||
return nil | ||
} | ||
|
||
if !tx.Migrator().HasIndex(&Channel{}, "idx_channels_key") { | ||
return nil | ||
} | ||
|
||
err := tx.Migrator().DropIndex(&Channel{}, "idx_channels_key") | ||
if err != nil { | ||
common.SysLog("remove idx_channels_key Failure: " + err.Error()) | ||
} | ||
return nil | ||
}, | ||
Rollback: func(tx *gorm.DB) error { | ||
return nil | ||
}, | ||
} | ||
} | ||
|
||
func migration(db *gorm.DB) error { | ||
// 如果是第一次运行 直接跳过 | ||
if !db.Migrator().HasTable("channels") { | ||
return nil | ||
} | ||
|
||
m := gormigrate.New(db, gormigrate.DefaultOptions, []*gormigrate.Migration{ | ||
removeKeyIndexMigration(), | ||
}) | ||
return m.Migrate() | ||
} |