Skip to main content

Spanner Schema

schema

The schema block describes a database schema.

schema "public" {
...
}

schema constraints

ConstraintValue
Requiredfalse
Require Name (e.g., schema "name" )true

table

The table block describes a table in a database schema.

table "users" {
schema = schema.public
column "id" {
type = int
}
...
}

table attributes

NameRequiredValue
depends_onfalse

List of object references

row_deletion_policyfalse

Raw expression defined with sql("expr")

schematrue

Object reference to schema

table blocks

table.check

table.check attributes
NameRequiredValue
exprtruestring
table.check constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.check "name" )true
Repeatabletrue

table.column

table.column attributes
NameRequiredValue
defaultfalse

Column default expression can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
table.column blocks

table.column.as

table.column.as attributes
NameRequiredValue
exprtruestring
typefalse

enum (STORED)

table.column.options

table.column.options attributes
NameRequiredValue
allow_commit_timestampfalsebool
table.column constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.column "name" )true

table.foreign_key

table.foreign_key attributes
NameRequiredValue
columnstrue

Foreign key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
on_deletefalse

enum (NO_ACTION, CASCADE)

ref_columnstrue

Foreign key reference columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
table.foreign_key constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.foreign_key "name" )true

table.index

table.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
null_filteredfalsebool
uniquefalsebool
table.index blocks

table.index.on

table.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
table.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
table.index constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.index "name" )true
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

table.interleave

The interleave block defines a Spanner interleaved table relationship.

table "name" {
schema = schema.public
interleave {
parent = table.parent_table
type = IN_PARENT
on_delete = CASCADE
}
}
table.interleave attributes
NameRequiredValue
on_deletefalse

enum (NO_ACTION, CASCADE)

parenttrue

Object reference to table

typefalse

enum (IN_PARENT, IN)

table.primary_key

table.primary_key attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
table.primary_key blocks

table.primary_key.on

table.primary_key.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
table.primary_key.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
table.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

table constraints

ConstraintValue
Requiredfalse
Require Name (e.g., table "name" )true
Allow Qualifier (e.g., table "schema" "name" )true

view

The view block describes a view in a database schema.

view "clean_users" {
schema = schema.public
column "id" {
type = int
}
...
}

view attributes

NameRequiredValue
astruestring
schematrue

Object reference to schema

securitytrue

enum (DEFINER, INVOKER)

view constraints

ConstraintValue
Requiredfalse
Require Name (e.g., view "name" )true
Allow Qualifier (e.g., view "schema" "name" )true