@@ -5,18 +5,20 @@ package compiler
5
5
import (
6
6
"fmt"
7
7
"io"
8
- "os "
8
+ "io/ioutil "
9
9
"regexp"
10
10
"sort"
11
11
"strings"
12
12
13
13
"github.com/kyleconroy/sqlc/internal/config"
14
14
"github.com/kyleconroy/sqlc/internal/dinosql"
15
15
"github.com/kyleconroy/sqlc/internal/dolphin"
16
+ "github.com/kyleconroy/sqlc/internal/migrations"
16
17
"github.com/kyleconroy/sqlc/internal/pg"
17
18
"github.com/kyleconroy/sqlc/internal/postgresql"
18
19
"github.com/kyleconroy/sqlc/internal/sql/ast"
19
20
"github.com/kyleconroy/sqlc/internal/sql/catalog"
21
+ "github.com/kyleconroy/sqlc/internal/sql/sqlpath"
20
22
"github.com/kyleconroy/sqlc/internal/sqlite"
21
23
)
22
24
@@ -71,23 +73,29 @@ func Run(conf config.SQL, combo config.CombinedSettings) (*Result, error) {
71
73
return nil , fmt .Errorf ("unknown engine: %s" , conf .Engine )
72
74
}
73
75
74
- blobs := make ([]io.Reader , 0 , len (conf .Schema ))
75
- for _ , s := range conf .Schema {
76
- b , err := os .Open (s )
77
- if err != nil {
78
- return nil , err
79
- }
80
- blobs = append (blobs , b )
81
- }
82
- rd := io .MultiReader (blobs ... )
83
-
84
- stmts , err := p .Parse (rd )
76
+ files , err := sqlpath .Glob (conf .Schema )
85
77
if err != nil {
86
78
return nil , err
87
79
}
88
80
89
- if err := c .Build (stmts ); err != nil {
90
- return nil , err
81
+ for _ , filename := range files {
82
+ blob , err := ioutil .ReadFile (filename )
83
+ if err != nil {
84
+ // merr.Add(filename, "", 0, err)
85
+ return nil , err
86
+ }
87
+ contents := migrations .RemoveRollbackStatements (string (blob ))
88
+ stmts , err := p .Parse (strings .NewReader (contents ))
89
+ if err != nil {
90
+ // merr.Add(filename, , 0, err)
91
+ return nil , err
92
+ }
93
+ for i := range stmts {
94
+ if err := c .Update (stmts [i ]); err != nil {
95
+ // merr.Add(filename, contents, location(stmt), err)
96
+ return nil , err
97
+ }
98
+ }
91
99
}
92
100
93
101
var structs []dinosql.GoStruct
0 commit comments