enum_table 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG
CHANGED
data/README.markdown
CHANGED
@@ -32,7 +32,7 @@ database directly. Another problem is the database cannot enforce any
|
|
32
32
|
This plugin implements a different strategy which solves the above problems -
|
33
33
|
each enum is defined by a table with `id` and `value` columns, which defines the
|
34
34
|
values and the integers they map to. Altering the values can be done with simple
|
35
|
-
|
35
|
+
DML statements, which do not require rebuilding any tables.
|
36
36
|
|
37
37
|
[enum_column3]: https://github.com/taktsoft/enum_column3
|
38
38
|
[pt-osc]: http://www.percona.com/doc/percona-toolkit/2.1/pt-online-schema-change.html
|
@@ -12,7 +12,6 @@ module EnumTable
|
|
12
12
|
table_names = @connection.enum_tables
|
13
13
|
table_names.each do |table_name|
|
14
14
|
stream.puts " create_enum_table #{table_name.inspect}, force: true do |t|"
|
15
|
-
enum_table_column(stream, table_name, 'id', SchemaStatements::DEFAULT_ID_ATTRIBUTES)
|
16
15
|
enum_table_column(stream, table_name, 'value', SchemaStatements::DEFAULT_VALUE_ATTRIBUTES)
|
17
16
|
@connection.execute("SELECT id, value FROM #{table_name} ORDER BY id").each do |row|
|
18
17
|
stream.puts " t.add #{row[1].to_s.inspect}, #{row[0]}"
|
@@ -22,7 +22,6 @@ module EnumTable
|
|
22
22
|
end.sort
|
23
23
|
end
|
24
24
|
|
25
|
-
DEFAULT_ID_ATTRIBUTES = {type: :integer, limit: 1, null: false}.freeze
|
26
25
|
DEFAULT_VALUE_ATTRIBUTES = {type: :string, limit: 255, null: false}.freeze
|
27
26
|
|
28
27
|
class NewTable
|
@@ -30,7 +29,6 @@ module EnumTable
|
|
30
29
|
@connection = connection
|
31
30
|
@name = name
|
32
31
|
@options = options
|
33
|
-
@id = DEFAULT_ID_ATTRIBUTES.dup
|
34
32
|
@value = DEFAULT_VALUE_ATTRIBUTES.dup
|
35
33
|
@adds = []
|
36
34
|
values = options.delete(:values) and
|
@@ -38,13 +36,12 @@ module EnumTable
|
|
38
36
|
end
|
39
37
|
|
40
38
|
def _create
|
41
|
-
@connection.create_table @name, @options
|
42
|
-
t.column :id, @id.delete(:type), @id
|
39
|
+
@connection.create_table @name, @options do |t|
|
43
40
|
t.column :value, @value.delete(:type), @value
|
44
41
|
end
|
45
42
|
unless @connection.table_exists?(:enum_tables)
|
46
43
|
@connection.create_table :enum_tables, id: false, force: true do |t|
|
47
|
-
t.string :table_name, null: false
|
44
|
+
t.string :table_name, null: false, limit: 255
|
48
45
|
end
|
49
46
|
end
|
50
47
|
@connection.execute "INSERT INTO enum_tables(table_name) VALUES('#{@name}')"
|
@@ -52,10 +49,6 @@ module EnumTable
|
|
52
49
|
@adds.each { |args| table.add(*args) }
|
53
50
|
end
|
54
51
|
|
55
|
-
def id(options)
|
56
|
-
@id.update(options)
|
57
|
-
end
|
58
|
-
|
59
52
|
def value(options)
|
60
53
|
@value.update(options)
|
61
54
|
end
|
data/lib/enum_table/version.rb
CHANGED
@@ -35,18 +35,6 @@ describe EnumTable::SchemaDumper do
|
|
35
35
|
EOS
|
36
36
|
end
|
37
37
|
|
38
|
-
it "dumps custom id column attributes" do
|
39
|
-
connection.create_enum_table :user_genders do |t|
|
40
|
-
t.id type: :string, limit: 20, null: true
|
41
|
-
end
|
42
|
-
ActiveRecord::SchemaDumper.dump(connection, stream)
|
43
|
-
stream.string.must_include(<<-EOS.gsub(/^ *\|/, ''))
|
44
|
-
| create_enum_table "user_genders", force: true do |t|
|
45
|
-
| t.id type: :string, limit: 20, null: true
|
46
|
-
| end
|
47
|
-
EOS
|
48
|
-
end
|
49
|
-
|
50
38
|
it "dumps custom value column attributes" do
|
51
39
|
connection.create_enum_table :user_genders do |t|
|
52
40
|
t.value type: :binary, limit: 20, null: true
|
@@ -28,15 +28,6 @@ describe EnumTable::SchemaStatements do
|
|
28
28
|
connection.create_enum_table :genders, force: true
|
29
29
|
end
|
30
30
|
|
31
|
-
it "allows configuring the id column in the block" do
|
32
|
-
connection.create_enum_table :genders do |t|
|
33
|
-
t.id type: :string, limit: 20
|
34
|
-
end
|
35
|
-
column = connection.columns(:genders).find { |c| c.name == 'id' }
|
36
|
-
column.type.must_equal :string
|
37
|
-
column.limit.must_equal 20
|
38
|
-
end
|
39
|
-
|
40
31
|
it "allows configuring the type column in the block" do
|
41
32
|
connection.create_enum_table :genders do |t|
|
42
33
|
t.value type: :binary, limit: 20
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enum_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
@@ -82,21 +82,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
82
|
- - ! '>='
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
hash: 123907201229092467
|
88
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
86
|
none: false
|
90
87
|
requirements:
|
91
88
|
- - ! '>='
|
92
89
|
- !ruby/object:Gem::Version
|
93
90
|
version: '0'
|
94
|
-
segments:
|
95
|
-
- 0
|
96
|
-
hash: 123907201229092467
|
97
91
|
requirements: []
|
98
92
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.8.
|
93
|
+
rubygems_version: 1.8.23
|
100
94
|
signing_key:
|
101
95
|
specification_version: 3
|
102
96
|
summary: Enumeration tables for ActiveRecord
|
@@ -107,3 +101,4 @@ test_files:
|
|
107
101
|
- test/enum_table/test_schema_dumper.rb
|
108
102
|
- test/enum_table/test_schema_statements.rb
|
109
103
|
- test/test_helper.rb
|
104
|
+
has_rdoc:
|