Skip to content

Commit d7ea2b4

Browse files
committed
Updated migrator to also create entry in share_ids
1 parent d0bbcd1 commit d7ea2b4

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

share/sql/migrate.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func RunMigration(username, password, host, name, gatewaysvc, token string, port
115115
migrator.NewDb = migrator.NewDb.Debug()
116116
}
117117

118-
migrator.NewDb.AutoMigrate(&model.Share{}, &model.PublicLink{}, &model.ShareState{})
118+
migrator.NewDb.AutoMigrate(&model.ShareID{}, &model.Share{}, &model.PublicLink{}, &model.ShareState{})
119119

120120
migrateShares(ctx, migrator)
121121
fmt.Println("---------------------------------")
@@ -231,7 +231,16 @@ func handleSingleShare(ctx context.Context, migrator Migrator, s *OldShareEntry)
231231
fmt.Printf("An error occured while migrating share %ds: %s\n", s.ID, err.Error())
232232
return
233233
}
234-
var res *gorm.DB
234+
235+
shareId := model.ShareID{
236+
ID: uint(s.ID),
237+
}
238+
res := migrator.NewDb.Create(&shareId)
239+
if res.Error != nil {
240+
fmt.Printf("An error occured while creating ID for share %ds: %s\n", s.ID, res.Error.Error())
241+
return
242+
}
243+
235244
if share.IsShare {
236245
res = migrator.NewDb.Create(&share.Share)
237246
} else {
@@ -266,9 +275,10 @@ func oldShareToNewShare(ctx context.Context, migrator Migrator, s *OldShareEntry
266275
updatedAt = time.Now()
267276
fmt.Printf("WARN: STime not set for share %d\n", s.ID)
268277
}
278+
269279
protoShare := model.ProtoShare{
270-
Model: gorm.Model{
271-
ID: uint(s.ID),
280+
BaseModel: model.BaseModel{
281+
Id: uint(s.ID),
272282
CreatedAt: createdAt,
273283
UpdatedAt: updatedAt,
274284
},

0 commit comments

Comments
 (0)