You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Description
Adds a static check that migration SQL never hard-codes a schema, and
flips that gate in the migrations guide from *Target* to enforced.
Static-only — runs in the existing `go test` CI, no database required.
## Changes
`go/core/pkg/migrations/cross_track_test.go`:
- **`TestSchemaAgnosticSQL`** — rejects `CREATE`/`DROP SCHEMA`,
schema-qualified DDL (`CREATE TABLE foo.bar`), `SET search_path`, and
`ALTER ... SET SCHEMA` in every migration file. The schema a migration
lands in must come from the connection, not the file.
- **`TestSchemaViolations`** — table-driven unit test with positive and
negative cases. Detection is factored into a `schemaViolations` helper;
comment stripping via `stripSQLComments`.
---------
Signed-off-by: Jeremy Alvis <jeremy.alvis@solo.io>
Schema is a deploy-time choice, fixed by the connection rather than the migration file. A hard-coded schema breaks any deployment that runs the track in a different schema (e.g. a connection that sets `?search_path=<schema>`). The core and vector migrations comply today (verified by inspection until the lint lands).
108
+
Schema is a deploy-time choice, fixed by the connection rather than the migration file. A hard-coded schema breaks any deployment that runs the track in a different schema (e.g. a connection that sets `?search_path=<schema>`). The core and vector migrations comply, enforced by `TestSchemaAgnosticSQL`.
109
109
110
-
> **Enforcement.**A static lint test rejecting the forbidden patterns across all migration files (*Target — not yet enforced*; see [Static Analysis Enforcement](#static-analysis-enforcement)).
110
+
> **Enforcement.**`TestSchemaAgnosticSQL` rejects the forbidden patterns across all migration files (see [Static Analysis Enforcement](#static-analysis-enforcement)).
111
111
112
112
### Idempotency and cross-track safety
113
113
@@ -197,7 +197,7 @@ The policies above are enforced by static analysis tests in `go/core/pkg/migrati
197
197
|`TestNoCrossTrackDDL`| No track may `ALTER TABLE` or `CREATE INDEX ON` a table owned by another track |
198
198
|`TestMigrationGuards`| Up migrations must use `IF NOT EXISTS` on all `CREATE`/`ADD COLUMN`; down migrations must use `IF EXISTS` on all `DROP` statements |
199
199
| Contraction guard *(target)*| Blocks undeclared destructive DDL — `DROP`/`RENAME` of shipped objects, type narrowing, new constraints on shipped tables (see [Backward compatibility and contraction](#backward-compatibility-and-contraction)) |
200
-
|Schema-agnostic lint *(target)*| Rejects `CREATE SCHEMA`, schema-qualified DDL, `SET search_path`, and `ALTER ... SET SCHEMA` (see [Schema-agnostic SQL](#schema-agnostic-sql)) |
200
+
|`TestSchemaAgnosticSQL`| Rejects `CREATE SCHEMA`, schema-qualified DDL, `SET search_path`, and `ALTER ... SET SCHEMA` (see [Schema-agnostic SQL](#schema-agnostic-sql)) |
201
201
202
202
**Adding a new track**: add the track directory name to the `tracks` slice in each test so the new track is covered by the same checks.
0 commit comments