@@ -92,7 +92,7 @@ case and add a value for each parameter. `)
9292Update updates the expected files from the queries and their parameters.
9393Each query runs in its own transaction that rolls back (unless commit is true).
9494*/
95- func Update (root string , runFilter string , commit bool ) {
95+ func Update (root string , runFilter string , commit , noRestore bool ) {
9696 config , err := ReadConfig (root )
9797 ignorePatterns := []string {}
9898 if err == nil {
@@ -107,6 +107,8 @@ func Update(root string, runFilter string, commit bool) {
107107 os .Exit (3 )
108108 }
109109
110+ autoRestore (config , root , noRestore )
111+
110112 if err := TestConnectionString (config .PgUri ); err != nil {
111113 fmt .Print (err .Error ())
112114 os .Exit (2 )
@@ -133,6 +135,27 @@ the regresql update command again to reset the expected output files.
133135 ` )
134136}
135137
138+ func autoRestore (cfg config , root string , noRestore bool ) {
139+ if noRestore || ! ShouldAutoRestore (cfg .Snapshot ) {
140+ return
141+ }
142+ snapshotPath := GetSnapshotPath (cfg .Snapshot , root )
143+ if _ , err := os .Stat (snapshotPath ); os .IsNotExist (err ) {
144+ fmt .Printf ("Error: snapshot file not found: %s\n \n Run 'regresql snapshot build' to create a snapshot, or use '--no-restore' to skip\n " , snapshotPath )
145+ os .Exit (1 )
146+ }
147+ fmt .Printf ("Restoring snapshot: %s\n " , snapshotPath )
148+ opts := RestoreOptions {
149+ InputPath : snapshotPath ,
150+ Clean : true ,
151+ }
152+ if err := RestoreSnapshot (cfg .PgUri , opts ); err != nil {
153+ fmt .Printf ("Error: failed to restore snapshot: %s\n " , err )
154+ os .Exit (1 )
155+ }
156+ fmt .Println ()
157+ }
158+
136159// Test runs regression tests for all queries.
137160// Each query runs in its own transaction that rolls back (unless commit is true).
138161func Test (root , runFilter , formatName , outputPath string , commit , noRestore bool ) {
@@ -153,24 +176,7 @@ func Test(root, runFilter, formatName, outputPath string, commit, noRestore bool
153176 // Cache config for plan quality analysis
154177 SetGlobalConfig (config )
155178
156- // Auto-restore snapshot before test
157- if ! noRestore && ShouldAutoRestore (config .Snapshot ) {
158- snapshotPath := GetSnapshotPath (config .Snapshot , root )
159- if _ , err := os .Stat (snapshotPath ); os .IsNotExist (err ) {
160- fmt .Printf ("Error: snapshot file not found: %s\n \n Run 'regresql snapshot build' to create a snapshot, or use '--no-restore' to skip\n " , snapshotPath )
161- os .Exit (1 )
162- }
163- fmt .Printf ("Restoring snapshot: %s\n " , snapshotPath )
164- opts := RestoreOptions {
165- InputPath : snapshotPath ,
166- Clean : true ,
167- }
168- if err := RestoreSnapshot (config .PgUri , opts ); err != nil {
169- fmt .Printf ("Error: failed to restore snapshot: %s\n " , err )
170- os .Exit (1 )
171- }
172- fmt .Println ()
173- }
179+ autoRestore (config , root , noRestore )
174180
175181 // Validate schema hasn't changed since last snapshot build
176182 if err := ValidateSchemaHash (root ); err != nil {
0 commit comments