Class: Sequel::Schema::AlterTableGenerator
- Defined in:
- lib/sequel/schema/schema_generator.rb
Instance Attribute Summary collapse
-
#operations ⇒ Object
readonly
Returns the value of attribute operations.
Instance Method Summary collapse
- #add_column(name, type, opts = {}) ⇒ Object
- #add_index(columns, opts = {}) ⇒ Object
- #drop_column(name) ⇒ Object
- #drop_index(columns) ⇒ Object
-
#initialize(db, &block) ⇒ AlterTableGenerator
constructor
A new instance of AlterTableGenerator.
- #rename_column(name, new_name, opts = {}) ⇒ Object
- #set_column_default(name, default) ⇒ Object
- #set_column_type(name, type) ⇒ Object
Constructor Details
#initialize(db, &block) ⇒ AlterTableGenerator
Returns a new instance of AlterTableGenerator.
68 69 70 71 72 |
# File 'lib/sequel/schema/schema_generator.rb', line 68 def initialize(db, &block) @db = db @operations = [] instance_eval(&block) if block end |
Instance Attribute Details
#operations ⇒ Object (readonly)
Returns the value of attribute operations.
66 67 68 |
# File 'lib/sequel/schema/schema_generator.rb', line 66 def operations @operations end |
Instance Method Details
#add_column(name, type, opts = {}) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/sequel/schema/schema_generator.rb', line 74 def add_column(name, type, opts = {}) @operations << { :op => :add_column, :name => name, :type => type }.merge(opts) end |
#add_index(columns, opts = {}) ⇒ Object
113 114 115 116 117 118 119 |
# File 'lib/sequel/schema/schema_generator.rb', line 113 def add_index(columns, opts = {}) columns = [columns] unless columns.is_a?(Array) @operations << { :op => :add_index, :columns => columns }.merge(opts) end |
#drop_column(name) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/sequel/schema/schema_generator.rb', line 82 def drop_column(name) @operations << { :op => :drop_column, :name => name } end |
#drop_index(columns) ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/sequel/schema/schema_generator.rb', line 121 def drop_index(columns) columns = [columns] unless columns.is_a?(Array) @operations << { :op => :drop_index, :columns => columns } end |
#rename_column(name, new_name, opts = {}) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/sequel/schema/schema_generator.rb', line 89 def rename_column(name, new_name, opts = {}) @operations << { :op => :rename_column, :name => name, :new_name => new_name }.merge(opts) end |
#set_column_default(name, default) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/sequel/schema/schema_generator.rb', line 105 def set_column_default(name, default) @operations << { :op => :set_column_default, :name => name, :default => default } end |
#set_column_type(name, type) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/sequel/schema/schema_generator.rb', line 97 def set_column_type(name, type) @operations << { :op => :set_column_type, :name => name, :type => type } end |