-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
307 additions
and
9 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "git.vtb.link/eoefans/internal/app/api/idl" | ||
| "github.com/google/uuid" | ||
| "github.com/lib/pq" | ||
| "gorm.io/driver/mysql" | ||
| "gorm.io/driver/postgres" | ||
| "gorm.io/gorm" | ||
| ) | ||
|
|
||
| var oldDB *gorm.DB | ||
| var newDB *gorm.DB | ||
|
|
||
| const ( | ||
| oldDSN = "vlink02mysql:8715-3314fa3525fc@tcp(vtb-link-02-mysql.mysql.database.azure.com:3306)/eoefans-01?charset=utf8mb4&parseTime=true&loc=Asia%2FShanghai" | ||
| newDSN = "host=c.vlink01cosmosdb.postgres.database.azure.com port=5432 dbname=citus user=citus password=83cc-cddd5e342f63 sslmode=require TimeZone=Asia/Shanghai" | ||
| ) | ||
|
|
||
| func init() { | ||
| var err error | ||
| if oldDB, err = gorm.Open(mysql.Open(oldDSN)); err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| if newDB, err = gorm.Open(postgres.Open(newDSN)); err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
|
|
||
| func main() { | ||
| mPc() | ||
| } | ||
|
|
||
| type NewBilibiliVideo struct { | ||
| idl.BilibiliVideo | ||
| UUID uuid.UUID `gorm:"column:id;type:uuid;primary_key"` | ||
| TagList pq.StringArray `gorm:"column:tag_list;type:varchar(100)[]"` | ||
| } | ||
|
|
||
| func mVideo() { | ||
| var list []*idl.BilibiliVideo | ||
| result := oldDB.Table("bilbil_video").Order("id DESC").Find(&list) | ||
|
|
||
| if result.Error != nil { | ||
| panic(result.Error) | ||
| } | ||
|
|
||
| //for _, video := range list { | ||
| // new := &NewBilibiliVideo{ | ||
| // BilibiliVideo: *video, | ||
| // UUID: uuid.New(), | ||
| // TagList: strings.Split(video.Tag, ","), | ||
| // } | ||
| // | ||
| // result = newDB.Table("bilbil_video").Clauses(clause.OnConflict{DoNothing: true}).Create(new) | ||
| // if result.Error != nil { | ||
| // panic(result.Error) | ||
| // } | ||
| //} | ||
| // | ||
| //fmt.Println(list) | ||
| } | ||
|
|
||
| func mPD() { | ||
| var list []*idl.BilibiliDynamic | ||
| result := oldDB.Table("bilibili_dynamics").Order("id").Find(&list) | ||
| if result.Error != nil { | ||
| panic(result.Error) | ||
| } | ||
|
|
||
| for _, dynamic := range list { | ||
| result = newDB.Table("bilibili_dynamics").Create(dynamic) | ||
| if result.Error != nil { | ||
| panic(result.Error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func mPc() { | ||
| var list []*idl.BilibiliPicture | ||
| result := oldDB.Table("bilibili_pictures").Order("id").Find(&list) | ||
|
|
||
| if result.Error != nil { | ||
| panic(result.Error) | ||
| } | ||
|
|
||
| for _, picture := range list { | ||
| result = newDB.Table("bilibili_pictures").Create(picture) | ||
| if result.Error != nil { | ||
| panic(result.Error) | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.