@@ -2,16 +2,23 @@ package apply
22
33import (
44 "context"
5+ "fmt"
6+ "io/fs"
57
68 "github.com/jackc/pgx/v4"
79 "github.com/spf13/afero"
10+ "github.com/spf13/viper"
811 "github.com/supabase/cli/internal/migration/list"
912 "github.com/supabase/cli/internal/utils"
1013 "github.com/supabase/cli/pkg/migration"
1114)
1215
1316func MigrateAndSeed (ctx context.Context , version string , conn * pgx.Conn , fsys afero.Fs ) error {
14- if err := applyMigrationFiles (ctx , version , conn , fsys ); err != nil {
17+ if viper .GetBool ("EXPERIMENTAL" ) && len (version ) == 0 {
18+ if err := applySchemaFiles (ctx , conn , afero .NewIOFS (fsys )); err != nil {
19+ return err
20+ }
21+ } else if err := applyMigrationFiles (ctx , version , conn , fsys ); err != nil {
1522 return err
1623 }
1724 return applySeedFiles (ctx , conn , fsys )
@@ -38,3 +45,22 @@ func applySeedFiles(ctx context.Context, conn *pgx.Conn, fsys afero.Fs) error {
3845 }
3946 return migration .SeedData (ctx , seeds , conn , afero .NewIOFS (fsys ))
4047}
48+
49+ func applySchemaFiles (ctx context.Context , conn * pgx.Conn , fsys fs.FS ) error {
50+ declared , err := utils .Config .Db .Migrations .SchemaPaths .Files (fsys )
51+ if len (declared ) == 0 {
52+ return err
53+ }
54+ for _ , fp := range declared {
55+ schema , err := migration .NewMigrationFromFile (fp , fsys )
56+ if err != nil {
57+ return err
58+ }
59+ schema .Version = ""
60+ if err := schema .ExecBatch (ctx , conn ); err != nil {
61+ utils .CmdSuggestion = fmt .Sprintf ("See schema file: %s" , utils .Bold (fp ))
62+ return err
63+ }
64+ }
65+ return nil
66+ }
0 commit comments