Skip to content

Commit

Permalink
v2/app: allow dbs to be defined outside svcs
Browse files Browse the repository at this point in the history
Since we now accurately track database usages, we can
relax where they are defined. They can still only be *used*
from within services, to ensure permissions are mapped correctly.
  • Loading branch information
eandre committed Aug 2, 2023
1 parent bbc0df9 commit b51ef59
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
9 changes: 1 addition & 8 deletions v2/app/testdata/sqldb_outside_svc.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
! parse
err 'cannot define SQL Database resource in non-service package'
parse

-- svc/migrations/1_dummy.up.sql --
-- svc/svc.go --
Expand All @@ -19,9 +18,3 @@ import (
)

var Moo = sqldb.Named("svc")

-- want: errors --

── Resource defined outside of service ────────────────────────────────────────────────────[E9999]──

Resources can only be defined within a service.
4 changes: 4 additions & 0 deletions v2/app/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encr.dev/v2/parser/apis/middleware"
"encr.dev/v2/parser/infra/pubsub"
"encr.dev/v2/parser/infra/secrets"
"encr.dev/v2/parser/infra/sqldb"
)

// validate checks that the application is in a valid state across all services and compilation units.
Expand Down Expand Up @@ -46,6 +47,9 @@ func (d *Desc) validate(pc *parsectx.Context, result *parser.Result) {
case *secrets.Secrets:
// Secrets are allowed anywhere
continue
case *sqldb.Database:
// Databases are allowed anywhere
continue

default:
_, ok := d.ServiceForPath(b.Package().FSPath)
Expand Down

0 comments on commit b51ef59

Please sign in to comment.