@@ -144,13 +144,13 @@ func Vet(ctx context.Context, dir, filename string, opts *Options) error {
144
144
}
145
145
146
146
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 ) ,
154
154
}
155
155
errored := false
156
156
for _ , sql := range conf .SQL {
@@ -379,14 +379,14 @@ type rule struct {
379
379
}
380
380
381
381
type 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
390
390
}
391
391
392
392
func (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
448
448
}
449
449
450
450
func (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
459
452
}
460
453
461
454
func (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 {
488
481
var prep preparer
489
482
var expl explainer
490
483
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 " )
493
486
}
494
487
dburl , cleanup , err := c .fetchDatabaseUri (ctx , s )
495
488
if err != nil {
0 commit comments