migrations.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package migrations
  5. import (
  6. "bytes"
  7. "encoding/json"
  8. "fmt"
  9. "io/ioutil"
  10. "os"
  11. "path"
  12. "path/filepath"
  13. "strings"
  14. "time"
  15. "github.com/Unknwon/com"
  16. "github.com/go-xorm/xorm"
  17. gouuid "github.com/satori/go.uuid"
  18. log "gopkg.in/clog.v1"
  19. "gopkg.in/ini.v1"
  20. "github.com/gogits/gogs/modules/base"
  21. "github.com/gogits/gogs/modules/setting"
  22. )
  23. const _MIN_DB_VER = 4
  24. type Migration interface {
  25. Description() string
  26. Migrate(*xorm.Engine) error
  27. }
  28. type migration struct {
  29. description string
  30. migrate func(*xorm.Engine) error
  31. }
  32. func NewMigration(desc string, fn func(*xorm.Engine) error) Migration {
  33. return &migration{desc, fn}
  34. }
  35. func (m *migration) Description() string {
  36. return m.description
  37. }
  38. func (m *migration) Migrate(x *xorm.Engine) error {
  39. return m.migrate(x)
  40. }
  41. // The version table. Should have only one row with id==1
  42. type Version struct {
  43. ID int64 `xorm:"pk autoincr"`
  44. Version int64
  45. }
  46. // This is a sequence of migrations. Add new migrations to the bottom of the list.
  47. // If you want to "retire" a migration, remove it from the top of the list and
  48. // update _MIN_VER_DB accordingly
  49. var migrations = []Migration{
  50. // v0 -> v4: before 0.6.0 -> 0.7.33
  51. NewMigration("fix locale file load panic", fixLocaleFileLoadPanic), // V4 -> V5:v0.6.0
  52. NewMigration("trim action compare URL prefix", trimCommitActionAppUrlPrefix), // V5 -> V6:v0.6.3
  53. NewMigration("generate issue-label from issue", issueToIssueLabel), // V6 -> V7:v0.6.4
  54. NewMigration("refactor attachment table", attachmentRefactor), // V7 -> V8:v0.6.4
  55. NewMigration("rename pull request fields", renamePullRequestFields), // V8 -> V9:v0.6.16
  56. NewMigration("clean up migrate repo info", cleanUpMigrateRepoInfo), // V9 -> V10:v0.6.20
  57. NewMigration("generate rands and salt for organizations", generateOrgRandsAndSalt), // V10 -> V11:v0.8.5
  58. NewMigration("convert date to unix timestamp", convertDateToUnix), // V11 -> V12:v0.9.2
  59. NewMigration("convert LDAP UseSSL option to SecurityProtocol", ldapUseSSLToSecurityProtocol), // V12 -> V13:v0.9.37
  60. // v13 -> v14:v0.9.87
  61. NewMigration("set comment updated with created", setCommentUpdatedWithCreated),
  62. }
  63. // Migrate database to current version
  64. func Migrate(x *xorm.Engine) error {
  65. if err := x.Sync(new(Version)); err != nil {
  66. return fmt.Errorf("sync: %v", err)
  67. }
  68. currentVersion := &Version{ID: 1}
  69. has, err := x.Get(currentVersion)
  70. if err != nil {
  71. return fmt.Errorf("get: %v", err)
  72. } else if !has {
  73. // If the version record does not exist we think
  74. // it is a fresh installation and we can skip all migrations.
  75. currentVersion.ID = 0
  76. currentVersion.Version = int64(_MIN_DB_VER + len(migrations))
  77. if _, err = x.InsertOne(currentVersion); err != nil {
  78. return fmt.Errorf("insert: %v", err)
  79. }
  80. }
  81. v := currentVersion.Version
  82. if _MIN_DB_VER > v {
  83. log.Fatal(4, `Gogs no longer supports auto-migration from your previously installed version.
  84. Please try to upgrade to a lower version (>= v0.6.0) first, then upgrade to current version.`)
  85. return nil
  86. }
  87. if int(v-_MIN_DB_VER) > len(migrations) {
  88. // User downgraded Gogs.
  89. currentVersion.Version = int64(len(migrations) + _MIN_DB_VER)
  90. _, err = x.Id(1).Update(currentVersion)
  91. return err
  92. }
  93. for i, m := range migrations[v-_MIN_DB_VER:] {
  94. log.Info("Migration: %s", m.Description())
  95. if err = m.Migrate(x); err != nil {
  96. return fmt.Errorf("do migrate: %v", err)
  97. }
  98. currentVersion.Version = v + int64(i) + 1
  99. if _, err = x.Id(1).Update(currentVersion); err != nil {
  100. return err
  101. }
  102. }
  103. return nil
  104. }
  105. func sessionRelease(sess *xorm.Session) {
  106. if !sess.IsCommitedOrRollbacked {
  107. sess.Rollback()
  108. }
  109. sess.Close()
  110. }
  111. func fixLocaleFileLoadPanic(_ *xorm.Engine) error {
  112. cfg, err := ini.Load(setting.CustomConf)
  113. if err != nil {
  114. return fmt.Errorf("load custom config: %v", err)
  115. }
  116. cfg.DeleteSection("i18n")
  117. if err = cfg.SaveTo(setting.CustomConf); err != nil {
  118. return fmt.Errorf("save custom config: %v", err)
  119. }
  120. setting.Langs = strings.Split(strings.Replace(strings.Join(setting.Langs, ","), "fr-CA", "fr-FR", 1), ",")
  121. return nil
  122. }
  123. func trimCommitActionAppUrlPrefix(x *xorm.Engine) error {
  124. type PushCommit struct {
  125. Sha1 string
  126. Message string
  127. AuthorEmail string
  128. AuthorName string
  129. }
  130. type PushCommits struct {
  131. Len int
  132. Commits []*PushCommit
  133. CompareUrl string
  134. }
  135. type Action struct {
  136. ID int64 `xorm:"pk autoincr"`
  137. Content string `xorm:"TEXT"`
  138. }
  139. results, err := x.Query("SELECT `id`,`content` FROM `action` WHERE `op_type`=?", 5)
  140. if err != nil {
  141. return fmt.Errorf("select commit actions: %v", err)
  142. }
  143. sess := x.NewSession()
  144. defer sessionRelease(sess)
  145. if err = sess.Begin(); err != nil {
  146. return err
  147. }
  148. var pushCommits *PushCommits
  149. for _, action := range results {
  150. actID := com.StrTo(string(action["id"])).MustInt64()
  151. if actID == 0 {
  152. continue
  153. }
  154. pushCommits = new(PushCommits)
  155. if err = json.Unmarshal(action["content"], pushCommits); err != nil {
  156. return fmt.Errorf("unmarshal action content[%d]: %v", actID, err)
  157. }
  158. infos := strings.Split(pushCommits.CompareUrl, "/")
  159. if len(infos) <= 4 {
  160. continue
  161. }
  162. pushCommits.CompareUrl = strings.Join(infos[len(infos)-4:], "/")
  163. p, err := json.Marshal(pushCommits)
  164. if err != nil {
  165. return fmt.Errorf("marshal action content[%d]: %v", actID, err)
  166. }
  167. if _, err = sess.Id(actID).Update(&Action{
  168. Content: string(p),
  169. }); err != nil {
  170. return fmt.Errorf("update action[%d]: %v", actID, err)
  171. }
  172. }
  173. return sess.Commit()
  174. }
  175. func issueToIssueLabel(x *xorm.Engine) error {
  176. type IssueLabel struct {
  177. ID int64 `xorm:"pk autoincr"`
  178. IssueID int64 `xorm:"UNIQUE(s)"`
  179. LabelID int64 `xorm:"UNIQUE(s)"`
  180. }
  181. issueLabels := make([]*IssueLabel, 0, 50)
  182. results, err := x.Query("SELECT `id`,`label_ids` FROM `issue`")
  183. if err != nil {
  184. if strings.Contains(err.Error(), "no such column") ||
  185. strings.Contains(err.Error(), "Unknown column") {
  186. return nil
  187. }
  188. return fmt.Errorf("select issues: %v", err)
  189. }
  190. for _, issue := range results {
  191. issueID := com.StrTo(issue["id"]).MustInt64()
  192. // Just in case legacy code can have duplicated IDs for same label.
  193. mark := make(map[int64]bool)
  194. for _, idStr := range strings.Split(string(issue["label_ids"]), "|") {
  195. labelID := com.StrTo(strings.TrimPrefix(idStr, "$")).MustInt64()
  196. if labelID == 0 || mark[labelID] {
  197. continue
  198. }
  199. mark[labelID] = true
  200. issueLabels = append(issueLabels, &IssueLabel{
  201. IssueID: issueID,
  202. LabelID: labelID,
  203. })
  204. }
  205. }
  206. sess := x.NewSession()
  207. defer sessionRelease(sess)
  208. if err = sess.Begin(); err != nil {
  209. return err
  210. }
  211. if err = sess.Sync2(new(IssueLabel)); err != nil {
  212. return fmt.Errorf("Sync2: %v", err)
  213. } else if _, err = sess.Insert(issueLabels); err != nil {
  214. return fmt.Errorf("insert issue-labels: %v", err)
  215. }
  216. return sess.Commit()
  217. }
  218. func attachmentRefactor(x *xorm.Engine) error {
  219. type Attachment struct {
  220. ID int64 `xorm:"pk autoincr"`
  221. UUID string `xorm:"uuid INDEX"`
  222. // For rename purpose.
  223. Path string `xorm:"-"`
  224. NewPath string `xorm:"-"`
  225. }
  226. results, err := x.Query("SELECT * FROM `attachment`")
  227. if err != nil {
  228. return fmt.Errorf("select attachments: %v", err)
  229. }
  230. attachments := make([]*Attachment, 0, len(results))
  231. for _, attach := range results {
  232. if !com.IsExist(string(attach["path"])) {
  233. // If the attachment is already missing, there is no point to update it.
  234. continue
  235. }
  236. attachments = append(attachments, &Attachment{
  237. ID: com.StrTo(attach["id"]).MustInt64(),
  238. UUID: gouuid.NewV4().String(),
  239. Path: string(attach["path"]),
  240. })
  241. }
  242. sess := x.NewSession()
  243. defer sessionRelease(sess)
  244. if err = sess.Begin(); err != nil {
  245. return err
  246. }
  247. if err = sess.Sync2(new(Attachment)); err != nil {
  248. return fmt.Errorf("Sync2: %v", err)
  249. }
  250. // Note: Roll back for rename can be a dead loop,
  251. // so produces a backup file.
  252. var buf bytes.Buffer
  253. buf.WriteString("# old path -> new path\n")
  254. // Update database first because this is where error happens the most often.
  255. for _, attach := range attachments {
  256. if _, err = sess.Id(attach.ID).Update(attach); err != nil {
  257. return err
  258. }
  259. attach.NewPath = path.Join(setting.AttachmentPath, attach.UUID[0:1], attach.UUID[1:2], attach.UUID)
  260. buf.WriteString(attach.Path)
  261. buf.WriteString("\t")
  262. buf.WriteString(attach.NewPath)
  263. buf.WriteString("\n")
  264. }
  265. // Then rename attachments.
  266. isSucceed := true
  267. defer func() {
  268. if isSucceed {
  269. return
  270. }
  271. dumpPath := path.Join(setting.LogRootPath, "attachment_path.dump")
  272. ioutil.WriteFile(dumpPath, buf.Bytes(), 0666)
  273. fmt.Println("Fail to rename some attachments, old and new paths are saved into:", dumpPath)
  274. }()
  275. for _, attach := range attachments {
  276. if err = os.MkdirAll(path.Dir(attach.NewPath), os.ModePerm); err != nil {
  277. isSucceed = false
  278. return err
  279. }
  280. if err = os.Rename(attach.Path, attach.NewPath); err != nil {
  281. isSucceed = false
  282. return err
  283. }
  284. }
  285. return sess.Commit()
  286. }
  287. func renamePullRequestFields(x *xorm.Engine) (err error) {
  288. type PullRequest struct {
  289. ID int64 `xorm:"pk autoincr"`
  290. PullID int64 `xorm:"INDEX"`
  291. PullIndex int64
  292. HeadBarcnh string
  293. IssueID int64 `xorm:"INDEX"`
  294. Index int64
  295. HeadBranch string
  296. }
  297. if err = x.Sync(new(PullRequest)); err != nil {
  298. return fmt.Errorf("sync: %v", err)
  299. }
  300. results, err := x.Query("SELECT `id`,`pull_id`,`pull_index`,`head_barcnh` FROM `pull_request`")
  301. if err != nil {
  302. if strings.Contains(err.Error(), "no such column") {
  303. return nil
  304. }
  305. return fmt.Errorf("select pull requests: %v", err)
  306. }
  307. sess := x.NewSession()
  308. defer sessionRelease(sess)
  309. if err = sess.Begin(); err != nil {
  310. return err
  311. }
  312. var pull *PullRequest
  313. for _, pr := range results {
  314. pull = &PullRequest{
  315. ID: com.StrTo(pr["id"]).MustInt64(),
  316. IssueID: com.StrTo(pr["pull_id"]).MustInt64(),
  317. Index: com.StrTo(pr["pull_index"]).MustInt64(),
  318. HeadBranch: string(pr["head_barcnh"]),
  319. }
  320. if pull.Index == 0 {
  321. continue
  322. }
  323. if _, err = sess.Id(pull.ID).Update(pull); err != nil {
  324. return err
  325. }
  326. }
  327. return sess.Commit()
  328. }
  329. func cleanUpMigrateRepoInfo(x *xorm.Engine) (err error) {
  330. type (
  331. User struct {
  332. ID int64 `xorm:"pk autoincr"`
  333. LowerName string
  334. }
  335. Repository struct {
  336. ID int64 `xorm:"pk autoincr"`
  337. OwnerID int64
  338. LowerName string
  339. }
  340. )
  341. repos := make([]*Repository, 0, 25)
  342. if err = x.Where("is_mirror=?", false).Find(&repos); err != nil {
  343. return fmt.Errorf("select all non-mirror repositories: %v", err)
  344. }
  345. var user *User
  346. for _, repo := range repos {
  347. user = &User{ID: repo.OwnerID}
  348. has, err := x.Get(user)
  349. if err != nil {
  350. return fmt.Errorf("get owner of repository[%d - %d]: %v", repo.ID, repo.OwnerID, err)
  351. } else if !has {
  352. continue
  353. }
  354. configPath := filepath.Join(setting.RepoRootPath, user.LowerName, repo.LowerName+".git/config")
  355. // In case repository file is somehow missing.
  356. if !com.IsFile(configPath) {
  357. continue
  358. }
  359. cfg, err := ini.Load(configPath)
  360. if err != nil {
  361. return fmt.Errorf("open config file: %v", err)
  362. }
  363. cfg.DeleteSection("remote \"origin\"")
  364. if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
  365. return fmt.Errorf("save config file: %v", err)
  366. }
  367. }
  368. return nil
  369. }
  370. func generateOrgRandsAndSalt(x *xorm.Engine) (err error) {
  371. type User struct {
  372. ID int64 `xorm:"pk autoincr"`
  373. Rands string `xorm:"VARCHAR(10)"`
  374. Salt string `xorm:"VARCHAR(10)"`
  375. }
  376. orgs := make([]*User, 0, 10)
  377. if err = x.Where("type=1").And("rands=''").Find(&orgs); err != nil {
  378. return fmt.Errorf("select all organizations: %v", err)
  379. }
  380. sess := x.NewSession()
  381. defer sessionRelease(sess)
  382. if err = sess.Begin(); err != nil {
  383. return err
  384. }
  385. for _, org := range orgs {
  386. if org.Rands, err = base.GetRandomString(10); err != nil {
  387. return err
  388. }
  389. if org.Salt, err = base.GetRandomString(10); err != nil {
  390. return err
  391. }
  392. if _, err = sess.Id(org.ID).Update(org); err != nil {
  393. return err
  394. }
  395. }
  396. return sess.Commit()
  397. }
  398. type TAction struct {
  399. ID int64 `xorm:"pk autoincr"`
  400. CreatedUnix int64
  401. }
  402. func (t *TAction) TableName() string { return "action" }
  403. type TNotice struct {
  404. ID int64 `xorm:"pk autoincr"`
  405. CreatedUnix int64
  406. }
  407. func (t *TNotice) TableName() string { return "notice" }
  408. type TComment struct {
  409. ID int64 `xorm:"pk autoincr"`
  410. CreatedUnix int64
  411. }
  412. func (t *TComment) TableName() string { return "comment" }
  413. type TIssue struct {
  414. ID int64 `xorm:"pk autoincr"`
  415. DeadlineUnix int64
  416. CreatedUnix int64
  417. UpdatedUnix int64
  418. }
  419. func (t *TIssue) TableName() string { return "issue" }
  420. type TMilestone struct {
  421. ID int64 `xorm:"pk autoincr"`
  422. DeadlineUnix int64
  423. ClosedDateUnix int64
  424. }
  425. func (t *TMilestone) TableName() string { return "milestone" }
  426. type TAttachment struct {
  427. ID int64 `xorm:"pk autoincr"`
  428. CreatedUnix int64
  429. }
  430. func (t *TAttachment) TableName() string { return "attachment" }
  431. type TLoginSource struct {
  432. ID int64 `xorm:"pk autoincr"`
  433. CreatedUnix int64
  434. UpdatedUnix int64
  435. }
  436. func (t *TLoginSource) TableName() string { return "login_source" }
  437. type TPull struct {
  438. ID int64 `xorm:"pk autoincr"`
  439. MergedUnix int64
  440. }
  441. func (t *TPull) TableName() string { return "pull_request" }
  442. type TRelease struct {
  443. ID int64 `xorm:"pk autoincr"`
  444. CreatedUnix int64
  445. }
  446. func (t *TRelease) TableName() string { return "release" }
  447. type TRepo struct {
  448. ID int64 `xorm:"pk autoincr"`
  449. CreatedUnix int64
  450. UpdatedUnix int64
  451. }
  452. func (t *TRepo) TableName() string { return "repository" }
  453. type TMirror struct {
  454. ID int64 `xorm:"pk autoincr"`
  455. UpdatedUnix int64
  456. NextUpdateUnix int64
  457. }
  458. func (t *TMirror) TableName() string { return "mirror" }
  459. type TPublicKey struct {
  460. ID int64 `xorm:"pk autoincr"`
  461. CreatedUnix int64
  462. UpdatedUnix int64
  463. }
  464. func (t *TPublicKey) TableName() string { return "public_key" }
  465. type TDeployKey struct {
  466. ID int64 `xorm:"pk autoincr"`
  467. CreatedUnix int64
  468. UpdatedUnix int64
  469. }
  470. func (t *TDeployKey) TableName() string { return "deploy_key" }
  471. type TAccessToken struct {
  472. ID int64 `xorm:"pk autoincr"`
  473. CreatedUnix int64
  474. UpdatedUnix int64
  475. }
  476. func (t *TAccessToken) TableName() string { return "access_token" }
  477. type TUser struct {
  478. ID int64 `xorm:"pk autoincr"`
  479. CreatedUnix int64
  480. UpdatedUnix int64
  481. }
  482. func (t *TUser) TableName() string { return "user" }
  483. type TWebhook struct {
  484. ID int64 `xorm:"pk autoincr"`
  485. CreatedUnix int64
  486. UpdatedUnix int64
  487. }
  488. func (t *TWebhook) TableName() string { return "webhook" }
  489. func convertDateToUnix(x *xorm.Engine) (err error) {
  490. log.Info("This migration could take up to minutes, please be patient.")
  491. type Bean struct {
  492. ID int64 `xorm:"pk autoincr"`
  493. Created time.Time
  494. Updated time.Time
  495. Merged time.Time
  496. Deadline time.Time
  497. ClosedDate time.Time
  498. NextUpdate time.Time
  499. }
  500. var tables = []struct {
  501. name string
  502. cols []string
  503. bean interface{}
  504. }{
  505. {"action", []string{"created"}, new(TAction)},
  506. {"notice", []string{"created"}, new(TNotice)},
  507. {"comment", []string{"created"}, new(TComment)},
  508. {"issue", []string{"deadline", "created", "updated"}, new(TIssue)},
  509. {"milestone", []string{"deadline", "closed_date"}, new(TMilestone)},
  510. {"attachment", []string{"created"}, new(TAttachment)},
  511. {"login_source", []string{"created", "updated"}, new(TLoginSource)},
  512. {"pull_request", []string{"merged"}, new(TPull)},
  513. {"release", []string{"created"}, new(TRelease)},
  514. {"repository", []string{"created", "updated"}, new(TRepo)},
  515. {"mirror", []string{"updated", "next_update"}, new(TMirror)},
  516. {"public_key", []string{"created", "updated"}, new(TPublicKey)},
  517. {"deploy_key", []string{"created", "updated"}, new(TDeployKey)},
  518. {"access_token", []string{"created", "updated"}, new(TAccessToken)},
  519. {"user", []string{"created", "updated"}, new(TUser)},
  520. {"webhook", []string{"created", "updated"}, new(TWebhook)},
  521. }
  522. for _, table := range tables {
  523. log.Info("Converting table: %s", table.name)
  524. if err = x.Sync2(table.bean); err != nil {
  525. return fmt.Errorf("Sync [table: %s]: %v", table.name, err)
  526. }
  527. offset := 0
  528. for {
  529. beans := make([]*Bean, 0, 100)
  530. if err = x.Sql(fmt.Sprintf("SELECT * FROM `%s` ORDER BY id ASC LIMIT 100 OFFSET %d",
  531. table.name, offset)).Find(&beans); err != nil {
  532. return fmt.Errorf("select beans [table: %s, offset: %d]: %v", table.name, offset, err)
  533. }
  534. log.Trace("Table [%s]: offset: %d, beans: %d", table.name, offset, len(beans))
  535. if len(beans) == 0 {
  536. break
  537. }
  538. offset += 100
  539. baseSQL := "UPDATE `" + table.name + "` SET "
  540. for _, bean := range beans {
  541. valSQLs := make([]string, 0, len(table.cols))
  542. for _, col := range table.cols {
  543. fieldSQL := ""
  544. fieldSQL += col + "_unix = "
  545. switch col {
  546. case "deadline":
  547. if bean.Deadline.IsZero() {
  548. continue
  549. }
  550. fieldSQL += com.ToStr(bean.Deadline.Unix())
  551. case "created":
  552. fieldSQL += com.ToStr(bean.Created.Unix())
  553. case "updated":
  554. fieldSQL += com.ToStr(bean.Updated.Unix())
  555. case "closed_date":
  556. fieldSQL += com.ToStr(bean.ClosedDate.Unix())
  557. case "merged":
  558. fieldSQL += com.ToStr(bean.Merged.Unix())
  559. case "next_update":
  560. fieldSQL += com.ToStr(bean.NextUpdate.Unix())
  561. }
  562. valSQLs = append(valSQLs, fieldSQL)
  563. }
  564. if len(valSQLs) == 0 {
  565. continue
  566. }
  567. if _, err = x.Exec(baseSQL + strings.Join(valSQLs, ",") + " WHERE id = " + com.ToStr(bean.ID)); err != nil {
  568. return fmt.Errorf("update bean [table: %s, id: %d]: %v", table.name, bean.ID, err)
  569. }
  570. }
  571. }
  572. }
  573. return nil
  574. }