migrations.go 18 KB

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