Module: MigrationComments::ActiveRecord::ConnectionAdapters::SQLiteAdapter
- Includes:
- AbstractSQLiteAdapter
- Defined in:
- lib/migration_comments/active_record/connection_adapters/sqlite_adapter.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#add_column_options!, #change_column_with_migration_comments, #column_for, #comment_sql, #comments_supported?, #inline_comments?, #retrieve_column_comments, #retrieve_table_comment, #set_column_comment, #set_table_comment
Class Method Details
.included(base) ⇒ Object
5
6
7
8
9
10
11
|
# File 'lib/migration_comments/active_record/connection_adapters/sqlite_adapter.rb', line 5
def self.included(base)
base.module_eval do
alias_method_chain :columns, :migration_comments
alias_method_chain :copy_table, :migration_comments
alias_method_chain :change_column, :migration_comments
end
end
|
Instance Method Details
34
35
36
37
38
39
40
41
|
# File 'lib/migration_comments/active_record/connection_adapters/sqlite_adapter.rb', line 34
def columns_with_migration_comments(table_name, name = nil)
cols = columns_without_migration_comments(table_name, name)
= retrieve_column_comments(table_name, *(cols.map(&:name)))
cols.each do |col|
col. = [col.name.to_sym] if .has_key?(col.name.to_sym)
end
cols
end
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/migration_comments/active_record/connection_adapters/sqlite_adapter.rb', line 43
def (from, to, options = {}) options = options.merge(:id => (!columns(from).detect{|c| c.name == 'id'}.nil? && 'id' == primary_key(from).to_s))
unless options.has_key?(:comment)
= (from)
options = options.merge(:comment => ) if
end
create_table(to, options) do |definition|
@definition = definition
columns(from).each do |column|
column_name = options[:rename] ?
(options[:rename][column.name] ||
options[:rename][column.name.to_sym] ||
column.name) : column.name
@definition.column(column_name, column.type,
:limit => column.limit, :default => column.default,
:precision => column.precision, :scale => column.scale,
:null => column.null, :comment => column.)
end
@definition.primary_key(primary_key(from)) if primary_key(from)
yield @definition if block_given?
end
copy_table_indexes(from, to, options[:rename] || {})
copy_table_contents(from, to,
@definition.columns.map {|column| column.name},
options[:rename] || {})
end
|
#create_table(table_name, options = {}) {|td| ... } ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/migration_comments/active_record/connection_adapters/sqlite_adapter.rb', line 13
def create_table(table_name, options = {})
td = ActiveRecord::ConnectionAdapters::TableDefinition.new(self)
td.primary_key(options[:primary_key] || ActiveRecord::Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
td. options[:comment] if options.has_key?(:comment)
td.base = self
yield td if block_given?
if options[:force] && table_exists?(table_name)
drop_table(table_name)
end
create_sql = "CREATE#{' TEMPORARY' if options[:temporary]} TABLE "
create_sql << "#{quote_table_name(table_name)}#{td.} ("
create_sql << td.columns.map do |column|
column.to_sql + column..to_s
end * ", "
create_sql << ") #{options[:options]}"
execute create_sql
end
|