Skip to content

Commit d01276b

Browse files
committed
fix: define dbName and tableName before use in dumper.go
1 parent ebabe77 commit d01276b

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

dumper.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,29 @@ func (d *Dumper) getTables() (map[string][]string, error) {
112112
}
113113

114114
func (d *Dumper) dumpSchema(table string) error {
115+
parts := strings.SplitN(table, ".", 2)
116+
if len(parts) != 2 {
117+
return fmt.Errorf("invalid table name format: %s", table)
118+
}
119+
dbName, tableName := parts[0], parts[1]
120+
115121
query := fmt.Sprintf("SELECT create_table_query FROM system.tables WHERE database='%s' AND name='%s' SETTINGS display_secrets_in_show_and_select=1 FORMAT TabSeparated", dbName, tableName)
116122
resp, err := d.client.ExecuteQuery(query)
117123
if err != nil {
118124
return err
119125
}
120126

127+
filename := fmt.Sprintf("%s/%s/%s.schema.sql", d.config.StorageConfig["path"], dbName, tableName)
128+
return d.storage.Upload(filename, bytes.NewReader(resp), d.config.CompressFormat, d.config.CompressLevel)
129+
}
130+
131+
func (d *Dumper) dumpData(table string) error {
121132
parts := strings.SplitN(table, ".", 2)
122133
if len(parts) != 2 {
123134
return fmt.Errorf("invalid table name format: %s", table)
124135
}
125136
dbName, tableName := parts[0], parts[1]
126-
filename := fmt.Sprintf("%s/%s/%s.schema.sql", d.config.StorageConfig["path"], dbName, tableName)
127-
return d.storage.Upload(filename, bytes.NewReader(resp), d.config.CompressFormat, d.config.CompressLevel)
128-
}
129137

130-
func (d *Dumper) dumpData(table string) error {
131138
query := fmt.Sprintf("SELECT * FROM %s FORMAT SQLInsert SETTINGS output_format_sql_insert_max_batch_size=%d", table, d.config.BatchSize)
132139
body, err := d.client.ExecuteQueryStreaming(query)
133140
if err != nil {

0 commit comments

Comments
 (0)