Module: SequelColumnTypes

Included in:
Sequel::Schema::AlterTableGenerator, Sequel::Schema::CreateTableGenerator
Defined in:
common/db/db_migrator.rb

Overview

Sequel uses a nice DSL for creating tables but not for altering tables. The definitions below try to provide a reasonable experience for both cases. Creation is the normal:

HalfLongString :title, :null => true

while altering is (to add a column):

HalfLongString :title

Instance Method Summary collapse

Instance Method Details

#apply_mtime_columns(create_time = true) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
# File 'common/db/db_migrator.rb', line 144

def apply_mtime_columns(create_time = true)
  String :created_by
  String :last_modified_by

  if create_time
    DateTime :create_time, :null => false
  end

  DateTime :system_mtime, :null => false, :index => true
  DateTime :user_mtime, :null => false, :index => true
end

#apply_name_columnsObject



125
126
127
128
129
130
131
132
133
# File 'common/db/db_migrator.rb', line 125

def apply_name_columns
  String :authority_id, :null => true
  String :dates, :null => true
  TextField :qualifier, :null => true
  DynamicEnum :source_id, :null => true
  DynamicEnum :rules_id, :null => true
  TextField :sort_name, :null => false
  Integer :sort_name_auto_generate
end

#apply_parallel_name_columnsObject



135
136
137
138
139
140
141
142
# File 'common/db/db_migrator.rb', line 135

def apply_parallel_name_columns
  String :dates, :null => true
  TextField :qualifier, :null => true
  DynamicEnum :source_id, :null => true
  DynamicEnum :rules_id, :null => true
  TextField :sort_name, :null => false
  Integer :sort_name_auto_generate, :default => 1
end

#BlobField(field, opts = {}) ⇒ Object



109
110
111
# File 'common/db/db_migrator.rb', line 109

def BlobField(field, opts = {})
  create_column(*ColumnDefs.blobField(field, opts))
end

#create_column(*column_def) ⇒ Object



81
82
83
84
85
86
87
# File 'common/db/db_migrator.rb', line 81

def create_column(*column_def)
  if self.respond_to?(:column)
    column(*column_def)
  else
    add_column(*column_def)
  end
end

#DynamicEnum(field, opts = {}) ⇒ Object



119
120
121
122
# File 'common/db/db_migrator.rb', line 119

def DynamicEnum(field, opts = {})
  Integer field, opts
  foreign_key([field], :enumeration_value, :key => :id)
end

#HalfLongString(field, opts = {}) ⇒ Object



99
100
101
# File 'common/db/db_migrator.rb', line 99

def HalfLongString(field, opts = {})
  create_column(*ColumnDefs.halfLongString(field, opts))
end

#LongString(field, opts = {}) ⇒ Object



95
96
97
# File 'common/db/db_migrator.rb', line 95

def LongString(field, opts = {})
  create_column(*ColumnDefs.longString(field, opts))
end

#MediumBlobField(field, opts = {}) ⇒ Object



114
115
116
# File 'common/db/db_migrator.rb', line 114

def MediumBlobField(field, opts = {})
  create_column(*ColumnDefs.mediumBlobField(field, opts))
end

#TextBlobField(field, opts = {}) ⇒ Object



104
105
106
# File 'common/db/db_migrator.rb', line 104

def TextBlobField(field, opts = {})
  create_column(*ColumnDefs.textBlobField(field, opts))
end

#TextField(field, opts = {}) ⇒ Object



90
91
92
# File 'common/db/db_migrator.rb', line 90

def TextField(field, opts = {})
  create_column(*ColumnDefs.textField(field, opts))
end