| applyTo | ** |
|---|
This is a PostgreSQL migration project using Sqitch for schema management. It defines one of many services of vibetype, an event community platform. The SQL schema applied by this service is exposed as a GraphQL API by the postgraphile service.
- Each migration consists of three files in
src/:deploy/<name>.sql,revert/<name>.sql, andverify/<name>.sql - Migrations are wrapped in transactions (
BEGIN;/COMMIT;) - All migrations are tracked in
src/sqitch.plan
- The PostgreSQL schema is exposed as a GraphQL API via PostGraphile v5
- The GraphQL API exposed should have a simple and consistent surface, especially when it comes to naming
- Prefer CRUD behavior and constraints over custom functions, to keep the schema simple and maintainable
- The
vibetype.jwtcomposite type defines JWT payload fields; PostGraphile uses it for JWT signing - Error codes consist of 5 capitalized letters starting with a
VTprefix: e.g.VTPLLfor "password length low"
ENABLE ROW LEVEL SECURITY(RLS) policies to enforce access control on tables- Grant
EXECUTEon functions to the appropriate roles only - Ensure that PostGraphile Smart Comments properly control API exposure
- Prefer
security invoker; only usesecurity definerwhen necessary - Use the
vibetype_privateschema for internal logic and especially protected content that should never be exposed directly
- Performance is key: always consider query planner optimizations when writing SQL
- Prefer SQL over PL/pgSQL, except where it doesn't make sense
- Foreign keys must have corresponding indexes
- Ensure SQL logic is always covered by tests
- Use the test framework in
test/rather thansrc/verify/scripts
- Edit SQL files, keeping the plan in sync
- Ensure correctness of security and permissions
- Ensure proper test coverage
- Run
npm run test:updateto build the Docker test image, deploy all migrations, run test SQL, revert, and update schema fixture files
- Code style
- Sort any elements (imports, object properties, functions, ...), e.g. alphabetically, except when it doesn't make sense.
- Agents
- After making changes to the codebase, ensure AGENTS.md is in sync with your knowledge of the project.