Documentation
¶
Overview ¶
Package capyrls converts Supabase row-level-security policies to portable, vanilla PostgreSQL.
Supabase RLS is standard CREATE POLICY plus a platform-provided context: auth.uid()/auth.jwt()/auth.role(), the anon/authenticated/service_role pseudo-roles, and PostgREST injecting a verified JWT into a session GUC. None of that exists on plain Postgres. capyrls re-homes the policies onto one of two conventions:
- vanilla (default): a small app.* schema of accessor functions over transaction-local GUCs (app.user_id, app.role, promoted claims). The database stops knowing JWTs exist; the app sets typed facts per transaction. Policies are rewritten to the new accessors.
- supabase-compat: an auth.* shim backed by the request.jwt.claims GUC. Policies port verbatim; useful for a zero-risk lift-and-shift.
Input is either SQL sources (Supabase migration folders, pg_dump --schema-only) or a live database via the live subpackage. Output is a SQL bundle plus a report describing the context contract the application must now fulfil.
Index ¶
Constants ¶
const Version = "1.1.0"
Version is the capyrls release version.
Variables ¶
This section is empty.
Functions ¶
func QuoteIdent ¶
QuoteIdent quotes a PostgreSQL identifier only when required.
Types ¶
type Catalog ¶
type Catalog struct {
Tables map[string]*Table
Policies []*Policy
Defaults []ColumnDefault
Routines []Routine
Notes []string
}
Catalog is the RLS-relevant state extracted from SQL files or a live database: tables with row security, policies in final state, and the auth.*-referencing objects that need conversion or review.
func NewCatalog ¶
func NewCatalog() *Catalog
func (*Catalog) AddDefault ¶
func (c *Catalog) AddDefault(d ColumnDefault)
AddDefault records an auth-referencing column default.
func (*Catalog) AddRoutine ¶
AddRoutine records an auth-referencing function or procedure.
func (*Catalog) SetTableRLS ¶
SetTableRLS records a table's row-security flags. Used by external catalog builders such as the live subpackage.
type ClaimMapping ¶
type ColumnDefault ¶
ColumnDefault is a column default expression that references auth.*.
type Options ¶
type Options struct {
Mode Mode
RoleModel RoleModel
// NoSplitAll keeps FOR ALL policies intact instead of splitting them
// into per-command policies.
NoSplitAll bool
// NoServiceEscape suppresses the GUC-gated bypass policies emitted for
// the single-role model.
NoServiceEscape bool
// Prefix is the schema and GUC namespace, default "app".
Prefix string
// AppRole and ServiceRole name the roles for the role-split model.
AppRole string
ServiceRole string
}
Options control a conversion. The zero value is the recommended setup: vanilla mode, role-split model, FOR ALL policies split per command, service escape enabled for the single-role model.
type Policy ¶
type Policy struct {
Name string
Table QName
Permissive bool
Cmd PolicyCmd
Roles []string // lower-cased role names; empty means PUBLIC
Using string // raw expression SQL without the outer parens; "" if absent
WithCheck string
Origin string // "<file>:<line>" or "database"
}
Policy is one row-security policy in its final (post-ALTER) state.
type PolicyOutcome ¶
type QName ¶
QName is a possibly schema-qualified identifier. Schema is "" when the source SQL left the name unqualified; Key() folds that to "public", which matches how unqualified DDL resolves in the dumps this tool consumes.
func (QName) EffectiveSchema ¶
type Report ¶
type Report struct {
Tool string `json:"tool"`
Version string `json:"version"`
Mode string `json:"mode"`
RoleModel string `json:"role_model"`
Policies []PolicyOutcome `json:"policies"`
Claims []ClaimMapping `json:"claims"`
GUCs []GUCSpec `json:"gucs"`
Defaults []string `json:"column_defaults"`
Routines []string `json:"routines_to_review"`
Warnings []string `json:"warnings"`
Notes []string `json:"notes"`
}
type Result ¶
Result is a finished conversion.
func Convert ¶
Convert parses SQL sources and converts the final policy state into a fresh, ordered SQL bundle (prelude, roles, policies) plus a report.
func ConvertCatalog ¶
ConvertCatalog converts an already-built catalog (see ParseSQL and the live subpackage).
func Rewrite ¶
Rewrite transforms SQL sources in place: auth.* helper calls are rewritten to the target convention while everything else stays byte-identical. Use it to keep an existing migration history instead of adopting a fresh bundle. The returned files mirror the inputs, plus the prelude and report.
type RoleModel ¶
type RoleModel int
RoleModel describes how the converted database separates privileges.
const ( // RoleSplit creates a non-owning runtime role (RLS applies) and a // BYPASSRLS service role - the classic three-role convention. RoleSplit RoleModel = iota // RoleSingle assumes the app connects as the table owner (the common // managed-Postgres setup) and FORCEs row security instead. RoleSingle )
type Routine ¶
Routine is a function or procedure whose body references auth.*. Def carries the full CREATE definition when introspected live; it is "" when the reference was found while scanning SQL files.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
capyrls
command
capyrls converts Supabase row-level-security policies to portable, vanilla PostgreSQL.
|
capyrls converts Supabase row-level-security policies to portable, vanilla PostgreSQL. |
|
Package live builds a capyrls.Catalog by introspecting a running database instead of parsing SQL files.
|
Package live builds a capyrls.Catalog by introspecting a running database instead of parsing SQL files. |