From 38e988b84cfdf905efdb24e7de5a5ce5496fa21b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Eriksson?= Date: Tue, 1 Aug 2023 13:58:47 +0200 Subject: [PATCH] v2/app: allow dbs to be defined outside svcs 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. --- v2/app/testdata/sqldb_outside_svc.txt | 9 +-------- v2/app/validate.go | 4 ++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/v2/app/testdata/sqldb_outside_svc.txt b/v2/app/testdata/sqldb_outside_svc.txt index ca9498fa84..b8a1ee49dd 100644 --- a/v2/app/testdata/sqldb_outside_svc.txt +++ b/v2/app/testdata/sqldb_outside_svc.txt @@ -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 -- @@ -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. diff --git a/v2/app/validate.go b/v2/app/validate.go index 5576f31470..856db7895f 100644 --- a/v2/app/validate.go +++ b/v2/app/validate.go @@ -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. @@ -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)