zdm 1.0.6 → 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gemfiles/4.1.gemfile.lock +1 -1
- data/gemfiles/4.2.gemfile.lock +1 -1
- data/gemfiles/5.0.gemfile.lock +1 -1
- data/lib/version.rb +1 -1
- data/lib/zdm.rb +28 -0
- data/spec/zdm_spec.rb +9 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 325f45e849c39b9770c22c7ce892a41f153b6a30
|
4
|
+
data.tar.gz: acb9889d53d320c1d9b74d570f2cfdbc18d2828f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a6efd42171ebfe5bc3f152cbc238cf06cfe53322e66d6198bd45dcd702ed5ce6b67446aaee5251f21c63c7de32ae3c7493357b5039457ce513fbd8c7040c813
|
7
|
+
data.tar.gz: 6773233f8e943de709541d87ea7517b0a0d2d662564d27d5f235976086410a22ed845c2b723a5a5ab0e758fb1dc9183e95016cf0a7007d9d0aa501f6dda156f2
|
data/gemfiles/4.1.gemfile.lock
CHANGED
data/gemfiles/4.2.gemfile.lock
CHANGED
data/gemfiles/5.0.gemfile.lock
CHANGED
data/lib/version.rb
CHANGED
data/lib/zdm.rb
CHANGED
@@ -136,6 +136,34 @@ module Zdm
|
|
136
136
|
def rename_column(old_name, new_name)
|
137
137
|
raise "Unsupported: you must first run a migration adding the column `#{new_name}`, deploy the code live, then run another migration at a later time to remove the column `#{old_name}`"
|
138
138
|
end
|
139
|
+
|
140
|
+
def add_index(column_names, opts = {})
|
141
|
+
column_names = Array(column_names)
|
142
|
+
index_name = opts[:name] || "index_#{@origin}_on_#{column_names.join('_and_')}"
|
143
|
+
raise ArgumentError, "Index name '#{index_name}' on table #{@origin} is too long" if index_name.length > 64
|
144
|
+
index_type = opts[:type] || (opts[:unique] ? 'UNIQUE' : '')
|
145
|
+
index_using = "USING #{opts[:using] || 'btree'}"
|
146
|
+
index_columns = quoted_columns_for_index(column_names, opts).join(',')
|
147
|
+
ddl("CREATE #{index_type} INDEX `#{index_name}` #{index_using} ON `#{@copy}` (#{index_columns})")
|
148
|
+
end
|
149
|
+
|
150
|
+
def remove_index(index_name)
|
151
|
+
ddl("ALTER TABLE `#{@copy}` DROP INDEX `#{index_name}`")
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def quoted_columns_for_index(column_names, opts)
|
157
|
+
option_strings = Hash[column_names.map {|name| [name, '']}]
|
158
|
+
length = opts[:length]
|
159
|
+
case length
|
160
|
+
when Hash
|
161
|
+
column_names.each {|name| option_strings[name] += "(#{length[name]})" if length.has_key?(name) && length[name].present?}
|
162
|
+
when Integer
|
163
|
+
column_names.each {|name| option_strings[name] += "(#{length})"}
|
164
|
+
end
|
165
|
+
column_names.map {|name| "`#{name}`#{option_strings[name]}"}
|
166
|
+
end
|
139
167
|
end
|
140
168
|
|
141
169
|
class Migrator
|
data/spec/zdm_spec.rb
CHANGED
@@ -36,6 +36,9 @@ describe Zdm do
|
|
36
36
|
m.alter("DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci")
|
37
37
|
m.add_column('test', "varchar(32) DEFAULT 'foo'")
|
38
38
|
m.change_column('name', 'varchar(99) NOT NULL')
|
39
|
+
m.remove_index('index_people_on_created_at')
|
40
|
+
m.add_index(:code)
|
41
|
+
m.add_index([:created_at, :code], unique: true, name: 'idx_test', length: {code: 191})
|
39
42
|
end
|
40
43
|
|
41
44
|
conn = ActiveRecord::Base.connection
|
@@ -50,8 +53,9 @@ describe Zdm do
|
|
50
53
|
`test` varchar(32) COLLATE utf8_unicode_ci DEFAULT 'foo',
|
51
54
|
PRIMARY KEY (`id`),
|
52
55
|
UNIQUE KEY `index_people_on_name` (`name`) USING BTREE,
|
56
|
+
UNIQUE KEY `idx_test` (`created_at`,`code`(191)) USING BTREE,
|
53
57
|
KEY `index_people_on_account_id_and_code` (`account_id`,`code`(191)) USING BTREE,
|
54
|
-
KEY `
|
58
|
+
KEY `index_people_on_code` (`code`(191)) USING BTREE
|
55
59
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
|
56
60
|
EOS
|
57
61
|
|
@@ -82,10 +86,12 @@ describe Zdm do
|
|
82
86
|
`account_id` int(11) DEFAULT NULL,
|
83
87
|
`name` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
84
88
|
`code` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
85
|
-
`created_at` datetime DEFAULT NULL,
|
89
|
+
`created_at` datetime DEFAULT NULL,
|
90
|
+
PRIMARY KEY (`id`),
|
86
91
|
UNIQUE KEY `index_people_on_name` (`name`) USING BTREE,
|
92
|
+
UNIQUE KEY `idx_test` (`created_at`,`code`(191)) USING BTREE,
|
87
93
|
KEY `index_people_on_account_id_and_code` (`account_id`,`code`(191)) USING BTREE,
|
88
|
-
KEY `
|
94
|
+
KEY `index_people_on_code` (`code`(191)) USING BTREE
|
89
95
|
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
90
96
|
EOS
|
91
97
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zdm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ITRP Institute, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|