feat(storage): add native MySQL namespace and identity pilots

Add resumable checked migrations and explicit schema administration commands. Port ML budgets, namespaces, identity and group persistence with three-backend contracts. Keep MySQL unavailable as the full application backend.
This commit is contained in:
Anya Tokugawa committed 2026-11-30 23:03:24 +09:00
1 parent 0c7897d695
commit 6a67fd9afe
40 files changed
+3087 -94

No files matched your search

+20 -5
View File
@@ -18,7 +18,12 @@ type adminBackendFixture struct {
func newAdminBackendFixture(t *testing.T, backend storeSQLBackend) *adminBackendFixture {
t.Helper()
s := testNamespaceStore(t, backend)
s := testNamespaceCoreStore(t, backend)
if backend == storeMySQL {
if err := s.ensureMySQLAuthFoundation(context.Background()); err != nil {
t.Fatal(err)
}
}
if backend == storePostgreSQL {
if err := s.ensurePostgreSQLAuthFoundation(context.Background()); err != nil {
t.Fatal(err)
@@ -64,6 +69,10 @@ func newAdminBackendFixture(t *testing.T, backend storeSQLBackend) *adminBackend
// Test fixture SQL is owned and uses explicit format slots; production queries
// do not run through a SQL string rewriting layer.
func (f *adminBackendFixture) query(query string, n int) string {
if f.s.sqlBackend == storeMySQL {
// Only owned fixture SQL. Production statements compose identifiers.
query = strings.ReplaceAll(query, " groups ", " `groups` ")
}
p := make([]any, n)
for i := range p {
p[i] = f.s.sqlParam(i + 1)
@@ -81,9 +90,15 @@ func (f *adminBackendFixture) row(query string, args ...any) *sql.Row {
}
func (f *adminBackendFixture) local(domain, user string) string {
f.t.Helper()
f.exec(`INSERT INTO principals(uuid,display_name,created_at_ms,updated_at_ms) VALUES(%s,%s,1,1) ON CONFLICT DO NOTHING`, user, user)
f.exec(`INSERT INTO principal_identities(uuid,principal_uuid,provider_type,subject,created_at_ms) VALUES(%s,%s,'password',%s,1) ON CONFLICT DO NOTHING`, user, user, user)
f.exec(`INSERT INTO domain_memberships(uuid,domain_uuid,principal_uuid,created_at_ms) VALUES(%s,%s,%s,1) ON CONFLICT DO NOTHING`, domain+":"+user, f.domains[domain], user)
if f.s.sqlBackend == storeMySQL {
f.exec(`INSERT INTO principals(uuid,display_name,created_at_ms,updated_at_ms) VALUES(%s,%s,1,1) ON DUPLICATE KEY UPDATE uuid=principals.uuid`, user, user)
f.exec(`INSERT INTO principal_identities(uuid,principal_uuid,provider_type,subject,created_at_ms) VALUES(%s,%s,'password',%s,1) ON DUPLICATE KEY UPDATE uuid=principal_identities.uuid`, user, user, user)
f.exec(`INSERT INTO domain_memberships(uuid,domain_uuid,principal_uuid,created_at_ms) VALUES(%s,%s,%s,1) ON DUPLICATE KEY UPDATE uuid=domain_memberships.uuid`, domain+":"+user, f.domains[domain], user)
} else {
f.exec(`INSERT INTO principals(uuid,display_name,created_at_ms,updated_at_ms) VALUES(%s,%s,1,1) ON CONFLICT DO NOTHING`, user, user)
f.exec(`INSERT INTO principal_identities(uuid,principal_uuid,provider_type,subject,created_at_ms) VALUES(%s,%s,'password',%s,1) ON CONFLICT DO NOTHING`, user, user, user)
f.exec(`INSERT INTO domain_memberships(uuid,domain_uuid,principal_uuid,created_at_ms) VALUES(%s,%s,%s,1) ON CONFLICT DO NOTHING`, domain+":"+user, f.domains[domain], user)
}
var id string
if err := f.row(`SELECT uuid FROM domain_memberships WHERE domain_uuid=%s AND principal_uuid=%s`, f.domains[domain], user).Scan(&id); err != nil {
f.t.Fatal(err)
@@ -111,7 +126,7 @@ func (f *adminBackendFixture) membership(domain, user string, want bool) {
}
}
func forAdminBackends(t *testing.T, fn func(*testing.T, *adminBackendFixture)) {
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL} {
for _, b := range []storeSQLBackend{storeSQLite, storePostgreSQL, storeMySQL} {
t.Run(fmt.Sprint(b), func(t *testing.T) { fn(t, newAdminBackendFixture(t, b)) })
}
}