Skip to content

Commit

Permalink
feat: add Undo config (#410)
Browse files Browse the repository at this point in the history
add undo config
  • Loading branch information
jasondeng1997 authored Jan 1, 2023
1 parent 0de9f4f commit 12005a8
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
51 changes: 51 additions & 0 deletions pkg/datasource/sql/undo/undo_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package undo

import (
"flag"
)

type CompressConfig struct {
Enable bool `yaml:"enable" json:"enable,omitempty" `
Type string `yaml:"type" json:"type,omitempty" `
Threshold int `yaml:"threshold" json:"threshold,omitempty" `
}

type UndoConfig struct {
DataValidation bool `yaml:"data-validation" json:"data-validation,omitempty" `
LogSerialization string `yaml:"log-serialization" json:"log-serialization,omitempty" `
LogTable string `yaml:"log-table" json:"log-table,omitempty" `
OnlyCareUpdateColumns bool `yaml:"only-care-update-columns" json:"only-care-update-columns,omitempty" `
Compress CompressConfig `yaml:"compress" json:"compress,omitempty" `
}

func (ufg *UndoConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.BoolVar(&ufg.DataValidation, prefix+".data-validation", true, "Judge whether the before image and after image are the same,If it is the same, undo will not be recorded")
f.StringVar(&ufg.LogSerialization, prefix+".log-serialization", "jackson", "Serialization method.")
f.StringVar(&ufg.LogTable, prefix+".log-table", "undo_log", "undo log table name.")
f.BoolVar(&ufg.OnlyCareUpdateColumns, prefix+".only-care-update-columns", true, "The switch for degrade check.")

}

// RegisterFlagsWithPrefix for Compress.
func (cfg *CompressConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
f.BoolVar(&cfg.Enable, prefix+".log-table-name", true, "Whether compression is required.")
f.StringVar(&cfg.Type, prefix+".clean-period", "zip", "Compression type")
f.IntVar(&cfg.Threshold, prefix+".clean-period", 64, "Compression threshold Unit: k")
}
54 changes: 54 additions & 0 deletions pkg/datasource/sql/undo/undo_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package undo

import (
"flag"
"testing"
)

func TestCompressConfig_RegisterFlagsWithPrefix(t *testing.T) {
type fields struct {
Enable bool
Type string
Threshold int
}
type args struct {
prefix string
f *flag.FlagSet
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
})
}
}

func TestUndoConfig_RegisterFlagsWithPrefix(t *testing.T) {
type fields struct {
DataValidation bool
LogSerialization string
LogTable string
OnlyCareUpdateColumns bool
Compress CompressConfig
}
type args struct {
prefix string
f *flag.FlagSet
}
tests := []struct {
name string
fields fields
args args
}{
// TODO: Add test cases.
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
})
}
}

0 comments on commit 12005a8

Please sign in to comment.