@@ -144,13 +144,13 @@ func Vet(ctx context.Context, dir, filename string, opts *Options) error {
144144 }
145145
146146 c := checker {
147- Rules : rules ,
148- Conf : conf ,
149- Dir : dir ,
150- Env : env ,
151- Envmap : map [ string ] string {} ,
152- Stderr : stderr ,
153- NoDatabase : e . NoDatabase ,
147+ Rules : rules ,
148+ Conf : conf ,
149+ Dir : dir ,
150+ Env : env ,
151+ Stderr : stderr ,
152+ OnlyManagedDB : e . Debug . OnlyManagedDatabases ,
153+ Replacer : shfmt . NewReplacer ( nil ) ,
154154 }
155155 errored := false
156156 for _ , sql := range conf .SQL {
@@ -379,14 +379,14 @@ type rule struct {
379379}
380380
381381type checker struct {
382- Rules map [string ]rule
383- Conf * config.Config
384- Dir string
385- Env * cel.Env
386- Envmap map [ string ] string
387- Stderr io. Writer
388- NoDatabase bool
389- Client pb. QuickClient
382+ Rules map [string ]rule
383+ Conf * config.Config
384+ Dir string
385+ Env * cel.Env
386+ Stderr io. Writer
387+ OnlyManagedDB bool
388+ Client pb. QuickClient
389+ Replacer * shfmt. Replacer
390390}
391391
392392func (c * checker ) fetchDatabaseUri (ctx context.Context , s config.SQL ) (string , func () error , error ) {
@@ -448,14 +448,7 @@ func (c *checker) fetchDatabaseUri(ctx context.Context, s config.SQL) (string, f
448448}
449449
450450func (c * checker ) DSN (dsn string ) (string , error ) {
451- // Populate the environment variable map if it is empty
452- if len (c .Envmap ) == 0 {
453- for _ , e := range os .Environ () {
454- k , v , _ := strings .Cut (e , "=" )
455- c .Envmap [k ] = v
456- }
457- }
458- return shfmt .Replace (dsn , c .Envmap ), nil
451+ return c .Replacer .Replace (dsn ), nil
459452}
460453
461454func (c * checker ) checkSQL (ctx context.Context , s config.SQL ) error {
@@ -488,8 +481,8 @@ func (c *checker) checkSQL(ctx context.Context, s config.SQL) error {
488481 var prep preparer
489482 var expl explainer
490483 if s .Database != nil { // TODO only set up a database connection if a rule evaluation requires it
491- if c . NoDatabase {
492- return fmt .Errorf ("database: connections disabled via command line flag " )
484+ if s . Database . URI != "" && c . OnlyManagedDB {
485+ return fmt .Errorf ("database: connections disabled via SQLCDEBUG=databases=managed " )
493486 }
494487 dburl , cleanup , err := c .fetchDatabaseUri (ctx , s )
495488 if err != nil {
0 commit comments