activerecord-mysql-awesome 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a21a0f151f532f79298ad0c6dff3cc8fc2de50fb
|
4
|
+
data.tar.gz: e7b5019e83e9574918d428ccc5e9d8c60be43a13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f8063d4621ac388c7edca128674cd53cf5e45ccb8452678700d520a1b1c45262d21533ad62ba1dbb9df1fd16ab5178b4b8422840e32160675f0ad20a1077d9
|
7
|
+
data.tar.gz: 6f0153a9989ba7b6106416f8d962f7ecfac29d28c0fd796aacf9a499ba4311eb60ee8f8d3b4b277fa905f966a3ba586f546179d74b739993e7308d6b98bd7a9e
|
data/lib/activerecord-mysql-awesome/active_record/connection_adapters/abstract_mysql_adapter.rb
CHANGED
@@ -3,27 +3,94 @@ require 'active_record/connection_adapters/abstract_mysql_adapter'
|
|
3
3
|
module ActiveRecord
|
4
4
|
module Mysql
|
5
5
|
module Awesome
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
class ChangeColumnDefinition < Struct.new(:column, :name) #:nodoc:
|
7
|
+
end
|
8
|
+
|
9
|
+
class ColumnDefinition < ActiveRecord::ConnectionAdapters::ColumnDefinition
|
10
|
+
attr_accessor :auto_increment, :unsigned, :charset, :collation
|
11
|
+
end
|
12
|
+
|
13
|
+
class TableDefinition < ActiveRecord::ConnectionAdapters::TableDefinition
|
14
|
+
def initialize(types, name, temporary, options, as = nil)
|
15
|
+
super(types, name, temporary, options)
|
16
|
+
@as = as
|
17
|
+
end
|
18
|
+
|
19
|
+
def primary_key(name, type = :primary_key, options = {})
|
20
|
+
options[:auto_increment] ||= type == :bigint
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_column_definition(name, type, options) # :nodoc:
|
25
|
+
column = super
|
26
|
+
column.auto_increment = options[:auto_increment]
|
27
|
+
column.unsigned = options[:unsigned]
|
28
|
+
column.charset = options[:charset]
|
29
|
+
column.collation = options[:collation]
|
30
|
+
column
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def create_column_definition(name, type)
|
36
|
+
ColumnDefinition.new(name, type)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
module SchemaCreation
|
41
|
+
def visit_AddColumn(o)
|
42
|
+
add_column_position!("ADD #{accept(o)}", column_options(o))
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def visit_ColumnDefinition(o)
|
48
|
+
o.sql_type = type_to_sql(o.type.to_sym, o.limit, o.precision, o.scale, o.unsigned)
|
49
|
+
column_sql = "#{quote_column_name(o.name)} #{o.sql_type}"
|
50
|
+
add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
|
51
|
+
column_sql
|
52
|
+
end
|
53
|
+
|
54
|
+
def visit_ChangeColumnDefinition(o)
|
55
|
+
change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}"
|
56
|
+
add_column_position!(change_column_sql, column_options(o.column))
|
57
|
+
end
|
58
|
+
|
59
|
+
def column_options(o)
|
60
|
+
column_options = super
|
61
|
+
column_options[:first] = o.first
|
62
|
+
column_options[:after] = o.after
|
63
|
+
column_options[:auto_increment] = o.auto_increment
|
64
|
+
column_options[:primary_key] = o.primary_key
|
65
|
+
column_options[:charset] = o.charset
|
66
|
+
column_options[:collation] = o.collation
|
67
|
+
column_options
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_column_options!(sql, options)
|
71
|
+
if options[:charset]
|
72
|
+
sql << " CHARACTER SET #{options[:charset]}"
|
14
73
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
74
|
+
if options[:collation]
|
75
|
+
sql << " COLLATE #{options[:collation]}"
|
76
|
+
end
|
77
|
+
if options[:primary_key] == true
|
78
|
+
sql << " PRIMARY KEY"
|
79
|
+
end
|
80
|
+
super
|
81
|
+
end
|
19
82
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
83
|
+
def add_column_position!(sql, options)
|
84
|
+
if options[:first]
|
85
|
+
sql << " FIRST"
|
86
|
+
elsif options[:after]
|
87
|
+
sql << " AFTER #{quote_column_name(options[:after])}"
|
24
88
|
end
|
25
|
-
|
26
|
-
|
89
|
+
sql
|
90
|
+
end
|
91
|
+
|
92
|
+
def type_to_sql(type, limit, precision, scale, unsigned = false)
|
93
|
+
@conn.type_to_sql(type.to_sym, limit, precision, scale, unsigned)
|
27
94
|
end
|
28
95
|
end
|
29
96
|
|
@@ -128,110 +195,30 @@ module ActiveRecord
|
|
128
195
|
include TimeValueWithPrecision
|
129
196
|
end
|
130
197
|
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
module ConnectionAdapters
|
135
|
-
class AbstractMysqlAdapter < AbstractAdapter
|
136
|
-
prepend Mysql::Awesome
|
137
|
-
|
138
|
-
class Column < ConnectionAdapters::Column # :nodoc:
|
139
|
-
prepend Mysql::Awesome::Column
|
140
|
-
end
|
141
198
|
|
142
|
-
|
143
|
-
end
|
199
|
+
public
|
144
200
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
|
155
|
-
def primary_key(name, type = :primary_key, options = {})
|
156
|
-
options[:auto_increment] ||= type == :bigint
|
157
|
-
super
|
158
|
-
end
|
159
|
-
|
160
|
-
def new_column_definition(name, type, options) # :nodoc:
|
161
|
-
column = super
|
162
|
-
column.auto_increment = options[:auto_increment]
|
163
|
-
column.unsigned = options[:unsigned]
|
164
|
-
column.charset = options[:charset]
|
165
|
-
column.collation = options[:collation]
|
166
|
-
column
|
167
|
-
end
|
168
|
-
|
169
|
-
private
|
170
|
-
|
171
|
-
def create_column_definition(name, type)
|
172
|
-
ColumnDefinition.new(name, type)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
class SchemaCreation < AbstractAdapter::SchemaCreation
|
177
|
-
def visit_AddColumn(o)
|
178
|
-
add_column_position!("ADD #{accept(o)}", column_options(o))
|
179
|
-
end
|
180
|
-
|
181
|
-
private
|
182
|
-
|
183
|
-
def visit_ColumnDefinition(o)
|
184
|
-
sql_type = type_to_sql(o.type.to_sym, o.limit, o.precision, o.scale, o.unsigned)
|
185
|
-
column_sql = "#{quote_column_name(o.name)} #{sql_type}"
|
186
|
-
add_column_options!(column_sql, column_options(o)) unless o.type == :primary_key
|
187
|
-
column_sql
|
188
|
-
end
|
189
|
-
|
190
|
-
def visit_ChangeColumnDefinition(o)
|
191
|
-
change_column_sql = "CHANGE #{quote_column_name(o.name)} #{accept(o.column)}"
|
192
|
-
add_column_position!(change_column_sql, column_options(o.column))
|
193
|
-
end
|
194
|
-
|
195
|
-
def column_options(o)
|
196
|
-
column_options = super
|
197
|
-
column_options[:first] = o.first
|
198
|
-
column_options[:after] = o.after
|
199
|
-
column_options[:auto_increment] = o.auto_increment
|
200
|
-
column_options[:primary_key] = o.primary_key
|
201
|
-
column_options[:charset] = o.charset
|
202
|
-
column_options[:collation] = o.collation
|
203
|
-
column_options
|
204
|
-
end
|
205
|
-
|
206
|
-
def add_column_options!(sql, options)
|
207
|
-
if options[:charset]
|
208
|
-
sql << " CHARACTER SET #{options[:charset]}"
|
209
|
-
end
|
210
|
-
if options[:collation]
|
211
|
-
sql << " COLLATE #{options[:collation]}"
|
212
|
-
end
|
213
|
-
if options[:primary_key] == true
|
214
|
-
sql << " PRIMARY KEY"
|
201
|
+
def type_to_sql(type, limit = nil, precision = nil, scale = nil, unsigned = false)
|
202
|
+
return "#{type_to_sql(type, limit, precision, scale)} unsigned" if unsigned && type != :primary_key
|
203
|
+
case type.to_s
|
204
|
+
when 'integer'
|
205
|
+
case limit
|
206
|
+
when nil, 4, 11; 'int' # compatibility with MySQL default
|
207
|
+
else
|
208
|
+
super(type, limit, precision, scale)
|
215
209
|
end
|
216
|
-
|
217
|
-
|
210
|
+
when 'primary_key'
|
211
|
+
"#{type_to_sql(:integer, limit, precision, scale, unsigned)} auto_increment PRIMARY KEY"
|
212
|
+
when 'datetime', 'time'
|
213
|
+
return super(type, limit, precision, scale) unless precision
|
218
214
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
sql << " AFTER #{quote_column_name(options[:after])}"
|
215
|
+
native_type = native_database_types[type.to_sym][:name]
|
216
|
+
case precision
|
217
|
+
when 0..6; "#{native_type}(#{precision})"
|
218
|
+
else raise(ActiveRecordError, "No #{native_type} type has precision of #{precision}. The allowed range of precision is from 0 to 6")
|
224
219
|
end
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
def type_to_sql(type, limit, precision, scale, unsigned = false)
|
229
|
-
@conn.type_to_sql(type.to_sym, limit, precision, scale, unsigned)
|
230
|
-
end
|
231
|
-
|
232
|
-
def quote_value(value, column)
|
233
|
-
column.sql_type ||= type_to_sql(column.type, column.limit, column.precision, column.scale, column.unsigned)
|
234
|
-
super
|
220
|
+
else
|
221
|
+
super(type, limit, precision, scale)
|
235
222
|
end
|
236
223
|
end
|
237
224
|
|
@@ -265,7 +252,7 @@ module ActiveRecord
|
|
265
252
|
end
|
266
253
|
|
267
254
|
def migration_keys
|
268
|
-
super
|
255
|
+
super | [:unsigned, :collation]
|
269
256
|
end
|
270
257
|
|
271
258
|
def table_options(table_name)
|
@@ -314,13 +301,14 @@ module ActiveRecord
|
|
314
301
|
schema_creation.accept(ChangeColumnDefinition.new(cd, column.name))
|
315
302
|
end
|
316
303
|
|
317
|
-
|
304
|
+
private
|
305
|
+
|
318
306
|
def configure_connection
|
319
307
|
_config = @config
|
320
308
|
if [':default', :default].include?(@config[:strict])
|
321
309
|
@config = @config.deep_merge(variables: { sql_mode: :default })
|
322
310
|
end
|
323
|
-
|
311
|
+
super
|
324
312
|
ensure
|
325
313
|
@config = _config
|
326
314
|
end
|
@@ -330,4 +318,18 @@ module ActiveRecord
|
|
330
318
|
end
|
331
319
|
end
|
332
320
|
end
|
321
|
+
|
322
|
+
module ConnectionAdapters
|
323
|
+
class AbstractMysqlAdapter < AbstractAdapter
|
324
|
+
prepend Mysql::Awesome
|
325
|
+
|
326
|
+
class Column < ConnectionAdapters::Column # :nodoc:
|
327
|
+
prepend Mysql::Awesome::Column
|
328
|
+
end
|
329
|
+
|
330
|
+
class SchemaCreation < AbstractAdapter::SchemaCreation
|
331
|
+
prepend Mysql::Awesome::SchemaCreation
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
333
335
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-mysql-awesome
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryuta Kamizono
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|