Create a new Flyway SQL migration file for OneBook with proper naming convention, RLS policies, tenant isolation, and PostgreSQL 17 best practices.
Create a new Flyway database migration following OneBook conventions.
Check existing migrations to find the next available version number:
ls backend/src/main/resources/db/migration/ | sort -V | tail -5
Current migrations: V1–V14 (V12 intentionally skipped). Next available: V15.
File naming convention: V{N}__{description}.sql (two underscores).
Create the file at: backend/src/main/resources/db/migration/V{N}__{description}.sql
Every new table MUST include:
-- V{N}: {Description}
-- Tables: {list of tables created/modified}
-- RLS: yes
-- Author: @database agent
CREATE TABLE {table_name} (
id BIGSERIAL PRIMARY KEY,
tenant_id VARCHAR(255) NOT NULL,
-- domain-specific columns here
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
-- Multi-tenant isolation (REQUIRED for every tenant-scoped table)
ALTER TABLE {table_name} ENABLE ROW LEVEL SECURITY;
CREATE POLICY {table_name}_tenant_isolation ON {table_name}
USING (tenant_id = current_setting('app.tenant_id', true));
-- Indexes
CREATE INDEX idx_{table_name}_tenant ON {table_name}(tenant_id);
| Data Type | SQL Type | Notes |
|---|---|---|
| Money/amounts | NUMERIC(19,4) | Never FLOAT/DOUBLE |
| Timestamps | TIMESTAMPTZ | Never TIMESTAMP without TZ |
| Tenant ID | VARCHAR(255) NOT NULL | Every table |
| Primary key | BIGSERIAL | Auto-increment |
| Encrypted text | TEXT | Stores Base64 ciphertext |
| Metadata | JSONB | Flexible JSON |
| Status/enums | VARCHAR(50) | Short strings |
NUMERIC(19,4) for monetary columnsTIMESTAMPTZ for all timestamp columnssnake_case conventionbackend/src/main/resources/db/migration/.github/agents/database.agent.mddocs/technical/sql-schema.md