Parent

SQL::TableModifier

Attributes

table_name[RW]
opts[RW]
statements[RW]
adapter[RW]

Public Class Methods

new(adapter, table_name, opts = {}, &block) click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 7
 7:     def initialize(adapter, table_name, opts = {}, &block)
 8:       @adapter = adapter
 9:       @table_name = table_name.to_s
10:       @opts = (opts)
11: 
12:       @statements = []
13: 
14:       self.instance_eval &block
15:     end

Public Instance Methods

add_column(name, type, opts = {}) click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 17
17:     def add_column(name, type, opts = {})
18:       column = SQL::TableCreator::Column.new(@adapter, name, type, opts)
19:       @statements << "ALTER TABLE #{quoted_table_name} ADD COLUMN #{column.to_sql}"
20:     end
change_column(name, type, opts = {}) click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 40
40:     def change_column(name, type, opts = {})
41:       column = SQL::TableCreator::Column.new(@adapter, name, type, opts)
42:       @statements << @adapter.change_column_type_statement(table_name, column)
43:     end
drop_column(name) click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 22
22:     def drop_column(name)
23:       # raise NotImplemented for SQLite3. Can't ALTER TABLE, need to copy table.
24:       # We'd have to inspect it, and we can't, since we aren't executing any queries yet.
25:       # TODO instead of building the SQL queries when executing the block, create AddColumn,
26:       # AlterColumn and DropColumn objects that get #to_sql'd
27:       if name.is_a?(Array)
28:         name.each{ |n| drop_column(n) }
29:       else
30:         @statements << "ALTER TABLE #{quoted_table_name} DROP COLUMN #{quote_column_name(name)}"
31:       end
32:     end
Also aliased as: drop_columns
drop_columns(name) click to toggle source
Alias for: drop_column
quote_column_name(name) click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 45
45:     def quote_column_name(name)
46:       @adapter.send(:quote_name, name.to_s)
47:     end
quoted_table_name() click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 49
49:     def quoted_table_name
50:       @adapter.send(:quote_name, table_name)
51:     end
rename_column(name, new_name, opts = {}) click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 35
35:     def rename_column(name, new_name, opts = {})
36:       # raise NotImplemented for SQLite3
37:       @statements << "ALTER TABLE #{quoted_table_name} RENAME COLUMN #{quote_column_name(name)} TO #{quote_column_name(new_name)}"
38:     end
to_sql() click to toggle source
    # File lib/dm-migrations/sql/table_modifier.rb, line 53
53:     def to_sql
54:       @statements.join(';')
55:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.