Skip to content

Troubleshooting ​

Find your problem by symptom (what the app or Postgres says) or by the error code the CLI printed. With --json, the code is error.code and the fix is error.hint. Exit code 1 means you can fix it; 2 is an AccessNexus bug (rerun with --verbose and report the stack).

By symptom ​

"new row violates row-level security policy for table ..." ​

Postgres SQLSTATE 42501. The written row fails the WITH CHECK of an insert or update policy.

Likely causeFix
The owner column is not the caller (user_id missing or someone else's id)Send user_id: user.id; isOwner and definePermissions pin it on purpose
An update moves the row out of the rule (changes the owner or tenant)Intended: UPDATE keeps WITH CHECK. Freeze those columns with trigger.lockColumns
The insert targets a tenant the user is not a member ofIntended (pinTenant). Check the membership row exists
The select rule does not admit the new row (see next section)Add a branch that admits it

Never fix it by removing policies, enableRLS: false, or policy.public() for writes.

create() or update() fails although the write is allowed ​

The SDK's create and update return the row (INSERT/UPDATE ... RETURNING), and Postgres checks the returned row against the select policy. If select does not admit it, the write fails with the RLS error above. Typical cases:

  • A membership table whose select is "members of the org": the user's own new row is not visible yet. Add policy.isOwner('user_id') to select.
  • A tenant table whose first membership is added by an AFTER INSERT trigger: RETURNING is checked before it. Add 'own' (or policy.isOwner('created_by')) to read.
  • A soft-delete select that excludes deleted_at IS NOT NULL is fine; but a select with a condition the written row does not meet (for example published = true only) is not.

Reads return nothing, or findById / update return "no rows" ​

RLS hides rows instead of raising errors. A SELECT returns [], a DELETE affects 0 rows, and the SDK's findById / findOne (which use .maybeSingle()) return data: null without an error. The SDK's update(id), delete(id), updateOne and deleteOne turn the "0 rows" case into the error ACCESSNEXUS_NOT_FOUND_OR_DENIED (see SDK errors).

  • The table has no policies (deny-all, NO_POLICIES), or no rule for that operation.
  • The request is anonymous: the session expired, or the client was created without the user's session.
  • The rule checks a different column than you think: run validate (UNKNOWN_COLUMN in manual mode is not caught by TypeScript).

"permission denied for function ..." ​

A security: 'definer' RPC called by an anonymous visitor. EXECUTE is revoked from anon by design. Sign in first, or add allowAnon: true if anonymous use is intended (and check the caller in the body).

"stack depth limit exceeded" or "infinite recursion detected in policy" ​

  • The SQL was applied by a role without BYPASSRLS, so the membership helpers re-enter their own policy. push now refuses this (PUSH_ROLE_NO_BYPASSRLS); push again as postgres.
  • A policy.custom subquery reads the same table the policy is on. Use policy.belongsTo with a membership table, which compiles to a recursion-safe helper.

Locked column or soft-delete errors (SQLSTATE 42501) ​

  • trigger.lockColumns raised: the user tried to change a frozen column. Intended; change it through the service role or a definer RPC.
  • "<table>.<column> can only be set by DELETE (soft delete)": a plain UPDATE touched the soft-delete column. Delete the row instead; restore through a definer RPC.

Foreign key error when deleting a parent ​

Foreign keys default to ON DELETE NO ACTION. Set onDelete: { column: 'cascade' | 'set null' | 'restrict' }.

Policies seem to allow more than the schema says ​

  • Old policies created outside AccessNexus (dashboard, earlier migrations) still exist, and Postgres ORs permissive policies. List them: SELECT tablename, policyname FROM pg_policies WHERE schemaname = 'public';

Drift: the database no longer matches the schema ​

  • MIGRATION_DRIFT: an applied migration file was edited. Restore it (git checkout -- <file>), change the schema, generate a new __changes migration.
  • Changes made in the dashboard are not detected by diff, which compares the schema with files on disk, not with the database. Bring them into the schema, or revert them.

By CLI error code ​

Schema and config ​

CodeFix
SCHEMA_NOT_FOUNDCreate accessnexus.schema.ts (init --yes), pass --schema, or set schema in the config
SCHEMA_NO_DEFAULT_EXPORTEnd the file with export default defineSchema({...})
SCHEMA_INVALIDA builder rejected the definition (bad identifier, unknown reference, unknown role); the message names it
SCHEMA_VALIDATION_FAILEDFix every entry of issues[] (see below)
SCHEMA_LOAD_FAILED, CONFIG_LOAD_FAILED, SEED_LOAD_FAILEDThe file threw or imports a missing package
MODULE_SYNTAX_ERRORSyntax error at the location shown
TS_LOADER_MISSINGesbuild is missing: npm install -D accessnexus
CONFIG_NOT_FOUND, CONFIG_INVALIDFix --config or the config's default export
UNKNOWN_COMMAND, UNKNOWN_FLAG, MISSING_FLAG_VALUE, INVALID_FLAG_VALUE, UNEXPECTED_ARGUMENT, INVALID_FLAGSFollow the hint or --help

Generate, diff and push ​

CodeFix
GENERATED_OUT_OF_DATERun diff to review, then generate, then retry
NOTHING_TO_PUSHRun generate first (or fix --output)
DESTRUCTIVE_MIGRATIONNothing was applied. A rename should be a rename in the schema; otherwise confirm data loss (with a backup) and pass --allow-destructive
DB_URL_MISSINGPass --url or set SUPABASE_DB_URL / ACCESSNEXUS_DB_URL / DATABASE_URL
PG_DRIVER_MISSINGnpm install -D pg
DB_CONNECTION_FAILEDWrong URL, password or network. Use the Session pooler string; local databases may need ?sslmode=disable; timeout via ACCESSNEXUS_DB_CONNECT_TIMEOUT
PUSH_ROLE_NO_BYPASSRLSNothing was applied. Connect as postgres, or ALTER ROLE <role> BYPASSRLS as a superuser
FOREIGN_POLICIESNothing was applied. A managed table has RLS policies AccessNexus did not generate, which would keep granting access. Review them, port what is still needed into the schema, then push --replace-foreign-policies
PUSH_FAILEDPostgres rejected a file (message included). The whole push was rolled back; nothing from it is applied. Fix the schema, generate, push again
MIGRATION_DRIFTRestore the applied migration, change the schema, generate
ADAPTER_NOT_FOUND, ADAPTER_AMBIGUOUS, ADAPTER_UNSUPPORTED, TARGET_NOT_FOUNDOnly the supabase adapter exists
TARGET_INVALIDAdd adapter: 'supabase' to the target

GENERATED_OUT_OF_DATE that generate does not fix

If diff lists a file as removed (D), for example generated/triggers/<table>_triggers.sql after you removed a table's last trigger, generate does not delete it in v0.4.4-next. Delete that file by hand, then diff --check passes. The trigger or function itself stays in the database until you drop it.

A PUSH_FAILED on rpcs.sql saying "cannot change return type of existing function" means you changed an RPC's returns: drop the old function as postgres, then push.

Seed and init ​

CodeFix
SEED_NOT_FOUND, SEED_EMPTYCreate or fix accessnexus.seed.ts
SEED_FAILEDRolled back. Push first; check columns and unique keys (including rows a trigger already creates)
SEED_REMOTE_BLOCKEDUse a local database, or --allow-remote-seed for a disposable one
INIT_NOT_INTERACTIVEAdd --yes
INIT_NEEDS_INPUTPass the flag named in the hint
INIT_DETECT_FAILEDRun in the project root, or let init --yes create a package.json
INTERNAL_ERROR (exit 2)AccessNexus bug: rerun with --verbose and report the stack

Schema validation issues ​

Errors make validate fail; warnings should be fixed unless the choice is deliberate.

CodeFix
UNKNOWN_COLUMN, UNKNOWN_TABLEFix the name in the policy, trigger, reference or index
UNKNOWN_COLUMN_TYPEUse a supported type (uuid, text, int, jsonb, timestamptz, "enum('a','b')", ...)
OWNER_COLUMN_NOT_UUIDisOwner needs a uuid column
INVALID_POLICY_RULEUse policy.public(), not the string 'public'
UNKNOWN_POLICY_OPERATIONKeys are select/insert/update/delete, not read/create
EMPTY_COMBINATORpolicy.any([]) / policy.all([]) needs rules
MISSING_COLUMNSAdd columns (manual mode)
AUDIT_TABLE_MISMATCHGive the audit table table_name, operation, old_data, new_data, changed_at
RPC_IN_TABLESMove RPCs to defineSchema(tables, { rpcs })
INVALID_TRIGGER, INVALID_REFERENCEFix the trigger or 'table.column' reference
INVALID_IDENTIFIER, RESERVED_IDENTIFIERLowercase snake_case, no keywords (order → orders)
UNKNOWN_TABLE_KEYA typo (polices:) or tables nested under tables:
INVALID_ENUM_VALUEA belongsTo where value not in the enum (misspelled role)
INVALID_DEFAULTdefault is raw SQL: "'todo'", not 'todo'
INVALID_ON_DELETEUnknown action, no foreign key, or 'set null' on a NOT NULL column
CASCADE_INTO_SOFT_DELETEUse 'restrict'
DUPLICATE_TRIGGERGive the second lockColumns/custom trigger its own name
BELONGS_TO_PROFILE_WRITABLEUse a membership table, or make the profile column server-written only
RLS_DISABLED_WITH_POLICIESRemove enableRLS: false
NO_POLICIES (warning)Add policies if the client uses the table
RLS_DISABLED (warning)Remove enableRLS: false unless the table must be open
TENANT_PARENT_UNCHECKED (warning)Add the same-tenant guard
NO_PRIMARY_KEY (warning)Add primaryKey
UNWRAPPED_AUTH_CALL (warning)Write (SELECT auth.uid())
PUBLIC_WRITE (warning)Writes open to anonymous visitors; use an owner or tenant rule
USER_ROW_INSERT_OPEN (warning)Use policy.isOwner('id')
AUDIT_INSERT_OPEN (warning)Set the audit table's insert to policy.none()
GLOBAL_ROLE_IN_TENANT_TABLE (warning)Use a tenant role instead of hasRole
SCHEMA_EMPTY (warning)Add tables

Released under the MIT License.