File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -389,6 +389,19 @@ func runSnapshotRestore() error {
389389 return fmt .Errorf ("database connection failed: %w" , err )
390390 }
391391
392+ // Check if database has existing tables and warn if --clean not specified
393+ if ! snapshotClean {
394+ db , err := regresql .OpenDB (cfg .PgUri )
395+ if err == nil {
396+ defer db .Close ()
397+ var tableCount int
398+ db .QueryRow ("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE'" ).Scan (& tableCount )
399+ if tableCount > 0 {
400+ return fmt .Errorf ("database has %d existing table(s). Use --clean to drop them before restore, or manually clear the database" , tableCount )
401+ }
402+ }
403+ }
404+
392405 inputPath := snapshotInput
393406 if inputPath == "" {
394407 inputPath = regresql .GetSnapshotPath (cfg .Snapshot , snapshotCwd )
You can’t perform that action at this time.
0 commit comments