activerecord-database_unsigned_columns 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +27 -0
- data/lib/active_record/database_unsigned_columns/adapters/mysql_adapter.rb +50 -0
- data/lib/active_record/database_unsigned_columns/definitions/column.rb +31 -0
- data/lib/active_record/database_unsigned_columns/definitions/table.rb +34 -0
- data/lib/active_record/database_unsigned_columns/railtie.rb +38 -0
- data/lib/activerecord-database_unsigned_columns.rb +2 -0
- metadata +101 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'UnsignedColumn'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ActiveRecord
|
3
|
+
module DatabaseUnsignedColumns
|
4
|
+
module Adapters
|
5
|
+
|
6
|
+
# Basado en http://thewebfellas.com/blog/2008/6/2/unsigned-integers-for-mysql-on-rails
|
7
|
+
# Modulo con extensiones/patches para ActiveRecord::Adapters::MysqlAdapter
|
8
|
+
module MysqlAdapter
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
# Se ejecuta cuando el modulo ha sido incluido en la clase
|
13
|
+
included do
|
14
|
+
self::NATIVE_DATABASE_TYPES[:primary_key] = 'INT UNSIGNED DEFAULT NULL auto_increment PRIMARY KEY'
|
15
|
+
alias_method_chain :add_column_sql, :unsigned
|
16
|
+
alias_method_chain :type_to_sql, :unsigned
|
17
|
+
# alias_method_chain :create_table, :mysql_options
|
18
|
+
|
19
|
+
# Incluir patch a self::Column:
|
20
|
+
#"#{self.name}::Column".constantize.send :include, NumericTypeColumn::ActiveRecord::MysqlColumnPatch
|
21
|
+
end
|
22
|
+
|
23
|
+
=begin
|
24
|
+
def create_table_with_mysql_options(table_name, options = {}) #:nodoc:
|
25
|
+
create_table_without_mysql_options(table_name, options.reverse_merge(options: options[:mysql_options] ? options[:mysql_options] : "ENGINE=InnoDB"))
|
26
|
+
end
|
27
|
+
=end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def add_column_sql_with_unsigned(table_name, column_name, type, options = {})
|
32
|
+
is_unsigned_valid = (((options.has_key? :unsigned) && (options[:unsigned] == true)) && (['integer', 'decimal', 'float', 'boolean'].include? type.to_s))
|
33
|
+
add_column_sql = "ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale], is_unsigned_valid)}"
|
34
|
+
add_column_options!(add_column_sql, options)
|
35
|
+
add_column_position!(add_column_sql, options)
|
36
|
+
add_column_sql
|
37
|
+
end
|
38
|
+
|
39
|
+
def type_to_sql_with_unsigned(type, limit = nil, precision = nil, scale = nil, unsigned = false)
|
40
|
+
sql = type_to_sql_without_unsigned(type, limit, precision, scale)
|
41
|
+
sql << ' UNSIGNED' if unsigned && (['integer', 'decimal', 'float', 'boolean'].include? type.to_s)
|
42
|
+
sql
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ActiveRecord
|
3
|
+
module DatabaseUnsignedColumns
|
4
|
+
module Definitions
|
5
|
+
|
6
|
+
# Basado en http://thewebfellas.com/blog/2008/6/2/unsigned-integers-for-mysql-on-rails
|
7
|
+
# Modulo con extensiones/patches para ActiveRecord::ConnectionAdapters::ColumnDefinition.
|
8
|
+
module Column
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
included do
|
13
|
+
attr_accessor :unsigned
|
14
|
+
alias_method_chain :sql_type, :unsigned
|
15
|
+
end
|
16
|
+
|
17
|
+
# Override de #sql_type
|
18
|
+
def sql_type_with_unsigned
|
19
|
+
# Cambio: signature de call base.type_to_sql:
|
20
|
+
if base.method(:type_to_sql).parameters.include?([:opt, :unsigned])
|
21
|
+
base.type_to_sql(type.to_sym, limit, precision, scale, unsigned) rescue type
|
22
|
+
else
|
23
|
+
base.type_to_sql(type.to_sym, limit, precision, scale) rescue type
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ActiveRecord
|
3
|
+
module DatabaseUnsignedColumns
|
4
|
+
module Definitions
|
5
|
+
|
6
|
+
# Basado en http://thewebfellas.com/blog/2008/6/2/unsigned-integers-for-mysql-on-rails
|
7
|
+
# Modulo con extensiones/patches para ActiveRecord::ConnectionAdapters::TableDefinition
|
8
|
+
module Table
|
9
|
+
|
10
|
+
extend ActiveSupport::Concern
|
11
|
+
|
12
|
+
# Ocurre al momento de incluirse éste módulo a la clase ActiveRecord::TableDefinition
|
13
|
+
included do
|
14
|
+
# Agregar en cadena el metodo column_with_unsigned:
|
15
|
+
alias_method_chain :column, :unsigned
|
16
|
+
end
|
17
|
+
|
18
|
+
# Permite dentro de una migracion:
|
19
|
+
# def change
|
20
|
+
# create_table :tablename do |t|
|
21
|
+
# t.integer :uno, unsigned: true
|
22
|
+
# end
|
23
|
+
# end
|
24
|
+
def column_with_unsigned(name, type, options = {})
|
25
|
+
ret_column = column_without_unsigned(name, type, options)
|
26
|
+
ret_column[name].unsigned = options[:unsigned]
|
27
|
+
ret_column
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ActiveRecord
|
3
|
+
module DatabaseUnsignedColumns
|
4
|
+
|
5
|
+
class Railtie < ::Rails::Railtie #:nodoc:
|
6
|
+
|
7
|
+
initializer 'active_record.extended_support.database_unsigned_columns' do |app|
|
8
|
+
|
9
|
+
ActiveSupport.on_load(:active_record) do
|
10
|
+
|
11
|
+
# Agregar el modulo para soportar definiciones de columnas unsigned:
|
12
|
+
require 'active_record/database_unsigned_columns/definitions/column'
|
13
|
+
ActiveRecord::ConnectionAdapters::ColumnDefinition.send :include, ActiveRecord::DatabaseUnsignedColumns::Definitions::Column
|
14
|
+
|
15
|
+
# Agregar el modulo para soportar definiciones de tablas con columnas unsigned:
|
16
|
+
require 'active_record/database_unsigned_columns/definitions/table'
|
17
|
+
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, ActiveRecord::DatabaseUnsignedColumns::Definitions::Table
|
18
|
+
|
19
|
+
# Agregar modulo a los adapters de BD:
|
20
|
+
require 'active_record/database_unsigned_columns/adapters/mysql_adapter'
|
21
|
+
[
|
22
|
+
"ActiveRecord::ConnectionAdapters::MysqlAdapter",
|
23
|
+
"ActiveRecord::ConnectionAdapters::Mysql2Adapter",
|
24
|
+
"ActiveRecord::ConnectionAdapters::Mysql2SpatialAdapter", # Adapter para rgeo-mysql
|
25
|
+
"ArJdbc::MySQL" # Adapter para jRuby JDBC
|
26
|
+
].each do |mysql_adapter_class|
|
27
|
+
adapter_class = mysql_adapter_class.safe_constantize
|
28
|
+
adapter_class.send :include, ActiveRecord::DatabaseUnsignedColumns::Adapters::MysqlAdapter if adapter_class.present?
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-database_unsigned_columns
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Roberto Quintanilla Gonzalez
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.2.12
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.2.12
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activerecord-database_schema
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - '='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.0.6
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - '='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.0.6
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mysql2
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Support for unsigned integer columns in ActiveRecord migrations.
|
63
|
+
email:
|
64
|
+
- roberto.quintanilla@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/active_record/database_unsigned_columns/adapters/mysql_adapter.rb
|
70
|
+
- lib/active_record/database_unsigned_columns/definitions/column.rb
|
71
|
+
- lib/active_record/database_unsigned_columns/definitions/table.rb
|
72
|
+
- lib/active_record/database_unsigned_columns/railtie.rb
|
73
|
+
- lib/activerecord-database_unsigned_columns.rb
|
74
|
+
- MIT-LICENSE
|
75
|
+
- Rakefile
|
76
|
+
- README.rdoc
|
77
|
+
homepage: https://github.com/vovimayhem
|
78
|
+
licenses: []
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 1.8.25
|
98
|
+
signing_key:
|
99
|
+
specification_version: 3
|
100
|
+
summary: Support for unsigned integer columns in ActiveRecord migrations.
|
101
|
+
test_files: []
|