2121 snapshotInput string
2222 snapshotClean bool
2323 snapshotBuildFixtures []string
24+ snapshotBuildSchema string
2425 snapshotBuildVerbose bool
2526
2627 snapshotCmd = & cobra.Command {
@@ -88,6 +89,7 @@ Examples:
8889Examples:
8990 regresql snapshot build
9091 regresql snapshot build --fixtures users,products,orders
92+ regresql snapshot build --schema schema.sql --fixtures seed_data
9193 regresql snapshot build --output snapshots/test_data.dump --verbose` ,
9294 Run : func (cmd * cobra.Command , args []string ) {
9395 if err := checkDirectory (snapshotCwd ); err != nil {
@@ -145,6 +147,7 @@ func init() {
145147
146148 snapshotBuildCmd .Flags ().StringVarP (& snapshotOutput , "output" , "o" , "" , "Output file path" )
147149 snapshotBuildCmd .Flags ().StringVarP (& snapshotFormat , "format" , "f" , "" , "Dump format: custom, plain, or directory" )
150+ snapshotBuildCmd .Flags ().StringVar (& snapshotBuildSchema , "schema" , "" , "Schema SQL file to apply before fixtures" )
148151 snapshotBuildCmd .Flags ().StringSliceVar (& snapshotBuildFixtures , "fixtures" , nil , "Fixture names to apply" )
149152 snapshotBuildCmd .Flags ().BoolVarP (& snapshotBuildVerbose , "verbose" , "v" , false , "Print detailed progress" )
150153}
@@ -376,17 +379,32 @@ func runSnapshotBuild() error {
376379 return fmt .Errorf ("pguri not configured in regress.yaml" )
377380 }
378381
382+ // Resolve and validate schema path
383+ var schemaPath string
384+ if snapshotBuildSchema != "" {
385+ schemaPath = snapshotBuildSchema
386+ if ! filepath .IsAbs (schemaPath ) {
387+ schemaPath = filepath .Join (snapshotCwd , schemaPath )
388+ }
389+ if _ , err := os .Stat (schemaPath ); err != nil {
390+ return fmt .Errorf ("schema file not found: %s" , schemaPath )
391+ }
392+ }
393+
379394 fixtures := snapshotBuildFixtures
380395 if len (fixtures ) == 0 {
381396 fixtures = regresql .GetSnapshotFixtures (cfg .Snapshot )
382397 }
383398
384- if len (fixtures ) == 0 {
399+ // Allow build with just schema (no fixtures)
400+ if len (fixtures ) == 0 && schemaPath == "" {
385401 return fmt .Errorf ("no fixtures specified. Use --fixtures flag or configure snapshot.fixtures in regress.yaml" )
386402 }
387403
388- if err := regresql .FixturesExist (snapshotCwd , fixtures ); err != nil {
389- return err
404+ if len (fixtures ) > 0 {
405+ if err := regresql .FixturesExist (snapshotCwd , fixtures ); err != nil {
406+ return err
407+ }
390408 }
391409
392410 outputPath := snapshotOutput
@@ -407,12 +425,18 @@ func runSnapshotBuild() error {
407425 fmt .Printf (" Database: %s\n " , maskConnectionString (cfg .PgUri ))
408426 fmt .Printf (" Output: %s\n " , outputPath )
409427 fmt .Printf (" Format: %s\n " , format )
410- fmt .Printf (" Fixtures: %v\n " , fixtures )
428+ if schemaPath != "" {
429+ fmt .Printf (" Schema: %s\n " , schemaPath )
430+ }
431+ if len (fixtures ) > 0 {
432+ fmt .Printf (" Fixtures: %v\n " , fixtures )
433+ }
411434 fmt .Println ()
412435
413436 result , err := regresql .BuildSnapshot (cfg .PgUri , snapshotCwd , regresql.SnapshotBuildOptions {
414437 OutputPath : outputPath ,
415438 Format : format ,
439+ SchemaPath : schemaPath ,
416440 Fixtures : fixtures ,
417441 Verbose : snapshotBuildVerbose ,
418442 })
@@ -429,7 +453,12 @@ func runSnapshotBuild() error {
429453 fmt .Printf (" Size: %s\n " , regresql .FormatBytes (result .Info .SizeBytes ))
430454 fmt .Printf (" Hash: %s\n " , result .Info .Hash )
431455 fmt .Printf (" Duration: %s\n " , result .Duration .Round (time .Millisecond ))
432- fmt .Printf (" Fixtures: %d applied\n " , len (result .FixturesUsed ))
456+ if result .Info .SchemaHash != "" {
457+ fmt .Printf (" Schema: %s\n " , result .Info .SchemaHash [:20 ]+ "..." )
458+ }
459+ if len (result .FixturesUsed ) > 0 {
460+ fmt .Printf (" Fixtures: %d applied\n " , len (result .FixturesUsed ))
461+ }
433462
434463 return nil
435464}
@@ -454,6 +483,13 @@ func runSnapshotInfo() error {
454483 fmt .Printf (" Created: %s\n " , info .Created .Format ("2006-01-02 15:04:05 UTC" ))
455484 fmt .Printf (" Hash: %s\n " , info .Hash )
456485
486+ if info .SchemaPath != "" {
487+ fmt .Println ()
488+ fmt .Println ("Schema:" )
489+ fmt .Printf (" Path: %s\n " , info .SchemaPath )
490+ fmt .Printf (" Hash: %s\n " , info .SchemaHash )
491+ }
492+
457493 if len (info .FixturesUsed ) > 0 {
458494 fmt .Println ()
459495 fmt .Println ("Fixtures used:" )
0 commit comments