@@ -27,12 +27,11 @@ import (
2727 "github.com/sqlc-dev/sqlc/internal/config"
2828 "github.com/sqlc-dev/sqlc/internal/dbmanager"
2929 "github.com/sqlc-dev/sqlc/internal/debug"
30- "github.com/sqlc-dev/sqlc/internal/migrations"
3130 "github.com/sqlc-dev/sqlc/internal/opts"
3231 "github.com/sqlc-dev/sqlc/internal/plugin"
3332 "github.com/sqlc-dev/sqlc/internal/quickdb"
33+ "github.com/sqlc-dev/sqlc/internal/schemautil"
3434 "github.com/sqlc-dev/sqlc/internal/shfmt"
35- "github.com/sqlc-dev/sqlc/internal/sql/sqlpath"
3635 "github.com/sqlc-dev/sqlc/internal/vet"
3736)
3837
@@ -422,25 +421,12 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f
422421 c .Client = dbmanager .NewClient (c .Conf .Servers )
423422 })
424423
425- var ddl []string
426- files , err := sqlpath .Glob (s .Schema )
424+ ddl , err := schemautil .LoadSchemasForApply (s .Schema , string (s .Engine ), func (warning string ) {
425+ fmt .Fprintln (c .Stderr , warning )
426+ })
427427 if err != nil {
428428 return "" , cleanup , err
429429 }
430- for _ , schema := range files {
431- contents , err := os .ReadFile (schema )
432- if err != nil {
433- return "" , cleanup , fmt .Errorf ("read file: %w" , err )
434- }
435- ddlText , warnings , err := migrations .PreprocessSchemaForApply (string (contents ), string (s .Engine ))
436- if err != nil {
437- return "" , cleanup , err
438- }
439- for _ , warning := range warnings {
440- fmt .Fprintln (c .Stderr , warning )
441- }
442- ddl = append (ddl , ddlText )
443- }
444430
445431 resp , err := c .Client .CreateDatabase (ctx , & dbmanager.CreateDatabaseRequest {
446432 Engine : string (s .Engine ),
@@ -547,24 +533,15 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
547533 defer db .Close ()
548534 // For in-memory SQLite databases, apply migrations
549535 if isInMemorySQLite (dburl ) {
550- files , err := sqlpath .Glob (s .Schema )
536+ ddl , err := schemautil .LoadSchemasForApply (s .Schema , string (s .Engine ), func (warning string ) {
537+ fmt .Fprintln (c .Stderr , warning )
538+ })
551539 if err != nil {
552540 return fmt .Errorf ("schema: %w" , err )
553541 }
554- for _ , schema := range files {
555- contents , err := os .ReadFile (schema )
556- if err != nil {
557- return fmt .Errorf ("read schema file: %w" , err )
558- }
559- ddl , warnings , err := migrations .PreprocessSchemaForApply (string (contents ), string (s .Engine ))
560- if err != nil {
561- return err
562- }
563- for _ , warning := range warnings {
564- fmt .Fprintln (c .Stderr , warning )
565- }
566- if _ , err := db .ExecContext (ctx , ddl ); err != nil {
567- return fmt .Errorf ("apply schema %s: %w" , schema , err )
542+ for _ , stmt := range ddl {
543+ if _ , err := db .ExecContext (ctx , stmt ); err != nil {
544+ return fmt .Errorf ("apply schema: %w" , err )
568545 }
569546 }
570547 }
0 commit comments