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
| Name | Required | Value | 
|---|---|---|
| ssd_to_hdd_spill_timespan | false | string | 
| storage | true | string | 
locality constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., locality "name") | true | 
placement
The placement block defines a Spanner instance placement configuration.
placement "europeplacement" {
  instance_partition = "euro-partition"
  default_leader     = "europe-west1"
}
placement attributes
| Name | Required | Value | 
|---|---|---|
| default_leader | false | string | 
| instance_partition | true | string | 
placement constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., placement "name") | true | 
schema
The schema block describes a database schema.
schema "public" {
  ...
}
schema constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| 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
| Name | Required | Value | 
|---|---|---|
| kind | true | 
 | 
| skip_range_max | false | int | 
| skip_range_min | false | int | 
| start_with_counter | false | int | 
sequence constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., sequence "name") | true | 
stream
The stream block defines a Spanner change stream.
stream "stream_name" {
  tables = [table.orders, table.users] // empty for all tables
  options = { 
     "option_1" = "option_val"
     "option_2" = "option_val"
   }
}
stream attributes
| Name | Required | Value | 
|---|---|---|
| options | false | map | 
| tables | false | List of object references | 
stream constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| 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
| Name | Required | Value | 
|---|---|---|
| depends_on | false | List of object references | 
| locality_group | false | Object reference | 
| row_deletion_policy | false | Raw expression defined with  | 
| schema | true | Object reference to  | 
table blocks
table.check
table.check attributes
| Name | Required | Value | 
|---|---|---|
| expr | true | string | 
table.check constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., table.check "name") | true | 
| Repeatable | true | 
table.column
table.column attributes
| Name | Required | Value | 
|---|---|---|
| default | false | Column default expression can be one of: 
 | 
| null | false | bool | 
| placement_key | false | bool | 
| type | true | Column type can be one of: 
 | 
table.column blocks
table.column.as
table.column.as attributes
| Name | Required | Value | 
|---|---|---|
| expr | true | string | 
| type | false | 
 | 
table.column.options
table.column.options attributes
| Name | Required | Value | 
|---|---|---|
| allow_commit_timestamp | false | bool | 
table.column constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., table.column "name") | true | 
table.foreign_key
table.foreign_key attributes
| Name | Required | Value | 
|---|---|---|
| columns | true | Foreign key columns can be one of: 
 | 
| on_delete | false | 
 | 
| ref_columns | true | Foreign key reference columns can be one of: 
 | 
table.foreign_key constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., table.foreign_key "name") | true | 
table.index
table.index attributes
| Name | Required | Value | 
|---|---|---|
| columns | false | Index columns can be one of: 
 | 
| null_filtered | false | bool | 
| search_index | false | bool | 
| unique | false | bool | 
table.index blocks
table.index.on
table.index.on attributes
| Name | Required | Value | 
|---|---|---|
| column | false | Index columns can be one of: 
 | 
| desc | false | bool | 
table.index.on constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name | false | 
| Repeatable | true | 
table.index constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| 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
| Name | Required | Value | 
|---|---|---|
| on_delete | false | 
 | 
| parent | true | Object reference to  | 
| type | false | 
 | 
table.primary_key
table.primary_key attributes
| Name | Required | Value | 
|---|---|---|
| columns | false | Index columns can be one of: 
 | 
table.primary_key blocks
table.primary_key.on
table.primary_key.on attributes
| Name | Required | Value | 
|---|---|---|
| column | false | Index columns can be one of: 
 | 
| desc | false | bool | 
table.primary_key.on constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name | false | 
| Repeatable | true | 
table.primary_key constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name | false | 
| Mutually exclusive sets | [columns, on] | 
| One of required sets | [columns, on] | 
table constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| 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
| Name | Required | Value | 
|---|---|---|
| as | true | string | 
| schema | true | Object reference to  | 
| security | true | 
 | 
view constraints
| Constraint | Value | 
|---|---|
| Required | false | 
| Require Name (e.g., view "name") | true | 
| Allow Qualifier (e.g., view "schema" "name") | true |