feat(store): per-account folder_mapping + excluded_folders columns
This commit is contained in:
+35
-15
@@ -6,19 +6,21 @@ import (
|
||||
)
|
||||
|
||||
type Account struct {
|
||||
ID int64
|
||||
TaskID int64
|
||||
SrcLogin string
|
||||
SrcPassEnc string
|
||||
DstLogin string
|
||||
DstPassEnc string
|
||||
TestSrcStatus string
|
||||
TestDstStatus string
|
||||
Status string
|
||||
Copied int64
|
||||
Skipped int64
|
||||
Errors int64
|
||||
LastError string
|
||||
ID int64
|
||||
TaskID int64
|
||||
SrcLogin string
|
||||
SrcPassEnc string
|
||||
DstLogin string
|
||||
DstPassEnc string
|
||||
TestSrcStatus string
|
||||
TestDstStatus string
|
||||
Status string
|
||||
Copied int64
|
||||
Skipped int64
|
||||
Errors int64
|
||||
LastError string
|
||||
FolderMapping map[string]string
|
||||
ExcludedFolders []string
|
||||
}
|
||||
|
||||
func (s *Store) CreateAccount(ctx context.Context, a Account) (int64, error) {
|
||||
@@ -39,7 +41,8 @@ func (s *Store) DeleteAccount(ctx context.Context, id int64) error {
|
||||
func (s *Store) ListAccountsByTask(ctx context.Context, taskID int64) ([]Account, error) {
|
||||
rows, err := s.Pool.Query(ctx,
|
||||
`SELECT id, task_id, src_login, src_pass_enc, dst_login, dst_pass_enc,
|
||||
test_src_status, test_dst_status, status, copied_count, skipped_count, error_count, last_error
|
||||
test_src_status, test_dst_status, status, copied_count, skipped_count,
|
||||
error_count, last_error, folder_mapping, excluded_folders
|
||||
FROM accounts WHERE task_id=$1 ORDER BY id`, taskID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -49,7 +52,8 @@ func (s *Store) ListAccountsByTask(ctx context.Context, taskID int64) ([]Account
|
||||
for rows.Next() {
|
||||
var a Account
|
||||
if err := rows.Scan(&a.ID, &a.TaskID, &a.SrcLogin, &a.SrcPassEnc, &a.DstLogin, &a.DstPassEnc,
|
||||
&a.TestSrcStatus, &a.TestDstStatus, &a.Status, &a.Copied, &a.Skipped, &a.Errors, &a.LastError); err != nil {
|
||||
&a.TestSrcStatus, &a.TestDstStatus, &a.Status, &a.Copied, &a.Skipped, &a.Errors, &a.LastError,
|
||||
&a.FolderMapping, &a.ExcludedFolders); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out = append(out, a)
|
||||
@@ -95,3 +99,19 @@ func (s *Store) IncAccountCounters(ctx context.Context, id, copied, skipped, err
|
||||
id, copied, skipped, errs)
|
||||
return err
|
||||
}
|
||||
|
||||
// SetAccountFolderMapping persists an account's per-folder rename map and the
|
||||
// set of source folders to skip. nil is normalized to empty so JSONB stays
|
||||
// '{}' / '[]' rather than null.
|
||||
func (s *Store) SetAccountFolderMapping(ctx context.Context, id int64, mapping map[string]string, excluded []string) error {
|
||||
if mapping == nil {
|
||||
mapping = map[string]string{}
|
||||
}
|
||||
if excluded == nil {
|
||||
excluded = []string{}
|
||||
}
|
||||
_, err := s.Pool.Exec(ctx,
|
||||
`UPDATE accounts SET folder_mapping=$2, excluded_folders=$3 WHERE id=$1`,
|
||||
id, mapping, excluded)
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user