Class: Sequel::Schema::AlterTableGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/schema/schema_generator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#operationsObject (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