# activerecord-spanner-adapter - Module ActiveRecord::ConnectionAdapters::Spanner::SchemaStatements (v2.2.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.2.0 (latest)](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements)
- [2.1.0](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/2.1.0/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements)
- [2.0.0](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/2.0.0/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements)
Reference documentation and code samples for the activerecord-spanner-adapter module ActiveRecord::ConnectionAdapters::Spanner::SchemaStatements.

## SchemaStatements

Collection of methods to handle database schema.

[Schema Doc](https://cloud.google.com/spanner/docs/information-schema)

## Methods

### #_add_foreign_key

    def _add_foreign_key(from_table, to_table, **options)

### #_remove_columns

    def _remove_columns(table_name, *column_names)

### #add_belongs_to

    def add_belongs_to(table_name, ref_name, **options)

**Alias Of** : [#add_reference](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements#ActiveRecord__ConnectionAdapters__Spanner__SchemaStatements_add_reference_instance_) Reference Column

### #add_column

    def add_column(table_name, column_name, type, **options)

### #add_foreign_key

    def add_foreign_key(from_table, to_table, **options)

### #add_index

    def add_index(table_name, column_name, options = {})

### #add_reference

    def add_reference(table_name, ref_name, **options)

**Aliases**

- [#add_belongs_to](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements#ActiveRecord__ConnectionAdapters__Spanner__SchemaStatements_add_belongs_to_instance_)
Reference Column

### #assume_migrated_upto_version

    def assume_migrated_upto_version(version)

### #change_column

    def change_column(table_name, column_name, type, **options)

### #change_column_default

    def change_column_default(_table_name, _column_name, _default_or_changes)

**Raises**

- ([ActiveRecordSpannerAdapter::NotSupportedError](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecordSpannerAdapter-NotSupportedError))

### #change_column_null

    def change_column_null(table_name, column_name, null, _default = nil)

### #check_constraints

    def check_constraints(table_name)

Check Contraints

### #column_definitions

    def column_definitions(table_name)

Column

### #create_join_table

    def create_join_table(table_1, table_2, column_options: {}, **options)

Creates a join table that uses all the columns in the table as the primary key by default, unless
an explicit primary key has been defined for the table. ActiveRecord will by default generate join
tables without a primary key. Cloud Spanner however requires all tables to have a primary key.
Instead of adding an additional column to the table only for the purpose of being the primary key,
the Spanner ActiveRecord adapter defines a primary key that contains all the columns in the join
table, as all values in the table should be unique anyways.

### #create_schema_dumper

    def create_schema_dumper(options)

### #create_table

    def create_table(table_name, id: :primary_key, **options)

**Yields**

- (td)

### #current_database

    def current_database()

### #data_source_exists?

    def data_source_exists?(table_name) -> Boolean

**Alias Of** : [#table_exists?](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements#ActiveRecord__ConnectionAdapters__Spanner__SchemaStatements_table_exists?_instance_) **Returns**

- (Boolean)

### #data_sources

    def data_sources()

**Aliases**

- [#tables](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements#ActiveRecord__ConnectionAdapters__Spanner__SchemaStatements_tables_instance_)
Table

### #drop_table

    def drop_table(table_name, options = {})

### #extract_schema_qualified_name

    def extract_schema_qualified_name(string)

### #fetch_type_metadata

    def fetch_type_metadata(sql_type, ordinal_position = nil, allow_commit_timestamp = nil, generated = nil, is_identity: false)

### #foreign_keys

    def foreign_keys(table_name, column: nil)

Foreign Keys
**Raises**

- (ArgumentError)

### #index_name_exists?

    def index_name_exists?(table_name, index_name) -> Boolean

**Returns**

- (Boolean)

### #indexes

    def indexes(table_name)

Index

### #insert_versions_sql

    def insert_versions_sql(versions)

### #migration_context

    def migration_context()

### #new_column_from_field

    def new_column_from_field(_table_name, field, _definitions = nil)

### #primary_and_parent_keys

    def primary_and_parent_keys(table_name)

### #primary_keys

    def primary_keys(table_name)

Primary Keys

### #quoted_scope

    def quoted_scope(name = nil, type: nil)

### #remove_column

    def remove_column(table_name, column_name, _type = nil, _options = {})

### #remove_columns

    def remove_columns(table_name, *column_names, _type: nil, **_options)

### #remove_foreign_key

    def remove_foreign_key(from_table, to_table = nil, **options)

### #remove_index

    def remove_index(table_name, column_name = nil, **options)

### #rename_column

    def rename_column(table_name, column_name, new_column_name)

### #rename_index

    def rename_index(table_name, old_name, new_name)

### #rename_table

    def rename_table(_table_name, _new_name)

**Raises**

- ([ActiveRecordSpannerAdapter::NotSupportedError](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecordSpannerAdapter-NotSupportedError))

### #schema_migration

    def schema_migration()

### #table_exists?

    def table_exists?(table_name) -> Boolean

**Aliases**

- [#data_source_exists?](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements#ActiveRecord__ConnectionAdapters__Spanner__SchemaStatements_data_source_exists?_instance_)
**Returns**

- (Boolean)

### #tables

    def tables()

**Alias Of** : [#data_sources](https://docs.cloud.google.com/ruby/docs/reference/activerecord-spanner-adapter/latest/ActiveRecord-ConnectionAdapters-Spanner-SchemaStatements#ActiveRecord__ConnectionAdapters__Spanner__SchemaStatements_data_sources_instance_) Table

### #type_to_sql

    def type_to_sql(type, limit: nil, precision: nil, scale: nil, **opts)

rubocop:disable Lint/UnusedMethodArgument

## Constants

### VERSION_7_2

**value:**Gem::Version.create "7.2.0"