Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
48613558
Commit
48613558
authored
Jan 11, 2026
by
yangjianbo
Browse files
fix(仪表盘): 修正分区迁移与范围测试
parent
4b66ee2f
Changes
2
Show whitespace changes
Inline
Side-by-side
backend/internal/repository/usage_log_repo_integration_test.go
View file @
48613558
...
@@ -311,7 +311,7 @@ func (s *UsageLogRepoSuite) TestDashboardStatsWithRange_Fallback() {
...
@@ -311,7 +311,7 @@ func (s *UsageLogRepoSuite) TestDashboardStatsWithRange_Fallback() {
now
:=
time
.
Now
()
.
UTC
()
now
:=
time
.
Now
()
.
UTC
()
todayStart
:=
truncateToDayUTC
(
now
)
todayStart
:=
truncateToDayUTC
(
now
)
rangeStart
:=
todayStart
.
Add
(
-
24
*
time
.
Hour
)
rangeStart
:=
todayStart
.
Add
(
-
24
*
time
.
Hour
)
rangeEnd
:=
now
rangeEnd
:=
now
.
Add
(
1
*
time
.
Second
)
user1
:=
mustCreateUser
(
s
.
T
(),
s
.
client
,
&
service
.
User
{
Email
:
"range-u1@test.com"
})
user1
:=
mustCreateUser
(
s
.
T
(),
s
.
client
,
&
service
.
User
{
Email
:
"range-u1@test.com"
})
user2
:=
mustCreateUser
(
s
.
T
(),
s
.
client
,
&
service
.
User
{
Email
:
"range-u2@test.com"
})
user2
:=
mustCreateUser
(
s
.
T
(),
s
.
client
,
&
service
.
User
{
Email
:
"range-u2@test.com"
})
...
...
backend/migrations/035_usage_logs_partitioning.sql
View file @
48613558
-- usage_logs monthly partition bootstrap.
-- usage_logs monthly partition bootstrap.
-- Only c
onverts to
partition
ed table
when usage_logs is
empty
.
-- Only c
reates
partition
s
when usage_logs is
already partitioned
.
--
Existing installations with data
require a manual migration plan.
--
Converting usage_logs to a partitioned table
require
s
a manual migration plan.
DO
$$
DO
$$
DECLARE
DECLARE
...
@@ -20,8 +20,8 @@ BEGIN
...
@@ -20,8 +20,8 @@ BEGIN
IF
NOT
is_partitioned
THEN
IF
NOT
is_partitioned
THEN
SELECT
EXISTS
(
SELECT
1
FROM
usage_logs
LIMIT
1
)
INTO
has_data
;
SELECT
EXISTS
(
SELECT
1
FROM
usage_logs
LIMIT
1
)
INTO
has_data
;
IF
NOT
has_data
THEN
IF
NOT
has_data
THEN
EXECUTE
'ALTER TABLE usage_logs PARTITION BY RANGE (created_at)'
;
-- Automatic conversion is intentionally skipped; see manual migration plan.
is_partitioned
:
=
TRUE
;
RAISE
NOTICE
'usage_logs is not partitioned; skip automatic partitioning'
;
END
IF
;
END
IF
;
END
IF
;
END
IF
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment