Skip to main content

Module default_functions

Module default_functions 

Expand description

Which functions a @default(...) may call (cratestack#1209).

A function-shaped default reaches a migration’s DEFAULT clause, so it has to name something the database can run. cratestack check accepts three groups and refuses everything else:

  • the markers, dbgenerated() and the refused autoincrement(); see super::default_markers;
  • cratestack’s own generators, BuiltinDefault: now(), uuid() and cuid(). The runtime fills them in Rust on create, on every backend, and the migration emitter writes the matching database default where the database has one;
  • functions the schema registers as provided by its database, with datasource db { functions = ["my_fn"] }. Registering is an assertion, like dbgenerated(): cratestack writes the call verbatim, and the database refuses the migration if the function does not exist.

@default(auth().field) is none of these: it is filled from the auth context and never reaches DDL.

Structs§

FunctionCall
A call at the start of a default’s inner text: name(args)trailing. closed is false when the opening ( has no matching ).

Enums§

BuiltinDefault
A @default(...) function cratestack itself defines.
DefaultValue
What a @default(...) inner text is.

Functions§

classify_default
Classify a @default(...) inner text. The parser and the migration emitter both go through this, so they cannot disagree on what a default means.
function_call
Parse the call at the start of inner, or None if it does not start with name(. A name is [A-Za-z_][A-Za-z0-9_.]*, so a schema-qualified public.my_fn() parses too; whitespace may sit between it and (. The closing ) is the one that balances the opening (.
registered_functions
The functions datasource { functions = [...] } registers, in order. Ok(empty) when there is no datasource or no functions entry; Err with a message when the entry is not a list of quoted function names.