Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature db migration #96

Merged

Conversation

sampsonye
Copy link
Collaborator

@sampsonye sampsonye commented Mar 9, 2022

Which changes (Bug/Feature):

Fixes #55

Special notes for reviewers:

支持在代码层级进行db migrate
使用步骤:
1. 在internal/migrations中新增go文件
2. 创建Migration{datetime} 结构,并实现Migration接口的两个方法GetCreateAt、Upgrade
3. Upgrade方法写入当前文件创建的时间
4. Upgrade写入需要执行的SQL
5. 在internal/models的models.go的initMigration方法中添加自己的Migration实现

Tips:
根据时间标记升序执行,并将当次版本中时间标记最大的值记入数据库,重复启动应用,升级脚本不会重复执行

@sampsonye sampsonye closed this Mar 9, 2022
@sampsonye sampsonye reopened this Mar 9, 2022
Copy link
Member

@colynn colynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们期望的应该是 引入 migrate工具,对于每次的变更项有migrate工具来解决,不然每次变更还是需要新增migrate的代码,
类似这种 https://github.com/goharbor/harbor/blob/main/src/migration/migration.go

@sampsonye
Copy link
Collaborator Author

sampsonye commented Mar 9, 2022

我们期望的应该是 引入 migrate工具,对于每次的变更项有migrate工具来解决,不然每次变更还是需要新增migrate的代码,
类似这种 https://github.com/goharbor/harbor/blob/main/src/migration/migration.go

开了个讨论帖,一起讨论讨论吧:#99

@codecov-commenter
Copy link

codecov-commenter commented Mar 14, 2022

Codecov Report

Merging #96 (71e24f1) into v1.5.0-feat-app-refactor (5314348) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@                   Coverage Diff                    @@
##           v1.5.0-feat-app-refactor     #96   +/-   ##
========================================================
  Coverage                      4.67%   4.67%           
========================================================
  Files                            10      10           
  Lines                          1454    1454           
========================================================
  Hits                             68      68           
  Misses                         1384    1384           
  Partials                          2       2           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5314348...71e24f1. Read the comment docs.

@sampsonye sampsonye requested a review from colynn March 14, 2022 02:59
Copy link
Member

@colynn colynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks sampsonye

internal/models/models.go Outdated Show resolved Hide resolved
@sampsonye sampsonye requested a review from colynn March 15, 2022 05:43
Copy link
Collaborator

@fanhousanbu fanhousanbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

func sureCreateTable(ormer orm.Ormer) {
ddl := `CREATE TABLE IF NOT EXISTS __dbmigration (
last_migration_date datetime DEFAULT CURRENT_TIMESTAMP
)`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不考虑加个索引什么的?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

记录来自 @sampsonye 的私下回复

https://dev.mysql.com/doc/refman/8.0/en/mysql-indexes.html

Indexes are less important for queries on small tables, or big tables where report queries process most or all of the rows. When a query needs to access most of the rows, reading sequentially is faster than working through an index. Sequential reads minimize disk seeks, even if not all the rows are needed for the query. See [Section 8.2.1.23, “Avoiding Full Table Scans”](https://dev.mysql.com/doc/refman/8.0/en/table-scan-avoidance.html) for details.

Copy link
Collaborator

@fanhousanbu fanhousanbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@colynn colynn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/LGTM

@colynn colynn merged commit b6e82f2 into go-atomci:v1.5.0-feat-app-refactor Mar 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

项目升级时如何同步配置变更?- 引入 migrate 工具
4 participants