@@ -16,11 +16,12 @@ func TestParseDDL(t *testing.T) {
16
16
columns []migrator.ColumnType
17
17
}{
18
18
{"with_fk" , []string {
19
- "CREATE TABLE `notes` (`id` integer NOT NULL,`text` varchar(500) DEFAULT \" hello\" ,`age` integer DEFAULT 18,`user_id` integer,PRIMARY KEY (`id`),CONSTRAINT `fk_users_notes` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`))" ,
19
+ "CREATE TABLE `notes` (" +
20
+ "`id` integer NOT NULL,`text` varchar(500) DEFAULT \" hello\" ,`age` integer DEFAULT 18,`user_id` integer,PRIMARY KEY (`id`),CONSTRAINT `fk_users_notes` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`))" ,
20
21
"CREATE UNIQUE INDEX `idx_profiles_refer` ON `profiles`(`text`)" ,
21
22
}, 6 , []migrator.ColumnType {
22
23
{NameValue : sql.NullString {String : "id" , Valid : true }, DataTypeValue : sql.NullString {String : "integer" , Valid : true }, ColumnTypeValue : sql.NullString {String : "integer" , Valid : true }, PrimaryKeyValue : sql.NullBool {Bool : true , Valid : true }, NullableValue : sql.NullBool {Valid : true }, UniqueValue : sql.NullBool {Valid : true }, DefaultValueValue : sql.NullString {Valid : false }},
23
- {NameValue : sql.NullString {String : "text" , Valid : true }, DataTypeValue : sql.NullString {String : "varchar" , Valid : true }, LengthValue : sql.NullInt64 {Int64 : 500 , Valid : true }, ColumnTypeValue : sql.NullString {String : "varchar(500)" , Valid : true }, DefaultValueValue : sql.NullString {String : "hello" , Valid : true }, NullableValue : sql.NullBool {Bool : true , Valid : true }, UniqueValue : sql.NullBool {Bool : true , Valid : true }, PrimaryKeyValue : sql.NullBool {Valid : true }},
24
+ {NameValue : sql.NullString {String : "text" , Valid : true }, DataTypeValue : sql.NullString {String : "varchar" , Valid : true }, LengthValue : sql.NullInt64 {Int64 : 500 , Valid : true }, ColumnTypeValue : sql.NullString {String : "varchar(500)" , Valid : true }, DefaultValueValue : sql.NullString {String : "hello" , Valid : true }, NullableValue : sql.NullBool {Bool : true , Valid : true }, UniqueValue : sql.NullBool {Bool : false , Valid : true }, PrimaryKeyValue : sql.NullBool {Valid : true }},
24
25
{NameValue : sql.NullString {String : "age" , Valid : true }, DataTypeValue : sql.NullString {String : "integer" , Valid : true }, ColumnTypeValue : sql.NullString {String : "integer" , Valid : true }, DefaultValueValue : sql.NullString {String : "18" , Valid : true }, NullableValue : sql.NullBool {Bool : true , Valid : true }, UniqueValue : sql.NullBool {Valid : true }, PrimaryKeyValue : sql.NullBool {Valid : true }},
25
26
{NameValue : sql.NullString {String : "user_id" , Valid : true }, DataTypeValue : sql.NullString {String : "integer" , Valid : true }, ColumnTypeValue : sql.NullString {String : "integer" , Valid : true }, DefaultValueValue : sql.NullString {Valid : false }, NullableValue : sql.NullBool {Bool : true , Valid : true }, UniqueValue : sql.NullBool {Valid : true }, PrimaryKeyValue : sql.NullBool {Valid : true }},
26
27
},
@@ -56,34 +57,78 @@ func TestParseDDL(t *testing.T) {
56
57
ColumnTypeValue : sql.NullString {String : "int" , Valid : true },
57
58
NullableValue : sql.NullBool {Bool : false , Valid : true },
58
59
DefaultValueValue : sql.NullString {Valid : false },
59
- UniqueValue : sql.NullBool {Bool : true , Valid : true },
60
+ UniqueValue : sql.NullBool {Bool : false , Valid : true },
60
61
PrimaryKeyValue : sql.NullBool {Valid : true },
61
62
},
62
63
},
63
- },
64
- {
64
+ }, {
65
65
"unique index" ,
66
66
[]string {
67
67
"CREATE TABLE `test-b` (`field` integer NOT NULL)" ,
68
68
"CREATE UNIQUE INDEX `idx_uq` ON `test-b`(`field`) WHERE field = 0" ,
69
69
},
70
70
1 ,
71
+ []migrator.ColumnType {{
72
+ NameValue : sql.NullString {String : "field" , Valid : true },
73
+ DataTypeValue : sql.NullString {String : "integer" , Valid : true },
74
+ ColumnTypeValue : sql.NullString {String : "integer" , Valid : true },
75
+ PrimaryKeyValue : sql.NullBool {Bool : false , Valid : true },
76
+ UniqueValue : sql.NullBool {Bool : false , Valid : true },
77
+ NullableValue : sql.NullBool {Bool : false , Valid : true },
78
+ }},
79
+ }, {
80
+ "normal index" ,
81
+ []string {
82
+ "CREATE TABLE `test-c` (`field` integer NOT NULL)" ,
83
+ "CREATE INDEX `idx_uq` ON `test-c`(`field`)" ,
84
+ },
85
+ 1 ,
86
+ []migrator.ColumnType {{
87
+ NameValue : sql.NullString {String : "field" , Valid : true },
88
+ DataTypeValue : sql.NullString {String : "integer" , Valid : true },
89
+ ColumnTypeValue : sql.NullString {String : "integer" , Valid : true },
90
+ PrimaryKeyValue : sql.NullBool {Bool : false , Valid : true },
91
+ UniqueValue : sql.NullBool {Bool : false , Valid : true },
92
+ NullableValue : sql.NullBool {Bool : false , Valid : true },
93
+ }},
94
+ }, {
95
+ "unique constraint" ,
96
+ []string {
97
+ "CREATE TABLE `unique_struct` (`name` text,CONSTRAINT `uni_unique_struct_name` UNIQUE (`name`))" ,
98
+ },
99
+ 2 ,
100
+ []migrator.ColumnType {{
101
+ NameValue : sql.NullString {String : "name" , Valid : true },
102
+ DataTypeValue : sql.NullString {String : "text" , Valid : true },
103
+ ColumnTypeValue : sql.NullString {String : "text" , Valid : true },
104
+ PrimaryKeyValue : sql.NullBool {Bool : false , Valid : true },
105
+ UniqueValue : sql.NullBool {Bool : true , Valid : true },
106
+ NullableValue : sql.NullBool {Bool : true , Valid : true },
107
+ }},
108
+ },
109
+ {
110
+ "non-unique index" ,
111
+ []string {
112
+ "CREATE TABLE `test-c` (`field` integer NOT NULL)" ,
113
+ "CREATE INDEX `idx_uq` ON `test-b`(`field`) WHERE field = 0" ,
114
+ },
115
+ 1 ,
71
116
[]migrator.ColumnType {
72
117
{
73
118
NameValue : sql.NullString {String : "field" , Valid : true },
74
119
DataTypeValue : sql.NullString {String : "integer" , Valid : true },
75
120
ColumnTypeValue : sql.NullString {String : "integer" , Valid : true },
76
121
PrimaryKeyValue : sql.NullBool {Bool : false , Valid : true },
77
- UniqueValue : sql.NullBool {Bool : true , Valid : true },
122
+ UniqueValue : sql.NullBool {Bool : false , Valid : true },
78
123
NullableValue : sql.NullBool {Bool : false , Valid : true },
79
124
},
80
125
},
81
126
},
82
127
{
83
- "non-unique index" ,
128
+ "index with \n from .schema sqlite " ,
84
129
[]string {
85
- "CREATE TABLE `test-c ` (`field` integer NOT NULL)" ,
86
- "CREATE INDEX `idx_uq` ON `test-b`(`field`) WHERE field = 0" ,
130
+ "CREATE TABLE `test-d ` (`field` integer NOT NULL)" ,
131
+ "CREATE INDEX `idx_uq`\n ON `test-b`(`field`) WHERE field = 0" ,
87
132
},
88
133
1 ,
89
134
[]migrator.ColumnType {
0 commit comments