working commit

This commit is contained in:
2026-06-07 18:19:15 +02:00
parent d3556d397c
commit 0506b35cd1
26 changed files with 199 additions and 1299 deletions
+22 -22
View File
@@ -11,11 +11,11 @@ import (
"go.yaml.in/yaml/v4"
)
func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.GetDumpParams) (*mbctl.GetDumpResult, error) {
func (oper *Operator) GetDump(ctx context.Context, accountID string, params *mbctl.GetDumpParams) (*mbctl.GetDumpResult, error) {
var err error
res := &mbctl.GetDumpResult{}
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
if err != nil {
return res, err
}
@@ -24,21 +24,21 @@ func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.Ge
return res, err
}
lg.WaitRestoring()
lg.WaitDumping()
oper.WaitRestoring()
oper.WaitDumping()
lg.DumpingSemUp()
defer lg.DumpingSemDown()
oper.DumpingSemUp()
defer oper.DumpingSemDown()
listAccounts, err := lg.db.CompletedListAccounts(ctx)
listAccounts, err := oper.db.CompletedListAccounts(ctx)
if err != nil {
return res, err
}
listGrants, err := lg.db.ListGrants(ctx)
listGrants, err := oper.db.ListGrants(ctx)
if err != nil {
return res, err
}
lg.DumpingSemDown()
oper.DumpingSemDown()
dump := descr.Dump{
Timestamp: time.Now().Format(time.RFC3339),
@@ -55,11 +55,11 @@ func (lg *Logic) GetDump(ctx context.Context, accountID string, params *mbctl.Ge
return res, err
}
func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbctl.RestoreDumpParams) (*mbctl.RestoreDumpResult, error) {
func (oper *Operator) RestoreDump(ctx context.Context, accountID string, params *mbctl.RestoreDumpParams) (*mbctl.RestoreDumpResult, error) {
var err error
res := &mbctl.RestoreDumpResult{}
grantExists, _, err := lg.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
grantExists, _, err := oper.db.GetGrant(ctx, accountID, descr.GrantModifyDatabase)
if err != nil {
return res, err
}
@@ -68,8 +68,8 @@ func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbct
return res, err
}
lg.WaitDumping()
lg.WaitRestoring()
oper.WaitDumping()
oper.WaitRestoring()
var dump descr.Dump
@@ -78,28 +78,28 @@ func (lg *Logic) RestoreDump(ctx context.Context, accountID string, params *mbct
return res, err
}
lg.RestoringSemUp()
defer lg.RestoringSemDown()
oper.RestoringSemUp()
defer oper.RestoringSemDown()
if params.DeleteAllRecords {
err = lg.db.CleanDatabase(ctx)
err = oper.db.CleanDatabase(ctx)
if err != nil {
return res, err
}
}
for _, account := range dump.Accounts {
lg.log.Infof("Insert account %s", account.Username)
err = lg.db.InsertAccount(ctx, &account)
oper.log.Infof("Insert account %s", account.Username)
err = oper.db.InsertAccount(ctx, &account)
if err != nil {
lg.log.Errorf("Insert account error: %v", err)
oper.log.Errorf("Insert account error: %v", err)
}
}
for _, grant := range dump.Grants {
lg.log.Infof("Insert grant %s for account %d", grant.Operation, grant.AccountID)
err = lg.db.InsertGrant(ctx, &grant)
oper.log.Infof("Insert grant %s for account %d", grant.Operation, grant.AccountID)
err = oper.db.InsertGrant(ctx, &grant)
if err != nil {
lg.log.Errorf("Insert account error: %v", err)
oper.log.Errorf("Insert account error: %v", err)
}
}