10
10
DEFAULT_BISECTION_THRESHOLD ,
11
11
DEFAULT_BISECTION_FACTOR ,
12
12
)
13
- from .databases .connect import connect_to_uri
13
+ from .databases .connect import connect
14
14
from .parse_time import parse_time_before_now , UNITS_STR , ParseError
15
+ from .config import apply_config
15
16
16
17
import rich
17
18
import click
26
27
27
28
28
29
@click .command ()
29
- @click .argument ("db1_uri" )
30
- @click .argument ("table1_name" )
31
- @click .argument ("db2_uri" )
32
- @click .argument ("table2_name" )
33
- @click .option ("-k" , "--key-column" , default = "id" , help = "Name of primary key column" )
30
+ @click .argument ("database1" , required = False )
31
+ @click .argument ("table1" , required = False )
32
+ @click .argument ("database2" , required = False )
33
+ @click .argument ("table2" , required = False )
34
+ @click .option ("-k" , "--key-column" , default = None , help = "Name of primary key column. Default='id'. " )
34
35
@click .option ("-t" , "--update-column" , default = None , help = "Name of updated_at/last_updated column" )
35
36
@click .option ("-c" , "--columns" , default = [], multiple = True , help = "Names of extra columns to compare" )
36
37
@click .option ("-l" , "--limit" , default = None , help = "Maximum number of differences to find" )
37
- @click .option ("--bisection-factor" , default = DEFAULT_BISECTION_FACTOR , help = "Segments per iteration" )
38
+ @click .option ("--bisection-factor" , default = None , help = f "Segments per iteration. Default= { DEFAULT_BISECTION_FACTOR } . " )
38
39
@click .option (
39
40
"--bisection-threshold" ,
40
- default = DEFAULT_BISECTION_THRESHOLD ,
41
- help = "Minimal bisection threshold. Below it, data-diff will download the data and compare it locally." ,
41
+ default = None ,
42
+ help = f "Minimal bisection threshold. Below it, data-diff will download the data and compare it locally. Default= { DEFAULT_BISECTION_THRESHOLD } ." ,
42
43
)
43
44
@click .option (
44
45
"--min-age" ,
57
58
@click .option (
58
59
"-j" ,
59
60
"--threads" ,
60
- default = "1" ,
61
+ default = None ,
61
62
help = "Number of worker threads to use per database. Default=1. "
62
63
"A higher number will increase performance, but take more capacity from your database. "
63
64
"'serial' guarantees a single-threaded execution of the algorithm (useful for debugging)." ,
64
65
)
65
- def main (
66
- db1_uri ,
67
- table1_name ,
68
- db2_uri ,
69
- table2_name ,
66
+ @click .option ("--conf" , default = None , help = "Path to a configuration.toml file, to provide a default configuration, and a list of possible runs." )
67
+ @click .option ("--run" , default = None , help = "Name of run-configuration to run. If used, CLI arguments for database and table must be omitted." )
68
+ def main (conf , run , ** kw ):
69
+ if conf :
70
+ kw = apply_config (conf , run , kw )
71
+ return _main (** kw )
72
+
73
+ def _main (
74
+ database1 ,
75
+ table1 ,
76
+ database2 ,
77
+ table2 ,
70
78
key_column ,
71
79
update_column ,
72
80
columns ,
@@ -82,35 +90,50 @@ def main(
82
90
threads ,
83
91
keep_column_case ,
84
92
json_output ,
93
+ threads1 = None ,
94
+ threads2 = None ,
95
+ __conf__ = None ,
85
96
):
86
- if limit and stats :
87
- print ("Error: cannot specify a limit when using the -s/--stats switch" )
88
- return
97
+
89
98
if interactive :
90
99
debug = True
91
100
92
101
if debug :
93
102
logging .basicConfig (level = logging .DEBUG , format = LOG_FORMAT , datefmt = DATE_FORMAT )
103
+ if __conf__ :
104
+ logging .debug (f"Applied run configuration: { __conf__ } " )
94
105
elif verbose :
95
106
logging .basicConfig (level = logging .INFO , format = LOG_FORMAT , datefmt = DATE_FORMAT )
96
107
108
+ if limit and stats :
109
+ logging .error ("Cannot specify a limit when using the -s/--stats switch" )
110
+ return
111
+
112
+ key_column = key_column or 'id'
113
+ if bisection_factor is None :
114
+ bisection_factor = DEFAULT_BISECTION_FACTOR
115
+ if bisection_threshold is None :
116
+ bisection_threshold = DEFAULT_BISECTION_THRESHOLD
117
+
97
118
threaded = True
98
- if threads is not None :
99
- if threads .lower () == "serial" :
100
- threaded = False
101
- threads = 1
102
- else :
103
- try :
104
- threads = int (threads )
105
- except ValueError :
106
- logging .error ("Error: threads must be a number, 'auto', or 'serial'." )
107
- return
108
- if threads < 1 :
109
- logging .error ("Error: threads must be >= 1" )
110
- return
111
-
112
- db1 = connect_to_uri (db1_uri , threads )
113
- db2 = connect_to_uri (db2_uri , threads )
119
+ if threads is None :
120
+ threads = 1
121
+ elif isinstance (threads , str ) and threads .lower () == "serial" :
122
+ assert not (threads1 or threads2 )
123
+ threaded = False
124
+ threads = 1
125
+ else :
126
+ try :
127
+ threads = int (threads )
128
+ except ValueError :
129
+ logging .error ("Error: threads must be a number, or 'serial'." )
130
+ return
131
+ if threads < 1 :
132
+ logging .error ("Error: threads must be >= 1" )
133
+ return
134
+
135
+ db1 = connect (database1 , threads1 or threads )
136
+ db2 = connect (database2 , threads2 or threads )
114
137
115
138
if interactive :
116
139
db1 .enable_interactive ()
@@ -128,8 +151,8 @@ def main(
128
151
logging .error ("Error while parsing age expression: %s" % e )
129
152
return
130
153
131
- table1 = TableSegment (db1 , db1 .parse_table_name (table1_name ), key_column , update_column , columns , ** options )
132
- table2 = TableSegment (db2 , db2 .parse_table_name (table2_name ), key_column , update_column , columns , ** options )
154
+ table1_seg = TableSegment (db1 , db1 .parse_table_name (table1 ), key_column , update_column , columns , ** options )
155
+ table2_seg = TableSegment (db2 , db2 .parse_table_name (table2 ), key_column , update_column , columns , ** options )
133
156
134
157
differ = TableDiffer (
135
158
bisection_factor = bisection_factor ,
@@ -138,7 +161,7 @@ def main(
138
161
max_threadpool_size = threads and threads * 2 ,
139
162
debug = debug ,
140
163
)
141
- diff_iter = differ .diff_tables (table1 , table2 )
164
+ diff_iter = differ .diff_tables (table1_seg , table2_seg )
142
165
143
166
if limit :
144
167
diff_iter = islice (diff_iter , int (limit ))
0 commit comments