flydata 0.2.17 → 0.2.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/flydata-core/.gitignore +16 -0
- data/flydata-core/.rspec +1 -0
- data/flydata-core/.travis.yml +6 -0
- data/flydata-core/Gemfile +11 -0
- data/flydata-core/Gemfile.lock +51 -0
- data/flydata-core/lib/flydata-core/core_ext/module/include.rb +5 -0
- data/flydata-core/lib/flydata-core/core_ext/module.rb +1 -0
- data/flydata-core/lib/flydata-core/core_ext/object/prepend.rb +17 -0
- data/flydata-core/lib/flydata-core/core_ext/object.rb +1 -0
- data/flydata-core/lib/flydata-core/core_ext.rb +3 -0
- data/flydata-core/lib/flydata-core/errors.rb +334 -0
- data/flydata-core/lib/flydata-core/logger.rb +205 -0
- data/{lib/flydata → flydata-core/lib/flydata-core}/table_def/mysql_table_def.rb +6 -8
- data/{lib/flydata → flydata-core/lib/flydata-core}/table_def/redshift_table_def.rb +17 -2
- data/flydata-core/lib/flydata-core/table_def.rb +2 -0
- data/flydata-core/lib/flydata-core/thread_context.rb +31 -0
- data/flydata-core/lib/flydata-core.rb +1 -0
- data/flydata-core/spec/spec_helper.rb +2 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysql_table_def_spec.rb +22 -8
- data/flydata-core/spec/table_def/mysql_to_redshift_table_def_spec.rb +428 -0
- data/flydata-core/spec/table_def/mysqldump_test_bit_table.dump +51 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_foreign_key.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_all.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_column_comment.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_enum.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_multi_pk.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_table_no_pk.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unique_key.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unique_key2.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unique_key3.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/mysqldump_test_unsigned.dump +0 -0
- data/{spec/flydata → flydata-core/spec}/table_def/redshift_table_def_spec.rb +63 -16
- data/flydata.gemspec +34 -18
- data/lib/flydata/command/sync.rb +11 -8
- data/lib/flydata/parser/mysql/mysql_alter_table.treetop +128 -18
- data/lib/flydata/parser_provider.rb +1 -1
- data/lib/flydata.rb +11 -1
- data/spec/flydata/parser/mysql/alter_table_parser_spec.rb +173 -2
- data/spec/spec_helper.rb +3 -1
- metadata +34 -18
- data/.gitignore +0 -49
- data/lib/flydata/table_def.rb +0 -2
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module FlydataCore
|
2
2
|
module TableDef
|
3
3
|
|
4
4
|
class MysqlTableDef
|
@@ -78,8 +78,8 @@ class MysqlTableDef
|
|
78
78
|
nil
|
79
79
|
end
|
80
80
|
|
81
|
-
def self.create(io)
|
82
|
-
params = _create(io)
|
81
|
+
def self.create(io, options = {})
|
82
|
+
params = _create(io, options)
|
83
83
|
params ? self.new(*params) : nil
|
84
84
|
end
|
85
85
|
|
@@ -91,7 +91,7 @@ class MysqlTableDef
|
|
91
91
|
@comment = comment
|
92
92
|
end
|
93
93
|
|
94
|
-
def self._create(io)
|
94
|
+
def self._create(io, options)
|
95
95
|
table_def = ''
|
96
96
|
table_name = nil
|
97
97
|
columns = []
|
@@ -136,7 +136,7 @@ class MysqlTableDef
|
|
136
136
|
end
|
137
137
|
|
138
138
|
when :after_create_table
|
139
|
-
unless columns.any? {|column| column[:primary_key]}
|
139
|
+
unless columns.any? {|column| column[:primary_key]} or options[:skip_primary_key_check]
|
140
140
|
raise TableDefError, {error: "no primary key defined", table: table_name}
|
141
141
|
end
|
142
142
|
break
|
@@ -196,10 +196,8 @@ class MysqlTableDef
|
|
196
196
|
column[:auto_increment] = true if line =~ /AUTO_INCREMENT/i
|
197
197
|
column[:not_null] = true if line =~ /NOT NULL/i
|
198
198
|
column[:unique] = true if line =~ /UNIQUE/i
|
199
|
-
if /DEFAULT\s+((?:[
|
199
|
+
if /DEFAULT\s+((?:[bx]?'(?:\\'|[^'])*')|(?:[^'\s]+\b))/i.match(line)
|
200
200
|
val = $1
|
201
|
-
val = val.slice(1..-1) if val.start_with?("'")
|
202
|
-
val = val.slice(0..-2) if val.end_with?("'")
|
203
201
|
column[:default] = val == "NULL" ? nil : val
|
204
202
|
end
|
205
203
|
if /COMMENT\s+'(((?:\\'|[^'])*))'/i.match(line)
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
require 'date'
|
2
|
+
require 'flydata-core/errors'
|
3
|
+
|
4
|
+
module FlydataCore
|
2
5
|
module TableDef
|
3
6
|
|
4
7
|
class RedshiftTableDef
|
@@ -140,7 +143,19 @@ EOS
|
|
140
143
|
when 'date'
|
141
144
|
"'#{self.parse_date(default_value)}'"
|
142
145
|
else
|
143
|
-
|
146
|
+
if !default_value.kind_of?(String)
|
147
|
+
"'#{default_value}'"
|
148
|
+
elsif /^b'.+'$/.match(default_value)
|
149
|
+
"0b#{default_value[2..-2]}".oct
|
150
|
+
elsif /^[xX]'.+'$/.match(default_value)
|
151
|
+
"0x#{default_value[2..-2]}".oct
|
152
|
+
elsif /^0[bx].+/.match(default_value)
|
153
|
+
default_value.oct
|
154
|
+
elsif /^'.*'$/.match(default_value)
|
155
|
+
default_value
|
156
|
+
else
|
157
|
+
"'#{default_value}'"
|
158
|
+
end
|
144
159
|
end
|
145
160
|
end
|
146
161
|
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module FlydataCore
|
2
|
+
class ThreadContext
|
3
|
+
THREAD_LOCAL_KEY = 'flydata_thread_context'
|
4
|
+
|
5
|
+
def self.initialize(params = {})
|
6
|
+
Thread.current[THREAD_LOCAL_KEY] = params
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.initialized?
|
10
|
+
!!(Thread.current[THREAD_LOCAL_KEY])
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.parameters
|
14
|
+
Thread.current[THREAD_LOCAL_KEY]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.[](k)
|
18
|
+
h = Thread.current[THREAD_LOCAL_KEY]
|
19
|
+
h[k]
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.[]=(k, v)
|
23
|
+
h = Thread.current[THREAD_LOCAL_KEY]
|
24
|
+
h[k] = v
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.reset
|
28
|
+
Thread.current[THREAD_LOCAL_KEY] = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# Add require here
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'flydata/table_def'
|
2
|
+
require 'flydata-core/table_def'
|
3
3
|
|
4
|
-
module
|
4
|
+
module FlydataCore
|
5
5
|
module TableDef
|
6
6
|
|
7
7
|
|
@@ -33,7 +33,7 @@ describe MysqlTableDef do
|
|
33
33
|
{:column=>"id", :type=>"int8(20)", :auto_increment=>true, :not_null=>true, :primary_key=>true},
|
34
34
|
{:column=>"col_binary", :type=>"binary(202)", :default=>nil},
|
35
35
|
{:column=>"col_blob", :type=>"varbinary(65535)"},
|
36
|
-
{:column=>"col_bool", :type=>"int1(1)", :default=>"0"},
|
36
|
+
{:column=>"col_bool", :type=>"int1(1)", :default=>"'0'"},
|
37
37
|
{:column=>"col_char", :type=>"varchar(18)", :default=>nil},
|
38
38
|
{:column=>"col_date", :type=>"date", :default=>nil},
|
39
39
|
{:column=>"col_datetime", :type=>"datetime", :default=>nil},
|
@@ -73,7 +73,7 @@ describe MysqlTableDef do
|
|
73
73
|
context 'when table does not have primary key' do
|
74
74
|
let(:dump_file_io) { file_io('mysqldump_test_table_no_pk.dump') }
|
75
75
|
it 'should raise an error' do
|
76
|
-
expect{subject}.to raise_error(
|
76
|
+
expect{subject}.to raise_error(FlydataCore::TableDefError)
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
@@ -82,7 +82,7 @@ describe MysqlTableDef do
|
|
82
82
|
it 'comment should be set' do
|
83
83
|
expect(subject[:columns]).to eq(
|
84
84
|
[
|
85
|
-
{:column=>"id", :type=>"int4(11)", :not_null=>true, :default=>"0",
|
85
|
+
{:column=>"id", :type=>"int4(11)", :not_null=>true, :default=>"'0'",
|
86
86
|
:comment=>"this is primary key", :primary_key=>true},
|
87
87
|
{:column=>"value", :type=>"text"}
|
88
88
|
]
|
@@ -95,8 +95,8 @@ describe MysqlTableDef do
|
|
95
95
|
it 'multi pk should be set' do
|
96
96
|
expect(subject[:columns]).to eq(
|
97
97
|
[
|
98
|
-
{:column=>"id1", :type=>"int4(11)", :not_null=>true, :default=>"0", :primary_key=>true},
|
99
|
-
{:column=>"id2", :type=>"int4(11)", :not_null=>true, :default=>"0", :primary_key=>true},
|
98
|
+
{:column=>"id1", :type=>"int4(11)", :not_null=>true, :default=>"'0'", :primary_key=>true},
|
99
|
+
{:column=>"id2", :type=>"int4(11)", :not_null=>true, :default=>"'0'", :primary_key=>true},
|
100
100
|
{:column=>"value", :type=>"text"}
|
101
101
|
]
|
102
102
|
)
|
@@ -110,7 +110,7 @@ describe MysqlTableDef do
|
|
110
110
|
[
|
111
111
|
{:column=>"id", :type=>"int4(11)", :not_null=>true, :primary_key=>true},
|
112
112
|
{:column=>"enum_1", :type=>"enum('apple','orange','banana')", :default=>nil},
|
113
|
-
{:column=>"enum_2", :type=>"enum('a','b','c')", :default=>"a"},
|
113
|
+
{:column=>"enum_2", :type=>"enum('a','b','c')", :default=>"'a'"},
|
114
114
|
{:column=>"enum_3", :type=>"enum('e','f','g')", :not_null=>true},
|
115
115
|
]
|
116
116
|
)
|
@@ -184,6 +184,20 @@ describe MysqlTableDef do
|
|
184
184
|
}
|
185
185
|
end
|
186
186
|
end
|
187
|
+
|
188
|
+
context 'when table has bit with 0b default value' do
|
189
|
+
let(:dump_file_io) { file_io('mysqldump_test_bit_table.dump')}
|
190
|
+
it 'should extract default bit value appropriately' do
|
191
|
+
expect(subject[:columns][1][:default]).to eq("b'1'")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when table has int with 0x default value' do
|
196
|
+
let(:dump_file_io) { file_io('mysqldump_test_bit_table.dump')}
|
197
|
+
it 'should extract default int value appropriately' do
|
198
|
+
expect(subject[:columns][2][:default]).to eq("x'10'")
|
199
|
+
end
|
200
|
+
end
|
187
201
|
end
|
188
202
|
end
|
189
203
|
|
@@ -0,0 +1,428 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'flydata-core/table_def'
|
3
|
+
|
4
|
+
module FlydataCore
|
5
|
+
module TableDef
|
6
|
+
describe 'generate redshift table ddl from mysqldump' do
|
7
|
+
|
8
|
+
# file full path which exists in same directory.
|
9
|
+
def full_path(file_name)
|
10
|
+
File.join(File.dirname(__FILE__), file_name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def file_io(file_name)
|
14
|
+
File.new(full_path(file_name))
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:dump_file_name) { raise "file_name must be override on context." }
|
18
|
+
let(:dump_file_io) { file_io(dump_file_name) }
|
19
|
+
|
20
|
+
subject {
|
21
|
+
RedshiftTableDef.from_flydata_tabledef(
|
22
|
+
MysqlTableDef.create(dump_file_io).to_flydata_tabledef)
|
23
|
+
}
|
24
|
+
|
25
|
+
context 'with mysqldump_test_table_all' do
|
26
|
+
let(:dump_file_name) { 'mysqldump_test_table_all.dump' }
|
27
|
+
|
28
|
+
it 'should return ddl' do
|
29
|
+
expect(subject).to eq( <<EOT.strip )
|
30
|
+
CREATE TABLE "flydata_ctl_columns"(
|
31
|
+
id integer NOT NULL IDENTITY(1,1),
|
32
|
+
table_name varchar(128) NOT NULL,
|
33
|
+
column_name varchar(128) NOT NULL,
|
34
|
+
src_data_type varchar(1024) NOT NULL,
|
35
|
+
revision int NOT NULL DEFAULT 1,
|
36
|
+
ordinal_position int NOT NULL,
|
37
|
+
PRIMARY KEY(id)
|
38
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
39
|
+
DROP TABLE "test_table_all";
|
40
|
+
CREATE TABLE "test_table_all" (
|
41
|
+
"id" int8 NOT NULL,
|
42
|
+
"col_binary" varchar(202) DEFAULT NULL,
|
43
|
+
"col_blob" varchar(65535),
|
44
|
+
"col_bool" int2 DEFAULT '0',
|
45
|
+
"col_char" varchar(18) DEFAULT NULL,
|
46
|
+
"col_date" date DEFAULT NULL,
|
47
|
+
"col_datetime" timestamp DEFAULT NULL,
|
48
|
+
"col_decimal" numeric(5,2) DEFAULT NULL,
|
49
|
+
"col_double" float8 DEFAULT NULL,
|
50
|
+
"col_float" float4 DEFAULT NULL,
|
51
|
+
"col_float_4_2" float4 DEFAULT NULL,
|
52
|
+
"col_int" int4 DEFAULT NULL,
|
53
|
+
"col_int_6" int4 DEFAULT NULL,
|
54
|
+
"col_longblob" varchar(65535),
|
55
|
+
"col_longtext" varchar(max),
|
56
|
+
"col_mediumblob" varchar(65535),
|
57
|
+
"col_mediumint" int4 DEFAULT NULL,
|
58
|
+
"col_mediumtext" varchar(max),
|
59
|
+
"col_smallint" int2 DEFAULT NULL,
|
60
|
+
"col_text" varchar(max),
|
61
|
+
"col_time" timestamp DEFAULT NULL,
|
62
|
+
"col_timestamp" timestamp NOT NULL DEFAULT SYSDATE,
|
63
|
+
"col_tinyblob" varchar(255),
|
64
|
+
"col_tinyint" int2 DEFAULT NULL,
|
65
|
+
"col_tinytext" varchar(max),
|
66
|
+
"col_varbinary" varchar(512) DEFAULT NULL,
|
67
|
+
"col_varchar" varchar(372) DEFAULT NULL,
|
68
|
+
PRIMARY KEY (id)
|
69
|
+
);
|
70
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'test_table_all';
|
71
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
72
|
+
('test_table_all', 'id', 'int8(20)', 1),
|
73
|
+
('test_table_all', 'col_binary', 'binary(202)', 2),
|
74
|
+
('test_table_all', 'col_blob', 'varbinary(65535)', 3),
|
75
|
+
('test_table_all', 'col_bool', 'int1(1)', 4),
|
76
|
+
('test_table_all', 'col_char', 'varchar(18)', 5),
|
77
|
+
('test_table_all', 'col_date', 'date', 6),
|
78
|
+
('test_table_all', 'col_datetime', 'datetime', 7),
|
79
|
+
('test_table_all', 'col_decimal', 'numeric(5,2)', 8),
|
80
|
+
('test_table_all', 'col_double', 'float8', 9),
|
81
|
+
('test_table_all', 'col_float', 'float4', 10),
|
82
|
+
('test_table_all', 'col_float_4_2', 'float4(4,2)', 11),
|
83
|
+
('test_table_all', 'col_int', 'int4(11)', 12),
|
84
|
+
('test_table_all', 'col_int_6', 'int4(6)', 13),
|
85
|
+
('test_table_all', 'col_longblob', 'varbinary(4294967295)', 14),
|
86
|
+
('test_table_all', 'col_longtext', 'text', 15),
|
87
|
+
('test_table_all', 'col_mediumblob', 'varbinary(16777215)', 16),
|
88
|
+
('test_table_all', 'col_mediumint', 'int3(9)', 17),
|
89
|
+
('test_table_all', 'col_mediumtext', 'text', 18),
|
90
|
+
('test_table_all', 'col_smallint', 'int2(6)', 19),
|
91
|
+
('test_table_all', 'col_text', 'text', 20),
|
92
|
+
('test_table_all', 'col_time', 'time', 21),
|
93
|
+
('test_table_all', 'col_timestamp', 'datetime', 22),
|
94
|
+
('test_table_all', 'col_tinyblob', 'varbinary(255)', 23),
|
95
|
+
('test_table_all', 'col_tinyint', 'int1(4)', 24),
|
96
|
+
('test_table_all', 'col_tinytext', 'text', 25),
|
97
|
+
('test_table_all', 'col_varbinary', 'varbinary(512)', 26),
|
98
|
+
('test_table_all', 'col_varchar', 'varchar(372)', 27);
|
99
|
+
EOT
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context 'with mysqldump_test_bit_table.dump' do
|
104
|
+
let(:dump_file_name) { 'mysqldump_test_bit_table.dump' }
|
105
|
+
|
106
|
+
it 'should return ddl' do
|
107
|
+
expect(subject).to eq( <<EOT.strip )
|
108
|
+
CREATE TABLE "flydata_ctl_columns"(
|
109
|
+
id integer NOT NULL IDENTITY(1,1),
|
110
|
+
table_name varchar(128) NOT NULL,
|
111
|
+
column_name varchar(128) NOT NULL,
|
112
|
+
src_data_type varchar(1024) NOT NULL,
|
113
|
+
revision int NOT NULL DEFAULT 1,
|
114
|
+
ordinal_position int NOT NULL,
|
115
|
+
PRIMARY KEY(id)
|
116
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
117
|
+
DROP TABLE "bit_test_def_1";
|
118
|
+
CREATE TABLE "bit_test_def_1" (
|
119
|
+
"id" int4 NOT NULL,
|
120
|
+
"bit_value" bigint DEFAULT 1,
|
121
|
+
"int_value" int4 DEFAULT 16,
|
122
|
+
PRIMARY KEY (id)
|
123
|
+
);
|
124
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'bit_test_def_1';
|
125
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
126
|
+
('bit_test_def_1', 'id', 'int4(11)', 1),
|
127
|
+
('bit_test_def_1', 'bit_value', 'bit(1)', 2),
|
128
|
+
('bit_test_def_1', 'int_value', 'int4(11)', 3);
|
129
|
+
EOT
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'with mysqldump_test_foreign_key.dump' do
|
134
|
+
let(:dump_file_name) { 'mysqldump_test_foreign_key.dump' }
|
135
|
+
|
136
|
+
it 'should return ddl' do
|
137
|
+
expect(subject).to eq( <<EOT.strip )
|
138
|
+
CREATE TABLE "flydata_ctl_columns"(
|
139
|
+
id integer NOT NULL IDENTITY(1,1),
|
140
|
+
table_name varchar(128) NOT NULL,
|
141
|
+
column_name varchar(128) NOT NULL,
|
142
|
+
src_data_type varchar(1024) NOT NULL,
|
143
|
+
revision int NOT NULL DEFAULT 1,
|
144
|
+
ordinal_position int NOT NULL,
|
145
|
+
PRIMARY KEY(id)
|
146
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
147
|
+
DROP TABLE "product_order";
|
148
|
+
CREATE TABLE "product_order" (
|
149
|
+
"no" int4 NOT NULL,
|
150
|
+
"product_category" int4 NOT NULL,
|
151
|
+
"product_id" int4 NOT NULL,
|
152
|
+
"customer_id" int4 NOT NULL,
|
153
|
+
PRIMARY KEY (no)
|
154
|
+
);
|
155
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'product_order';
|
156
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
157
|
+
('product_order', 'no', 'int4(11)', 1),
|
158
|
+
('product_order', 'product_category', 'int4(11)', 2),
|
159
|
+
('product_order', 'product_id', 'int4(11)', 3),
|
160
|
+
('product_order', 'customer_id', 'int4(11)', 4);
|
161
|
+
EOT
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'with mysqldump_test_table_column_comment.dump' do
|
166
|
+
let(:dump_file_name) { 'mysqldump_test_table_column_comment.dump' }
|
167
|
+
|
168
|
+
it 'should return ddl' do
|
169
|
+
expect(subject).to eq( <<EOT.strip )
|
170
|
+
CREATE TABLE "flydata_ctl_columns"(
|
171
|
+
id integer NOT NULL IDENTITY(1,1),
|
172
|
+
table_name varchar(128) NOT NULL,
|
173
|
+
column_name varchar(128) NOT NULL,
|
174
|
+
src_data_type varchar(1024) NOT NULL,
|
175
|
+
revision int NOT NULL DEFAULT 1,
|
176
|
+
ordinal_position int NOT NULL,
|
177
|
+
PRIMARY KEY(id)
|
178
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
179
|
+
DROP TABLE "test_table_column_comment";
|
180
|
+
CREATE TABLE "test_table_column_comment" (
|
181
|
+
"id" int4 NOT NULL DEFAULT '0',
|
182
|
+
"value" varchar(max),
|
183
|
+
PRIMARY KEY (id)
|
184
|
+
);
|
185
|
+
COMMENT ON COLUMN "test_table_column_comment"."id"
|
186
|
+
IS 'this is primary key';
|
187
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'test_table_column_comment';
|
188
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
189
|
+
('test_table_column_comment', 'id', 'int4(11)', 1),
|
190
|
+
('test_table_column_comment', 'value', 'text', 2);
|
191
|
+
EOT
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'with mysqldump_test_table_enum.dump' do
|
196
|
+
let(:dump_file_name) { 'mysqldump_test_table_enum.dump' }
|
197
|
+
|
198
|
+
it 'should return ddl' do
|
199
|
+
expect(subject).to eq( <<EOT.strip )
|
200
|
+
CREATE TABLE "flydata_ctl_columns"(
|
201
|
+
id integer NOT NULL IDENTITY(1,1),
|
202
|
+
table_name varchar(128) NOT NULL,
|
203
|
+
column_name varchar(128) NOT NULL,
|
204
|
+
src_data_type varchar(1024) NOT NULL,
|
205
|
+
revision int NOT NULL DEFAULT 1,
|
206
|
+
ordinal_position int NOT NULL,
|
207
|
+
PRIMARY KEY(id)
|
208
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
209
|
+
DROP TABLE "test_table_enum";
|
210
|
+
CREATE TABLE "test_table_enum" (
|
211
|
+
"id" int4 NOT NULL,
|
212
|
+
"enum_1" varchar encode bytedict DEFAULT NULL,
|
213
|
+
"enum_2" varchar encode bytedict DEFAULT 'a',
|
214
|
+
"enum_3" varchar encode bytedict NOT NULL,
|
215
|
+
PRIMARY KEY (id)
|
216
|
+
);
|
217
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'test_table_enum';
|
218
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
219
|
+
('test_table_enum', 'id', 'int4(11)', 1),
|
220
|
+
('test_table_enum', 'enum_1', 'enum(\\'apple\\',\\'orange\\',\\'banana\\')', 2),
|
221
|
+
('test_table_enum', 'enum_2', 'enum(\\'a\\',\\'b\\',\\'c\\')', 3),
|
222
|
+
('test_table_enum', 'enum_3', 'enum(\\'e\\',\\'f\\',\\'g\\')', 4);
|
223
|
+
EOT
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context 'with mysqldump_test_table_multi_pk.dump' do
|
228
|
+
let(:dump_file_name) { 'mysqldump_test_table_multi_pk.dump' }
|
229
|
+
|
230
|
+
it 'should return ddl' do
|
231
|
+
expect(subject).to eq( <<EOT.strip )
|
232
|
+
CREATE TABLE "flydata_ctl_columns"(
|
233
|
+
id integer NOT NULL IDENTITY(1,1),
|
234
|
+
table_name varchar(128) NOT NULL,
|
235
|
+
column_name varchar(128) NOT NULL,
|
236
|
+
src_data_type varchar(1024) NOT NULL,
|
237
|
+
revision int NOT NULL DEFAULT 1,
|
238
|
+
ordinal_position int NOT NULL,
|
239
|
+
PRIMARY KEY(id)
|
240
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
241
|
+
DROP TABLE "test_table_multi_pk";
|
242
|
+
CREATE TABLE "test_table_multi_pk" (
|
243
|
+
"id1" int4 NOT NULL DEFAULT '0',
|
244
|
+
"id2" int4 NOT NULL DEFAULT '0',
|
245
|
+
"value" varchar(max),
|
246
|
+
PRIMARY KEY (id1,id2)
|
247
|
+
);
|
248
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'test_table_multi_pk';
|
249
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
250
|
+
('test_table_multi_pk', 'id1', 'int4(11)', 1),
|
251
|
+
('test_table_multi_pk', 'id2', 'int4(11)', 2),
|
252
|
+
('test_table_multi_pk', 'value', 'text', 3);
|
253
|
+
EOT
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context 'with mysqldump_test_table_no_pk.dump' do
|
258
|
+
let(:dump_file_name) { 'mysqldump_test_table_no_pk.dump' }
|
259
|
+
|
260
|
+
it 'should return ddl' do
|
261
|
+
expect{subject}.to raise_error(FlydataCore::TableDefError)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context 'with mysqldump_test_unique_key.dump' do
|
266
|
+
let(:dump_file_name) { 'mysqldump_test_unique_key.dump' }
|
267
|
+
|
268
|
+
it 'should return ddl' do
|
269
|
+
expect(subject).to eq( <<EOT.strip )
|
270
|
+
CREATE TABLE "flydata_ctl_columns"(
|
271
|
+
id integer NOT NULL IDENTITY(1,1),
|
272
|
+
table_name varchar(128) NOT NULL,
|
273
|
+
column_name varchar(128) NOT NULL,
|
274
|
+
src_data_type varchar(1024) NOT NULL,
|
275
|
+
revision int NOT NULL DEFAULT 1,
|
276
|
+
ordinal_position int NOT NULL,
|
277
|
+
PRIMARY KEY(id)
|
278
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
279
|
+
DROP TABLE "sample1";
|
280
|
+
CREATE TABLE "sample1" (
|
281
|
+
"id" int4 NOT NULL,
|
282
|
+
"title" varchar(768) DEFAULT NULL,
|
283
|
+
"name" varchar(max),
|
284
|
+
"num" int4 DEFAULT NULL,
|
285
|
+
PRIMARY KEY (id)
|
286
|
+
);
|
287
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'sample1';
|
288
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
289
|
+
('sample1', 'id', 'int4(11)', 1),
|
290
|
+
('sample1', 'title', 'varchar(768)', 2),
|
291
|
+
('sample1', 'name', 'text', 3),
|
292
|
+
('sample1', 'num', 'int4(11)', 4);
|
293
|
+
EOT
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context 'with mysqldump_test_unique_key2.dump' do
|
298
|
+
let(:dump_file_name) { 'mysqldump_test_unique_key2.dump' }
|
299
|
+
|
300
|
+
it 'should return ddl' do
|
301
|
+
expect(subject).to eq( <<EOT.strip )
|
302
|
+
CREATE TABLE "flydata_ctl_columns"(
|
303
|
+
id integer NOT NULL IDENTITY(1,1),
|
304
|
+
table_name varchar(128) NOT NULL,
|
305
|
+
column_name varchar(128) NOT NULL,
|
306
|
+
src_data_type varchar(1024) NOT NULL,
|
307
|
+
revision int NOT NULL DEFAULT 1,
|
308
|
+
ordinal_position int NOT NULL,
|
309
|
+
PRIMARY KEY(id)
|
310
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
311
|
+
DROP TABLE "sample1";
|
312
|
+
CREATE TABLE "sample1" (
|
313
|
+
"id" int4 NOT NULL,
|
314
|
+
"title" varchar(768) DEFAULT NULL,
|
315
|
+
"name" varchar(max),
|
316
|
+
"num" int4 DEFAULT NULL,
|
317
|
+
PRIMARY KEY (id)
|
318
|
+
);
|
319
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'sample1';
|
320
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
321
|
+
('sample1', 'id', 'int4(11)', 1),
|
322
|
+
('sample1', 'title', 'varchar(768)', 2),
|
323
|
+
('sample1', 'name', 'text', 3),
|
324
|
+
('sample1', 'num', 'int4(11)', 4);
|
325
|
+
EOT
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
context 'with mysqldump_test_unique_key3.dump' do
|
330
|
+
let(:dump_file_name) { 'mysqldump_test_unique_key3.dump' }
|
331
|
+
|
332
|
+
it 'should return ddl' do
|
333
|
+
expect(subject).to eq( <<EOT.strip )
|
334
|
+
CREATE TABLE "flydata_ctl_columns"(
|
335
|
+
id integer NOT NULL IDENTITY(1,1),
|
336
|
+
table_name varchar(128) NOT NULL,
|
337
|
+
column_name varchar(128) NOT NULL,
|
338
|
+
src_data_type varchar(1024) NOT NULL,
|
339
|
+
revision int NOT NULL DEFAULT 1,
|
340
|
+
ordinal_position int NOT NULL,
|
341
|
+
PRIMARY KEY(id)
|
342
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
343
|
+
DROP TABLE "invoice_items";
|
344
|
+
CREATE TABLE "invoice_items" (
|
345
|
+
"id" int4 NOT NULL,
|
346
|
+
"app_id" int4 NOT NULL,
|
347
|
+
"subscription_id" int4 NOT NULL,
|
348
|
+
"overage_id" varchar(765) NOT NULL,
|
349
|
+
"stripe_invoice_item_id" varchar(765) DEFAULT NULL,
|
350
|
+
"stripe_error" varchar(765) DEFAULT NULL,
|
351
|
+
"synced_to_stripe" int2 NOT NULL DEFAULT '0',
|
352
|
+
"description" varchar(max),
|
353
|
+
"item_name" varchar(765) NOT NULL,
|
354
|
+
"item_cost" int4 NOT NULL,
|
355
|
+
"item_count" int4 NOT NULL,
|
356
|
+
"total_cost" int4 NOT NULL,
|
357
|
+
"created_at" timestamp DEFAULT NULL,
|
358
|
+
"updated_at" timestamp DEFAULT NULL,
|
359
|
+
"bill_ahead" int2 DEFAULT '0',
|
360
|
+
"bill_ahead_resolved_at" timestamp DEFAULT NULL,
|
361
|
+
"stripe_invoice_id" varchar(765) DEFAULT NULL,
|
362
|
+
"is_vat" int2 NOT NULL DEFAULT '0',
|
363
|
+
PRIMARY KEY (id)
|
364
|
+
);
|
365
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'invoice_items';
|
366
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
367
|
+
('invoice_items', 'id', 'int4(11)', 1),
|
368
|
+
('invoice_items', 'app_id', 'int4(11)', 2),
|
369
|
+
('invoice_items', 'subscription_id', 'int4(11)', 3),
|
370
|
+
('invoice_items', 'overage_id', 'varchar(765)', 4),
|
371
|
+
('invoice_items', 'stripe_invoice_item_id', 'varchar(765)', 5),
|
372
|
+
('invoice_items', 'stripe_error', 'varchar(765)', 6),
|
373
|
+
('invoice_items', 'synced_to_stripe', 'int1(1)', 7),
|
374
|
+
('invoice_items', 'description', 'text', 8),
|
375
|
+
('invoice_items', 'item_name', 'varchar(765)', 9),
|
376
|
+
('invoice_items', 'item_cost', 'int4(11)', 10),
|
377
|
+
('invoice_items', 'item_count', 'int4(11)', 11),
|
378
|
+
('invoice_items', 'total_cost', 'int4(11)', 12),
|
379
|
+
('invoice_items', 'created_at', 'datetime', 13),
|
380
|
+
('invoice_items', 'updated_at', 'datetime', 14),
|
381
|
+
('invoice_items', 'bill_ahead', 'int1(1)', 15),
|
382
|
+
('invoice_items', 'bill_ahead_resolved_at', 'datetime', 16),
|
383
|
+
('invoice_items', 'stripe_invoice_id', 'varchar(765)', 17),
|
384
|
+
('invoice_items', 'is_vat', 'int1(1)', 18);
|
385
|
+
EOT
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
context 'with mysqldump_test_unsigned.dump' do
|
390
|
+
let(:dump_file_name) { 'mysqldump_test_unsigned.dump' }
|
391
|
+
|
392
|
+
it 'should return ddl' do
|
393
|
+
expect(subject).to eq( <<EOT.strip )
|
394
|
+
CREATE TABLE "flydata_ctl_columns"(
|
395
|
+
id integer NOT NULL IDENTITY(1,1),
|
396
|
+
table_name varchar(128) NOT NULL,
|
397
|
+
column_name varchar(128) NOT NULL,
|
398
|
+
src_data_type varchar(1024) NOT NULL,
|
399
|
+
revision int NOT NULL DEFAULT 1,
|
400
|
+
ordinal_position int NOT NULL,
|
401
|
+
PRIMARY KEY(id)
|
402
|
+
) DISTKEY(table_name) SORTKEY(table_name);
|
403
|
+
DROP TABLE "zerofill_table";
|
404
|
+
CREATE TABLE "zerofill_table" (
|
405
|
+
"id" int4 NOT NULL,
|
406
|
+
"value_int" int8 DEFAULT NULL,
|
407
|
+
"value_float" float4 DEFAULT NULL,
|
408
|
+
"value_dec" numeric(10,2) DEFAULT NULL,
|
409
|
+
"value_double" float8 DEFAULT NULL,
|
410
|
+
"name" varchar(768) DEFAULT NULL,
|
411
|
+
"value_small_int" int4 DEFAULT NULL,
|
412
|
+
PRIMARY KEY (id)
|
413
|
+
);
|
414
|
+
DELETE FROM "flydata_ctl_columns" WHERE table_name = 'zerofill_table';
|
415
|
+
INSERT INTO "flydata_ctl_columns" (table_name, column_name, src_data_type, ordinal_position) VALUES
|
416
|
+
('zerofill_table', 'id', 'int4(11)', 1),
|
417
|
+
('zerofill_table', 'value_int', 'int4(10) unsigned', 2),
|
418
|
+
('zerofill_table', 'value_float', 'float4 unsigned', 3),
|
419
|
+
('zerofill_table', 'value_dec', 'numeric(10,2) unsigned', 4),
|
420
|
+
('zerofill_table', 'value_double', 'float8 unsigned', 5),
|
421
|
+
('zerofill_table', 'name', 'varchar(768)', 6),
|
422
|
+
('zerofill_table', 'value_small_int', 'int2(5) unsigned', 7);
|
423
|
+
EOT
|
424
|
+
end
|
425
|
+
end
|
426
|
+
end
|
427
|
+
end
|
428
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
-- MySQL dump 10.13 Distrib 5.6.19, for osx10.9 (x86_64)
|
2
|
+
--
|
3
|
+
-- Host: localhost Database: sync_test
|
4
|
+
-- ------------------------------------------------------
|
5
|
+
-- Server version 5.6.19-log
|
6
|
+
|
7
|
+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
8
|
+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
9
|
+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
10
|
+
/*!40101 SET NAMES utf8 */;
|
11
|
+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
|
12
|
+
/*!40103 SET TIME_ZONE='+00:00' */;
|
13
|
+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
|
14
|
+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
|
15
|
+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
|
16
|
+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
|
17
|
+
|
18
|
+
--
|
19
|
+
-- Table structure for table `bit_test_def_1`
|
20
|
+
--
|
21
|
+
|
22
|
+
DROP TABLE IF EXISTS `bit_test_def_1`;
|
23
|
+
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
24
|
+
/*!40101 SET character_set_client = utf8 */;
|
25
|
+
CREATE TABLE `bit_test_def_1` (
|
26
|
+
`id` int(11) NOT NULL,
|
27
|
+
`bit_value` bit(1) DEFAULT b'1',
|
28
|
+
`int_value` int(11) DEFAULT x'10',
|
29
|
+
PRIMARY KEY (`id`)
|
30
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
31
|
+
/*!40101 SET character_set_client = @saved_cs_client */;
|
32
|
+
|
33
|
+
--
|
34
|
+
-- Dumping data for table `bit_test_def_1`
|
35
|
+
--
|
36
|
+
|
37
|
+
LOCK TABLES `bit_test_def_1` WRITE;
|
38
|
+
/*!40000 ALTER TABLE `bit_test_def_1` DISABLE KEYS */;
|
39
|
+
/*!40000 ALTER TABLE `bit_test_def_1` ENABLE KEYS */;
|
40
|
+
UNLOCK TABLES;
|
41
|
+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
|
42
|
+
|
43
|
+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
|
44
|
+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
|
45
|
+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
|
46
|
+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
47
|
+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
48
|
+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
49
|
+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
|
50
|
+
|
51
|
+
-- Dump completed on 2014-11-24 13:14:45
|
File without changes
|
File without changes
|
File without changes
|