Module: SnowflakeId::ColumnMethods

Defined in:
lib/snowflake_id/column_methods.rb

Instance Method Summary collapse

Instance Method Details

#snowflake(name, **options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/snowflake_id/column_methods.rb', line 5

def snowflake(name, **options)
  if name == :id && !options[:primary_key]
    raise ArgumentError, "Cannot use t.snowflake :id directly. Use `create_table` with `id: false` and then t.snowflake :id, primary_key: true"
  end

  table_name = @name

  unless table_name
    raise ArgumentError, "Could not determine table name for snowflake column. Make sure you're using it within a create_table block."
  end

  options[:default] = -> { "timestamp_id('#{table_name}'::text)" }

  column(name, :bigint, **options)
end