Commit c05c908
authored
refactor: migrate to jdbi (#241)
迁移到 JDBI,原因如下:
1. AI 非常擅长编写 SQL,更不擅长 ktorm 这种 DSL
2. sql 更加灵活自由,可以方便地使用PG自身能力,配合freemarker可以有不错的灵活性
3. 逻辑安全性由单元测试保证,已引入 embedded pg 用于测试
## Summary by Sourcery
将持久化层从 Ktorm 迁移到 Jdbi,引入由 Flyway 管理的数据库 schema,以及基于嵌入式 Postgres
的集成测试,并修复核心服务和任务中的若干查询与分页边界情况。
New Features:
- 引入基于 Jdbi 的仓库与数据库访问配置,替代 Ktorm
Bug Fixes:
- 修复 CopilotScoreRefreshTask 的分页问题,避免在刷新热门分数时出现跳页情况
- 确保用户名搜索会对 LIKE 通配符进行转义,使 % 和 _ 被视为字面字符
Enhancements:
- 重构服务层(copilot、comments、user、rating、follow、site message、segment、ark
level),使其使用新的 Jdbi 仓库而非 Ktorm
- 简化多处工具函数和配置函数,以提升可读性与一致性
- 调整 Copilot 分页的 hasNext 逻辑,更清晰地区分聚合与非聚合场景
Build:
- 将构建迁移为使用 Jdbi 依赖而不是 Ktorm,添加 Flyway 和嵌入式 Postgres 以支持测试,并提升 Kotlin 和
Gradle 版本
Documentation:
- 在 README 中记录基于 Flyway 的 schema 管理及基线策略
- 添加 AGENTS.md,描述架构以及数据库/测试环境的设置
Tests:
- 使用 zonky 嵌入式 Postgres 与 Flyway 迁移,为 Jdbi 仓库与评分服务增加大量集成测试
- 为数据库基础设施和 LocalDateTime 绑定添加冒烟测试
Chores:
- 引入 Flyway 迁移脚本 V1__init.sql 定义核心表结构,使 docker 初始化 schema 与代码预期保持一致
<details>
<summary>Original summary in English</summary>
## Summary by Sourcery
Migrate the persistence layer from Ktorm to Jdbi, introduce
Flyway-managed schema and embedded Postgres-backed integration tests,
and fix several query and pagination edge cases in core services and
tasks.
New Features:
- Introduce Jdbi-based repositories and configuration for database
access, replacing Ktorm
Bug Fixes:
- Fix CopilotScoreRefreshTask pagination bug that could skip pages when
refreshing hot scores
- Ensure user name search escapes LIKE wildcards so % and _ are treated
literally
Enhancements:
- Refactor service layer (copilot, comments, user, rating, follow, site
message, segment, ark level) to use new Jdbi repositories instead of
Ktorm
- Simplify multiple utility and config functions for better readability
and consistency
- Adjust Copilot pagination hasNext logic to more clearly reflect
aggregation vs non-aggregation cases
Build:
- Migrate build to use Jdbi dependencies instead of Ktorm, add Flyway
and embedded Postgres for tests, and bump Kotlin and Gradle versions
Documentation:
- Document Flyway-based schema management and baseline strategy in
README
- Add AGENTS.md describing architecture and database/testing setup
Tests:
- Add extensive integration tests for Jdbi repositories and rating
service using zonky embedded Postgres and Flyway migrations
- Add smoke tests for database infrastructure and LocalDateTime binding
Chores:
- Introduce Flyway V1__init.sql migration to define core tables,
aligning docker init schema with code expectations
</details>96 files changed
Lines changed: 8444 additions & 2088 deletions
File tree
- docker
- gradle/wrapper
- src
- main
- kotlin/plus/maa/backend
- common
- controller
- extensions
- utils/converter
- config
- doc
- validation
- controller
- request
- comments
- copilotset
- copilot
- user
- response
- comments
- user
- repository
- entity
- gamedata
- ktorm
- service
- follow
- level
- model
- segment
- task
- resources
- db/migration
- test/kotlin/plus/maa/backend
- controller/request/copilot
- repository
- ktorm
- service
- task
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
25 | 49 | | |
26 | 50 | | |
27 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
63 | 72 | | |
64 | 73 | | |
65 | 74 | | |
| |||
85 | 94 | | |
86 | 95 | | |
87 | 96 | | |
88 | | - | |
89 | 97 | | |
90 | | - | |
91 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
92 | 108 | | |
93 | 109 | | |
94 | 110 | | |
| |||
109 | 125 | | |
110 | 126 | | |
111 | 127 | | |
| 128 | + | |
112 | 129 | | |
113 | 130 | | |
114 | 131 | | |
| |||
125 | 142 | | |
126 | 143 | | |
127 | 144 | | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
144 | 157 | | |
145 | 158 | | |
146 | 159 | | |
| |||
178 | 191 | | |
179 | 192 | | |
180 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
Lines changed: 0 additions & 100 deletions
This file was deleted.
Lines changed: 14 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
0 commit comments