Class: SQL::TableModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/mack-data_mapper/dm_patches/migrations.rb

Overview

Sqlite3

Instance Method Summary collapse

Instance Method Details

#add_column(name, type, opts = {}) ⇒ Object

:nodoc:



24
25
26
27
# File 'lib/mack-data_mapper/dm_patches/migrations.rb', line 24

def add_column(name, type, opts = {})
  column = SQL::TableCreator::Column.new(@adapter, name, build_type(name, type), opts)
  @statements << "ALTER TABLE #{quoted_table_name} ADD COLUMN #{column.to_sql}"
end

#build_type(name, type_class, options = @opts) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/mack-data_mapper/dm_patches/migrations.rb', line 34

def build_type(name, type_class, options = @opts)
  schema = {:name => name.to_s, :quote_column_name => quote_column_name(name)}.merge(options)
  schema[:serial?] ||= schema[:serial]
  schema[:nullable?] ||= schema[:nullable]
  schema = @adapter.class.type_map[type_class].merge(schema)
  @adapter.property_schema_statement(schema)
end

#change_column(name, type, opts = {}) ⇒ Object



29
30
31
32
# File 'lib/mack-data_mapper/dm_patches/migrations.rb', line 29

def change_column(name, type, opts = {})
  # raise NotImplemented for SQLite3
  @statements << "ALTER TABLE #{quoted_table_name} ALTER COLUMN #{quote_column_name(name)} TYPE #{build_type(name, type, opts).gsub(quote_column_name(name), '').gsub('NOT NULL', '')}"
end