Skip to content

Commit 1a26b93

Browse files
committed
Store auth references as RecordIds
1 parent b15636d commit 1a26b93

3 files changed

Lines changed: 946 additions & 486 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ surreal import --conn http://localhost:8000 \
9898
schema.surql
9999
```
100100

101-
The generated schema uses `SCHEMAFULL` tables by default. Each field is typed from the BetterAuth schema: required fields take a concrete type (`string`, `datetime`, `bool`, and so on), optional fields use `option<T | null>` so they accept a typed value, a stored `NULL`, or a missing value, and object fields are marked `FLEXIBLE` so they hold arbitrary keys. `DEFINE INDEX` statements are emitted for unique fields and for fields BetterAuth marks as indexed. Every statement uses `IF NOT EXISTS`, so the file is safe to reapply.
101+
The generated schema uses `SCHEMAFULL` tables by default. Each field is typed from the BetterAuth schema: required fields take a concrete type (`string`, `datetime`, `bool`, and so on), optional fields use `option<T | null>` so they accept a typed value, a stored `NULL`, or a missing value, and object fields are marked `FLEXIBLE` so they hold arbitrary keys. Fields declared by Better Auth with `references: { field: "id" }` are emitted as SurrealDB `record<table>` fields, for example `session.userId` becomes `record<user>`. `DEFINE INDEX` statements are emitted for unique fields and for fields BetterAuth marks as indexed. Every statement uses `IF NOT EXISTS`, so the file is safe to reapply.
102+
103+
At runtime, the adapter converts referenced string IDs into SurrealDB `RecordId` values for create, update, and where clauses, then deserializes returned records back to plain string IDs for Better Auth. Existing string reference rows are not migrated automatically.
102104

103105
If your app adds many dynamic plugin fields and you do not want to regenerate the schema each time, set `schemaMode: 'schemaless'`. Known fields stay typed and indexed, and writes to undeclared fields are accepted.
104106

0 commit comments

Comments
 (0)