class Avram::Migrator::CreateTableStatement

Included Modules

Defined in:



Instance Method Summary

Macro Summary

Instance methods inherited from module Avram::Migrator::IndexStatementHelpers

add_index(column : Symbol, unique = false, using : Symbol = :btree) add_index, index_added?(index : String, column : Symbol) index_added?

Instance methods inherited from class Object

blank_for_validates_required? : Bool blank_for_validates_required?

Constructor Detail

def : TableName, *, if_not_exists : Bool = false) #

[View source]

Instance Method Detail

def build(&) : CreateTableStatement #

Accepts a block to build a table and indices using add and add_index methods.

The generated sql statements are aggregated in the #statements method.


built = do
  add_belongs_to Account, on_delete: :cascade
  add :email : String, unique: true

# => [
  "CREATE TABLE users (
    id serial PRIMARY KEY,
    created_at timestamptz NOT NULL,
    updated_at timestamptz NOT NULL,
    account_id bigint NOT NULL REFERENCES accounts (id) ON DELETE CASCADE,
    email text NOT NULL);",
  "CREATE UNIQUE INDEX users_email_index ON users USING btree (email);"

An optional second argument can toggle between the usage of a numeric or uuid based id column.

built =, PrimaryKeyType::UUID).build do
  add :email : String, unique: true

[View source]
def statements #

[View source]

Macro Detail

macro add(type_declaration, default = nil, index = false, unique = false, using = :btree, **type_options) #

[View source]
macro add_belongs_to(type_declaration, on_delete, references = nil, foreign_key_type = Int64, unique = false, index = true) #

Adds a references column and index given a model class and references option.

[View source]
macro add_timestamps #

[View source]
macro belongs_to(type_declaration, *args, **named_args) #

[View source]
macro composite_primary_key(*columns) #

[View source]
macro primary_key(type_declaration) #

[View source]