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
c624cce8
Commit
c624cce8
authored
Apr 21, 2026
by
IanShaw027
Browse files
fix: unblock auth identity compat backfill migration
parent
49258dd3
Changes
4
Show whitespace changes
Inline
Side-by-side
backend/internal/repository/auth_identity_compat_backfill_integration_test.go
0 → 100644
View file @
c624cce8
//go:build integration
package
repository
import
(
"context"
"os"
"path/filepath"
"strconv"
"testing"
"github.com/stretchr/testify/require"
)
func
TestAuthIdentityCompatBackfillMigration_AllowsLongReportTypes
(
t
*
testing
.
T
)
{
tx
:=
testTx
(
t
)
ctx
:=
context
.
Background
()
migration108Path
:=
filepath
.
Join
(
".."
,
".."
,
"migrations"
,
"108_auth_identity_foundation_core.sql"
)
migration108SQL
,
err
:=
os
.
ReadFile
(
migration108Path
)
require
.
NoError
(
t
,
err
)
migration109Path
:=
filepath
.
Join
(
".."
,
".."
,
"migrations"
,
"109_auth_identity_compat_backfill.sql"
)
migration109SQL
,
err
:=
os
.
ReadFile
(
migration109Path
)
require
.
NoError
(
t
,
err
)
_
,
err
=
tx
.
ExecContext
(
ctx
,
`
DROP TABLE IF EXISTS auth_identity_migration_reports CASCADE;
DROP TABLE IF EXISTS auth_identity_channels CASCADE;
DROP TABLE IF EXISTS identity_adoption_decisions CASCADE;
DROP TABLE IF EXISTS pending_auth_sessions CASCADE;
DROP TABLE IF EXISTS auth_identities CASCADE;
ALTER TABLE users
DROP COLUMN IF EXISTS signup_source,
DROP COLUMN IF EXISTS last_login_at,
DROP COLUMN IF EXISTS last_active_at;
`
)
require
.
NoError
(
t
,
err
)
_
,
err
=
tx
.
ExecContext
(
ctx
,
string
(
migration108SQL
))
require
.
NoError
(
t
,
err
)
var
userID
int64
require
.
NoError
(
t
,
tx
.
QueryRowContext
(
ctx
,
`
INSERT INTO users (email, password_hash, role, status, balance, concurrency)
VALUES ('oidc-demo-subject@oidc-connect.invalid', 'hash', 'user', 'active', 0, 1)
RETURNING id`
)
.
Scan
(
&
userID
))
_
,
err
=
tx
.
ExecContext
(
ctx
,
string
(
migration109SQL
))
require
.
NoError
(
t
,
err
)
var
reportCount
int
require
.
NoError
(
t
,
tx
.
QueryRowContext
(
ctx
,
`
SELECT COUNT(*)
FROM auth_identity_migration_reports
WHERE report_type = 'oidc_synthetic_email_requires_manual_recovery'
AND report_key = $1
`
,
strconv
.
FormatInt
(
userID
,
10
))
.
Scan
(
&
reportCount
))
require
.
Equal
(
t
,
1
,
reportCount
)
var
reportTypeLimit
int
require
.
NoError
(
t
,
tx
.
QueryRowContext
(
ctx
,
`
SELECT character_maximum_length
FROM information_schema.columns
WHERE table_schema = 'public'
AND table_name = 'auth_identity_migration_reports'
AND column_name = 'report_type'
`
)
.
Scan
(
&
reportTypeLimit
))
require
.
GreaterOrEqual
(
t
,
reportTypeLimit
,
45
)
require
.
NotZero
(
t
,
userID
)
}
backend/internal/repository/migrations_runner.go
View file @
c624cce8
...
@@ -73,6 +73,12 @@ var migrationChecksumCompatibilityRules = map[string]migrationChecksumCompatibil
...
@@ -73,6 +73,12 @@ var migrationChecksumCompatibilityRules = map[string]migrationChecksumCompatibil
"222b4a09c797c22e5922b6b172327c824f5463aaa8760e4f621bc5c22e2be0f3"
:
{},
"222b4a09c797c22e5922b6b172327c824f5463aaa8760e4f621bc5c22e2be0f3"
:
{},
},
},
},
},
"109_auth_identity_compat_backfill.sql"
:
{
fileChecksum
:
"551e498aa5616d2d91096e9d72cf9fb36e418ee22eacc557f8811cadbc9e20ee"
,
acceptedDBChecksum
:
map
[
string
]
struct
{}{
"2b380305e73ff0c13aa8c811e45897f2b36ca4a438f7b3e8f98e19ecb6bae0b3"
:
{},
},
},
}
}
// ApplyMigrations 将嵌入的 SQL 迁移文件应用到指定的数据库。
// ApplyMigrations 将嵌入的 SQL 迁移文件应用到指定的数据库。
...
...
backend/internal/repository/migrations_runner_checksum_test.go
View file @
c624cce8
...
@@ -51,4 +51,13 @@ func TestIsMigrationChecksumCompatible(t *testing.T) {
...
@@ -51,4 +51,13 @@ func TestIsMigrationChecksumCompatible(t *testing.T) {
)
)
require
.
False
(
t
,
ok
)
require
.
False
(
t
,
ok
)
})
})
t
.
Run
(
"109历史checksum可兼容"
,
func
(
t
*
testing
.
T
)
{
ok
:=
isMigrationChecksumCompatible
(
"109_auth_identity_compat_backfill.sql"
,
"2b380305e73ff0c13aa8c811e45897f2b36ca4a438f7b3e8f98e19ecb6bae0b3"
,
"551e498aa5616d2d91096e9d72cf9fb36e418ee22eacc557f8811cadbc9e20ee"
,
)
require
.
True
(
t
,
ok
)
})
}
}
backend/migrations/109_auth_identity_compat_backfill.sql
View file @
c624cce8
ALTER
TABLE
auth_identity_migration_reports
ALTER
COLUMN
report_type
TYPE
VARCHAR
(
80
);
INSERT
INTO
auth_identities
(
INSERT
INTO
auth_identities
(
user_id
,
user_id
,
provider_type
,
provider_type
,
...
...
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