# FSL reference | Learn: Schema | | --- | --- | --- | This guide covers Fauna Schema Language (FSL) syntax and API. For specific FSL schema definitions, see: * [FSL access provider schema](access-provider/) * [FSL collection schema](collection/) * [FSL function schema](function/) * [FSL role schema](role/) ## [](#comments)Comments FSL supports single-line and block comments as described in the FQL [comments](../fql/lexical/#comments) section of the language reference. ## [](#property)Property definition Property definition syntax has one of the following forms: | Syntax | Description | | --- | --- | --- | --- | | | Sets the property value for the item. | | | Relationship between the enclosing schema item and the referenced item, indicating existence. | | { } | Relationship between the enclosing schema item and the referenced item, indicating existence and given a value. | Properties can be unique for a schema item or can be repeated. ## [](#cross-reference)Cross-reference An FSL schema can reference another schema by name. For example, a role schema can reference a collection by name: ```fsl // Schema for the `Customer` collection. collection Customer { ... } ... // Schema for the `customer` role. role customer { // The role references the above `Customer` collection. privileges Customer { read } } ``` # FSL access provider schema | Learn: Access providers | | --- | --- | --- | An FSL access provider schema defines an [access provider](../../../learn/security/access-providers/). An access provider registers an external identity provider (IdP), such as Auth0, in your Fauna database. ```fsl access provider someIssuer { issuer "https://example.com/" jwks_uri "https://example.com/.well-known/jwks.json" role customer } ``` Once [set up](../../../learn/security/access-providers/#config), the IdP can issue JSON Web Tokens (JWTs) that act as Fauna [authentication secrets](../../../learn/security/authentication/#secrets). This lets your application’s end users use the IdP for authentication. You can create and manage schema using any of the following: * The [Fauna CLI](../../../learn/schema/manage-schema/#staged) * The [Fauna Dashboard](https://dashboard.fauna.com/) * The Fauna Core HTTP API’s [Schema endpoints](../../http/reference/core-api/#tag/Schema) * [FQL schema methods](../../../learn/schema/manage-schema/#fql) Fauna stores each access provider schema as an FQL document in the [`AccessProvider`](../../fql-api/accessprovider/) system collection. ## [](#fsl-syntax)FSL syntax ```fsl-sig access provider { issuer "" jwks_uri "" [role [{ predicate }] . . .] } ``` ## [](#name)Name _access provider_ **Required** Unique name for the access provider in the database. Must begin with a letter. Can only include letters, numbers, and underscores. ## [](#properties)Properties | Property | Required | Description | | --- | --- | --- | --- | --- | | issuer | true | Issuer for the IdP’s JWTs. Must match the iss claim in JWTs issued by the IdP.The issuer URL. This tells Fauna which IdP is permitted to send a JWT to authorize a query to be executed. | | jwks_uri | true | URI that points to public JSON web key sets (JWKS) for JWTs issued by the IdP. Fauna uses the keys to verify each JWT’s signature. | | role | | User-defined role assigned to JWTs issued by the IdP. Can’t be a built-in role.An access provider can have multiple role properties.Each role property can include a predicate function. If present, JWTs are only assigned the role if the predicate evaluates to true.The predicate function is passed one argument: an object containing the JWT’s payload. The predicate function does not support shorthand syntax. | ## [](#examples)Examples ```fsl access provider someIssuer { issuer "https://example.com/" jwks_uri "https://example.com/.well-known/jwks.json" role customer role manager { predicate (jwt => jwt!.scope.includes("manager")) } } ``` # FSL collection schema | Learn: Schema | | --- | --- | --- | An FSL collection schema defines the structure and behavior of a user-defined [collection](../../../learn/data-model/collections/) and its [documents](../../../learn/data-model/documents/). ```fsl collection Product { // Field definitions. // Define the structure of the collection's documents. name: String? description: String? price: Int = 0 stock: Int = 0 creationTime: Time = Time.now() creationTimeEpoch: Int? typeConflicts: { *: Any }? // Wildcard constraint. // Allows or disallows arbitrary ad hoc fields. *: Any // Migrations block. // Used for schema migrations. // Instructs Fauna how to handle updates to a collection's // field definitions and wildcard constraint. // Contains imperative migration statements. migrations { add .typeConflicts add .stock add_wildcard backfill .stock = 0 drop .internalDesc move_conflicts .typeConflicts move .desc -> .description split .creationTime -> .creationTime, .creationTimeEpoch } // Index definition. // You use indexes to filter and sort documents // in a performant way. index byName { terms [.name] values [desc(.stock), desc(mva(.categories))] } // Unique constraint. // Ensures a field value or combination of field values // is unique for each document in the collection. // Supports multivalue attribute (`mva`) fields, such as Arrays. unique [.name, .description, mva(.categories)] // Check constraint. // Ensures a field value meets provided criteria // before writes. Written as FQL predicate functions. check posStock ((doc) => doc.stock >= 0) // Computed field. // A document field that derives its value from a // user-defined, read-only FQL function that runs on every read. compute InventoryValue: Number = (.stock * .price) // Controls whether you can write to the `ttl` field for collection // documents. If the collection schema doesn't contain field // definitions, `document_ttls` defaults to `true`. Otherwise, // `document_ttls` defaults to `false`. document_ttls true // Sets the default `ttl` for documents in days from their creation // timestamp. You can override the default ttl` during document // creation. ttl_days 5 // Controls document history retention. history_days 3 } ``` You can create and manage schema using any of the following: * The [Fauna CLI](../../../learn/schema/manage-schema/#staged) * The [Fauna Dashboard](https://dashboard.fauna.com/) * The Fauna Core HTTP API’s [Schema endpoints](../../http/reference/core-api/#tag/Schema) * [FQL schema methods](../../../learn/schema/manage-schema/#fql) Fauna stores each collection schema as an FQL document in the [`Collection`](../../fql-api/collection/) system collection. ## [](#fsl-syntax)FSL syntax ```fsl-sig [@alias(] collection { [: . . .] [migrations ] [history_days ] [document_ttls ] [ttl_days