@@ -113,7 +113,7 @@ impl<'until_build, 'post_build> CreateColumn<'post_build>
113
113
"\" {}\" {} " ,
114
114
d. name,
115
115
match d. data_type {
116
- DbType :: VarBinary => "BLOB" ,
116
+ DbType :: Binary | DbType :: Uuid => "BLOB" ,
117
117
DbType :: VarChar
118
118
| DbType :: Date
119
119
| DbType :: DateTime
@@ -126,6 +126,9 @@ impl<'until_build, 'post_build> CreateColumn<'post_build>
126
126
| DbType :: Int64
127
127
| DbType :: Boolean => "INTEGER" ,
128
128
DbType :: Float | DbType :: Double => "REAL" ,
129
+ DbType :: BitVec | DbType :: MacAddress | DbType :: IpNetwork => unreachable!(
130
+ "BitVec, MacAddress and IpNetwork are not available for sqlite"
131
+ ) ,
129
132
}
130
133
)
131
134
. unwrap ( ) ;
@@ -203,7 +206,12 @@ impl<'until_build, 'post_build> CreateColumn<'post_build>
203
206
204
207
if let Some ( a) = a_opt {
205
208
if let Annotation :: MaxLength ( max_length) = a. annotation {
206
- write ! ( s, "VARCHAR({max_length}) " ) . unwrap ( ) ;
209
+ // utf8mb4 is 4 bytes wide, so that's the maximum for varchar
210
+ if * max_length < 2i32 . pow ( 14 ) - 1 {
211
+ write ! ( s, "VARCHAR({max_length}) " ) . unwrap ( ) ;
212
+ } else {
213
+ write ! ( s, "LONGTEXT " ) . unwrap ( ) ;
214
+ }
207
215
} else {
208
216
return Err ( Error :: SQLBuildError ( String :: from (
209
217
"VARCHAR must have a max_length annotation" ,
@@ -215,26 +223,7 @@ impl<'until_build, 'post_build> CreateColumn<'post_build>
215
223
) ) ) ;
216
224
}
217
225
}
218
- DbType :: VarBinary => {
219
- let a_opt = d
220
- . annotations
221
- . iter ( )
222
- . find ( |x| x. annotation . eq_shallow ( & Annotation :: MaxLength ( 0 ) ) ) ;
223
-
224
- if let Some ( a) = a_opt {
225
- if let Annotation :: MaxLength ( max_length) = a. annotation {
226
- write ! ( s, "VARBINARY({max_length}) " ) . unwrap ( ) ;
227
- } else {
228
- return Err ( Error :: SQLBuildError (
229
- "VARBINARY must have a max_length annotation" . to_string ( ) ,
230
- ) ) ;
231
- }
232
- } else {
233
- return Err ( Error :: SQLBuildError (
234
- "VARBINARY must have a max_length annotation" . to_string ( ) ,
235
- ) ) ;
236
- }
237
- }
226
+ DbType :: Binary | DbType :: Uuid => write ! ( s, "LONGBLOB " ) . unwrap ( ) ,
238
227
DbType :: Int8 => write ! ( s, "TINYINT(255) " ) . unwrap ( ) ,
239
228
DbType :: Int16 => write ! ( s, "SMALLINT(255) " ) . unwrap ( ) ,
240
229
DbType :: Int32 => write ! ( s, "INT(255) " ) . unwrap ( ) ,
@@ -275,6 +264,9 @@ impl<'until_build, 'post_build> CreateColumn<'post_build>
275
264
) ) ;
276
265
}
277
266
}
267
+ DbType :: BitVec | DbType :: IpNetwork | DbType :: MacAddress => {
268
+ unreachable ! ( "BitVec, MacAddress and IpNetwork are not available for mysql" )
269
+ }
278
270
} ;
279
271
280
272
for ( idx, x) in d. annotations . iter ( ) . enumerate ( ) {
@@ -403,7 +395,11 @@ impl<'until_build, 'post_build> CreateColumn<'post_build>
403
395
) ) ;
404
396
}
405
397
}
406
- DbType :: VarBinary => write ! ( s, "bytea " ) . unwrap ( ) ,
398
+ DbType :: Uuid => write ! ( s, "uuid " ) . unwrap ( ) ,
399
+ DbType :: MacAddress => write ! ( s, "macaddr " ) . unwrap ( ) ,
400
+ DbType :: IpNetwork => write ! ( s, "inet " ) . unwrap ( ) ,
401
+ DbType :: BitVec => write ! ( s, "varbit " ) . unwrap ( ) ,
402
+ DbType :: Binary => write ! ( s, "bytea " ) . unwrap ( ) ,
407
403
DbType :: Int8 => write ! ( s, "smallint " ) . unwrap ( ) ,
408
404
DbType :: Int16 => {
409
405
if d. annotations
0 commit comments