Skip to content

SDK: ValidateTablePrefix test helper to enforce table naming convention #91

Description

@I-am-nothing

Convention

Every table in a module's `app_` schema must start with `<module_id>_`. This prevents collisions when multiple modules share the same schema (e.g., two modules both creating `items`).

Proposed helper

```go
// In a module's integration test:
func TestTablePrefix(t *testing.T) {
ms.ValidateTablePrefix(t)
}
```

Implementation queries `information_schema.tables` after migrations run:

```sql
SELECT table_name FROM information_schema.tables
WHERE table_schema = current_schema()
AND table_name NOT LIKE $1 || '_%'
```

Where `$1` is `Config.ID`. Any rows returned → test fails with the offending table names.

Scope

  • Add `ValidateTablePrefix(t *testing.T)` to the SDK (receiver method on `*Module` + package-level wrapper).
  • Requires a live Postgres connection — this is an integration-test helper, not a unit test.
  • Should skip gracefully if no DB is configured (`skipIfNoDB` pattern).

Files

  • `internal/core/db.go` or a new `internal/core/validate.go`
  • Test in `internal/core/db_test.go` or `internal/core/validate_test.go`

Context

Template SQL updated to use `template_items` convention in PR #87. Docs updated. This issue adds automated enforcement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions