Skip to main content

Spanner Schema

locality​

The locality block defines a Spanner locality configuration.

locality_group "hot_data" {
storage = "ssd"
ssd_to_hdd_spill_timespan = "24h"
}

locality attributes​

NameRequiredValue
ssd_to_hdd_spill_timespanfalsestring
storagetruestring

locality constraints​

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

permission​

The permission block grants privileges to a role or user.

permission {
to = role.app
for = table.users
privileges = [SELECT]
grantable = true
}

permission attributes​

NameRequiredValue
fortrue

Permission target resource can be one of:

  1. Object reference to schema
  2. Object reference to table
  3. Object reference to view
  4. Object reference to table.column
  5. Object reference to view.column
grantablefalsebool
privilegestrue

List of strings or/and enums (SELECT, INSERT, UPDATE, DELETE)

totrue

Permission grantee can be one of:

  1. string
  2. Object reference to role
  3. Object reference to user

permission constraints​

ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

placement​

The placement block defines a Spanner instance placement configuration.

placement "europeplacement" {
instance_partition = "euro-partition"
default_leader = "europe-west1"
}

placement attributes​

NameRequiredValue
default_leaderfalsestring
instance_partitiontruestring

placement constraints​

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

property_graph​

The property_graph block defines a Spanner Property Graph.

property_graph "graph_name" {
schema = schema.public
node_table {
table = table.users
as = "Person"
key {
columns = [table.users.column.id]
}
}

edge_table {
table = table.follows
key {
columns = [table.follows.column.id]
}
source_key {
columns = [table.follows.column.from_id]
ref_columns = [table.users.column.id]
}
destination_key {
columns = [table.follows.column.to_id]
ref_columns = [table.users.column.id]
}
}
}

property_graph attributes​

NameRequiredValue
schematrue

Object reference to schema

property_graph blocks​

property_graph.edge_table​

property_graph.edge_table attributes​
NameRequiredValue
asfalsestring
tabletrue

Object reference to table

property_graph.edge_table blocks​

property_graph.edge_table.destination_key​

property_graph.edge_table.destination_key attributes​
NameRequiredValue
columnstrue

List of object reference to table.column

ref_columnsfalse

List of object reference to table.column

property_graph.edge_table.destination_key constraints​
ConstraintValue
Requiredtrue
Require Namefalse

property_graph.edge_table.key​

property_graph.edge_table.key attributes​
NameRequiredValue
columnstrue

List of object reference to table.column

property_graph.edge_table.source_key​

property_graph.edge_table.source_key attributes​
NameRequiredValue
columnstrue

List of object reference to table.column

ref_columnsfalse

List of object reference to table.column

property_graph.edge_table.source_key constraints​
ConstraintValue
Requiredtrue
Require Namefalse
property_graph.edge_table constraints​
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

property_graph.node_table​

property_graph.node_table attributes​
NameRequiredValue
asfalsestring
tabletrue

Object reference to table

property_graph.node_table blocks​

property_graph.node_table.key​

property_graph.node_table.key attributes​
NameRequiredValue
columnstrue

List of object reference to table.column

property_graph.node_table constraints​
ConstraintValue
Requiredtrue
Require Namefalse
Repeatabletrue

property_graph constraints​

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

role​

The role block describes a database role.

role "app" {
member_of = [role.parent]
}

role attributes​

NameRequiredValue
member_offalse

List of object reference to role

namefalsestring

role constraints​

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

schema​

The schema block describes a database schema.

schema "public" {
...
}

schema blocks​

schema.annotation​

schema.annotation constraints​
ConstraintValue
Requiredfalse
Require Namefalse
Allow unknown blockstrue
Allow unknown attributestrue

schema constraints​

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

sequence​

The sequence block defines a Spanner sequence.

sequence "order_seq" {
kind = "bit_reversed_positive"
skip_range_min = 1000
skip_range_max = 2000
start_with_counter = 5000
}

sequence attributes​

NameRequiredValue
kindtrue

enum (bit_reversed_positive)

skip_range_maxfalseint
skip_range_minfalseint
start_with_counterfalseint

sequence blocks​

sequence.annotation​

sequence.annotation constraints​
ConstraintValue
Requiredfalse
Require Namefalse
Allow unknown blockstrue
Allow unknown attributestrue

sequence constraints​

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

stream​

The stream block defines a Spanner change stream.

stream "stream_name" {
for_all = true // track all tables, or use tables = [...] for specific tables
options = {
"option_1" = "option_val"
"option_2" = "option_val"
}
for {
table = table.Users
columns = [column.Name, column.Email]
}
}

stream attributes​

NameRequiredValue
for_allfalsebool
optionsfalsemap
tablesfalse

List of object references

stream blocks​

stream.for​

stream.for attributes​
NameRequiredValue
columnsfalse

List of object references

tablefalse

Object reference

stream constraints​

ConstraintValue
Requiredfalse
Require Name (e.g., stream "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

locality_groupfalse

Object reference

row_deletion_policyfalse

Raw expression defined with sql("expr")

schematrue

Object reference to schema

table blocks​

table.annotation​

table.annotation constraints​
ConstraintValue
Requiredfalse
Require Namefalse
Allow unknown blockstrue
Allow unknown attributestrue

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
placement_keyfalsebool
typetrue

Column type can be one of:

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

table.column.annotation​

table.column.annotation constraints​
ConstraintValue
Requiredfalse
Require Namefalse
Allow unknown blockstrue
Allow unknown attributestrue

table.column.as​

table.column.as attributes​
NameRequiredValue
exprtruestring
typefalse

enum (STORED, HIDDEN)

table.column.options​

table.column.options attributes​
NameRequiredValue
allow_commit_timestampfalsebool
locality_groupfalse

Object reference

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​
Name and descriptionRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
falsebool
distance_typefalse

enum (COSINE, DOT_PRODUCT, EUCLIDEAN)

includefalse

Index included columns can be one of:

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

Object reference

null_filteredfalsebool
num_branchesfalseint
num_leavesfalseint
partition_byfalse

Search index partition columns can be one of:

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

search_index

Deprecated: use type = SEARCH instead

falsebool
sort_order_shardingfalsebool
tree_depthfalseint
typefalse

enum (SEARCH, VECTOR)

uniquefalsebool
wherefalsestring
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.order_by​

table.index.order_by attributes​
NameRequiredValue
columnfalse

Search index order column can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
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

user​

The user block describes a database user.

user "app_user" {
member_of = [role.app]
}

user attributes​

NameRequiredValue
member_offalse

List of object reference to role

namefalsestring

user constraints​

ConstraintValue
Requiredfalse
Require Name (e.g., user "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
depends_onfalse

List of object references

schematrue

Object reference to schema

securitytrue

enum (DEFINER, INVOKER)

view blocks​

view.annotation​

view.annotation constraints​
ConstraintValue
Requiredfalse
Require Namefalse
Allow unknown blockstrue
Allow unknown attributestrue

view constraints​

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