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:
1 parent
0c7897d695
commit
6a67fd9afe
40 files changed
+3087
-94
No files matched your search
@@ -12,6 +12,9 @@ import (
|
||||
// transaction. A second connection must never observe a Domain without its
|
||||
// built-in groups, or retain Campus privileges after a Domain moves.
|
||||
func (s *Store) writeDomain(ctx context.Context, id int64, update bool, campus, name, title, host, placement, instance, fingerprint string, enabled bool) error {
|
||||
if s.sqlBackend == storeMySQL && (strings.TrimSpace(placement) != "local" || instance != "" || fingerprint != "") {
|
||||
return ErrBackendFeatureUnavailable
|
||||
}
|
||||
if s.ReadOnly {
|
||||
return ErrReadOnly
|
||||
}
|
||||
@@ -33,6 +36,15 @@ func (s *Store) writeDomain(ctx context.Context, id int64, update bool, campus,
|
||||
return err
|
||||
}
|
||||
return s.namespaceWrite(ctx, func(ctx context.Context, tx *sql.Tx) error {
|
||||
if s.sqlBackend == storeMySQL {
|
||||
var mode string
|
||||
if err := tx.QueryRowContext(ctx, `SELECT authority_mode FROM campuses WHERE uuid=?`, campus).Scan(&mode); err != nil {
|
||||
return err
|
||||
}
|
||||
if mode != "standalone" {
|
||||
return ErrBackendFeatureUnavailable
|
||||
}
|
||||
}
|
||||
if err := s.ensureCampusExists(ctx, tx, campus); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -45,6 +57,15 @@ func (s *Store) writeDomain(ctx context.Context, id int64, update bool, campus,
|
||||
}
|
||||
key := uuid.NewString()
|
||||
if update {
|
||||
if s.sqlBackend == storeMySQL {
|
||||
var existingPlacement string
|
||||
if err := tx.QueryRowContext(ctx, `SELECT placement FROM domains WHERE id=?`, id).Scan(&existingPlacement); err != nil {
|
||||
return err
|
||||
}
|
||||
if existingPlacement != "local" {
|
||||
return ErrBackendFeatureUnavailable
|
||||
}
|
||||
}
|
||||
var mode string
|
||||
if err := tx.QueryRowContext(ctx, `SELECT d.uuid,c.authority_mode FROM domains d JOIN campuses c ON c.uuid=d.campus_uuid WHERE d.id=`+s.sqlParam(1), id).Scan(&key, &mode); err != nil {
|
||||
return err
|
||||
@@ -52,6 +73,9 @@ func (s *Store) writeDomain(ctx context.Context, id int64, update bool, campus,
|
||||
if mode == "managed" {
|
||||
return namespaceValidationError("managed campus topology is read-only")
|
||||
}
|
||||
if s.sqlBackend == storeMySQL && mode != "standalone" {
|
||||
return ErrBackendFeatureUnavailable
|
||||
}
|
||||
if placement == "remote" {
|
||||
var used bool
|
||||
if err := tx.QueryRowContext(ctx, `SELECT EXISTS(SELECT 1 FROM paths WHERE domain_uuid=`+s.sqlParam(1)+`)`, key).Scan(&used); err != nil {
|
||||
@@ -83,7 +107,7 @@ func (s *Store) writeDomain(ctx context.Context, id int64, update bool, campus,
|
||||
}
|
||||
}
|
||||
if !update && hasConfig {
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO config(domain_uuid,key,value,updated_at) SELECT `+s.sqlParam(1)+`,'locale',CASE WHEN lower(default_lang) LIKE 'ja%' THEN 'ja' ELSE 'en' END,`+s.sqlParam(2)+` FROM campuses WHERE uuid=`+s.sqlParam(3)+` ON CONFLICT(domain_uuid,key) DO NOTHING`, key, now, campus)
|
||||
_, err = tx.ExecContext(ctx, `INSERT INTO config(domain_uuid,`+s.sqlConfigKey()+`,value,updated_at) SELECT `+s.sqlParam(1)+`,'locale',CASE WHEN lower(default_lang) LIKE 'ja%' THEN 'ja' ELSE 'en' END,`+s.sqlParam(2)+` FROM campuses WHERE uuid=`+s.sqlParam(3)+s.sqlConflictDoNothing("config", "key", "domain_uuid,key"), key, now, campus)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user