Defining Schema

The schema is a JSON object sent to PUT /p/{id}/v1/schema:

{
  "tables": {
    "users": {
      "columns": {
        "display_name": "string",
        "avatar": "file",
        "role": { "type": "enum", "values": ["user", "admin"], "default": "user" }
      },
      "auth_table": true  // auto-creates email + password_hash
    },
    "posts": {
      "columns": {
        "user_id": "ref users required",
        "title": "string required",
        "body": "text",
        "published": "bool default false"
      },
      "access": { "read": "public", "create": "authenticated", "update": "owner", "delete": "owner" },
      "owner_field": "user_id"
    }
  }
}

Built-in columns

Every table automatically gets these — never define them:

Table options

OptionTypeDescription
auth_tablebooleanEnable email/password auth. Auto-creates email (string, required, unique) and hidden password_hash.
verify_emailbooleanRequire email verification for auth users.
accessobjectPer-operation access rules: read, create, update, delete.
owner_fieldstringRequired when access is "owner". Must be a ref column pointing to auth table. MoonDB compares it with user id from JWT — users only see/edit their own rows. Auto-filled on INSERT. Use "id" on auth_table itself.
uniquestring[][]Compound unique: [["user_id","slug"]].