convergence 0.0.7 → 0.0.8
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: 31b591ac5f9afe5f6f73bdbbbb42378929607426
|
4
|
+
data.tar.gz: 3a86d9868b9c825d7b4ddc1b3dfb6a5997950897
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb0c1a6e8f2456dbbfd858efcf3e0bac1ce10d75e6098eea8cc9835d5f247b4e677e51b4b0ddc671e311c7773c9f3ac7ffbedeea39248d5cc6a8679c7bac0fbf
|
7
|
+
data.tar.gz: 252b96343e6936c1850446c0ab3b43efc2db1d734fa7b841e64eda9b4644b18f4a053cda78806d2e7e369f948c67c489e51c870af7f8478b503c4b063637960b
|
data/Gemfile.lock
CHANGED
@@ -48,6 +48,6 @@ SET FOREIGN_KEY_CHECKS=1;
|
|
48
48
|
input_tables_with_full_option =
|
49
49
|
Convergence::DefaultParameter.append_database_default_parameter(input_tables, database_adapter)
|
50
50
|
delta = Convergence::Diff.new.diff(current_tables_with_full_option, input_tables_with_full_option)
|
51
|
-
sql_generator.generate(input_tables_with_full_option, delta)
|
51
|
+
sql_generator.generate(input_tables_with_full_option, delta, current_tables_with_full_option)
|
52
52
|
end
|
53
53
|
end
|
@@ -119,6 +119,7 @@ class Convergence::Dumper::MysqlSchemaDumper
|
|
119
119
|
end
|
120
120
|
|
121
121
|
def parse_indexes(table, table_indexes)
|
122
|
+
return if table_indexes.nil?
|
122
123
|
table_indexes.group_by { |r| r['INDEX_NAME'] }.each do |index_name, indexes|
|
123
124
|
type = indexes.first['CONSTRAINT_TYPE']
|
124
125
|
columns = indexes.map { |v| v['COLUMN_NAME'] }
|
@@ -8,7 +8,10 @@ class SQLGenerator::MysqlGenerator < SQLGenerator
|
|
8
8
|
}
|
9
9
|
QUOTE_OPTION = [:comment]
|
10
10
|
|
11
|
-
|
11
|
+
attr_reader :original_table
|
12
|
+
|
13
|
+
def generate(to_table, delta, original_table)
|
14
|
+
@original_table = original_table
|
12
15
|
sqls = []
|
13
16
|
sqls << change_table_sql(to_table, delta)
|
14
17
|
sqls << ['']
|
@@ -63,7 +66,17 @@ class SQLGenerator::MysqlGenerator < SQLGenerator
|
|
63
66
|
def alter_change_column_sql(table_name, column_name, change_column_option, to_table)
|
64
67
|
column = to_table[table_name].columns[column_name]
|
65
68
|
column.options.merge!(after: change_column_option[:after]) unless change_column_option[:after].nil?
|
66
|
-
|
69
|
+
sql = ""
|
70
|
+
original_column = original_table[table_name].columns[column_name]
|
71
|
+
if original_column.options[:primary_key]
|
72
|
+
extra = original_column.options[:extra]
|
73
|
+
if extra && extra.upcase.include?('AUTO_INCREMENT')
|
74
|
+
sql += %(ALTER TABLE `#{table_name}` MODIFY COLUMN #{create_column_sql(original_column, output_auto_increment: false)};\n)
|
75
|
+
end
|
76
|
+
sql += %(ALTER TABLE `#{table_name}` DROP PRIMARY KEY;\n)
|
77
|
+
end
|
78
|
+
sql += %(ALTER TABLE `#{table_name}` MODIFY COLUMN #{create_column_sql(column, output_primary_key: true)};)
|
79
|
+
sql
|
67
80
|
end
|
68
81
|
|
69
82
|
def alter_change_table_sql(table_name, change_table_option)
|
@@ -131,7 +144,7 @@ DROP TABLE `#{table_name}`;
|
|
131
144
|
end
|
132
145
|
end
|
133
146
|
|
134
|
-
def create_column_sql(column, output_primary_key: false)
|
147
|
+
def create_column_sql(column, output_primary_key: false, output_auto_increment: true)
|
135
148
|
sql = "`#{column.column_name}`"
|
136
149
|
sql += " #{column.type}"
|
137
150
|
sql += "(#{column.options[:limit]})" unless column.options[:limit].nil?
|
@@ -159,7 +172,11 @@ DROP TABLE `#{table_name}`;
|
|
159
172
|
sql += " COMMENT '#{column.options[:comment]}'"
|
160
173
|
end
|
161
174
|
if column.options[:extra]
|
162
|
-
|
175
|
+
if output_auto_increment
|
176
|
+
sql += " #{column.options[:extra].upcase}"
|
177
|
+
else
|
178
|
+
sql += " #{column.options[:extra].upcase.sub('AUTO_INCREMENT', '')}"
|
179
|
+
end
|
163
180
|
end
|
164
181
|
if column.options.keys.include?(:after)
|
165
182
|
if column.options[:after].nil?
|
data/lib/convergence/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: convergence
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shinsuke Nishio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mysql2
|