@@ -6,8 +6,6 @@ use rorm_declaration::imr::DefaultValue;
66use crate :: create_trigger:: trigger_annotation_to_trigger_postgres;
77#[ cfg( feature = "sqlite" ) ]
88use crate :: create_trigger:: trigger_annotation_to_trigger_sqlite;
9- #[ cfg( feature = "mysql" ) ]
10- use crate :: db_specific:: mysql;
119#[ cfg( feature = "postgres" ) ]
1210use crate :: db_specific:: postgres;
1311#[ cfg( feature = "sqlite" ) ]
@@ -50,19 +48,6 @@ pub struct CreateColumnSQLiteData<'until_build, 'post_build> {
5048 pub ( crate ) lookup : Option < & ' until_build mut Vec < Value < ' post_build > > > ,
5149}
5250
53- /**
54- Representation of the data of the creation of a column for the mysql dialect
55- */
56- #[ derive( Debug ) ]
57- #[ cfg( feature = "mysql" ) ]
58- pub struct CreateColumnMySQLData < ' until_build , ' post_build > {
59- pub ( crate ) name : & ' until_build str ,
60- pub ( crate ) data_type : DbType ,
61- pub ( crate ) annotations : Vec < SQLAnnotation < ' post_build > > ,
62- pub ( crate ) statements : Option < & ' until_build mut Vec < ( String , Vec < Value < ' post_build > > ) > > ,
63- pub ( crate ) lookup : Option < & ' until_build mut Vec < Value < ' post_build > > > ,
64- }
65-
6651/**
6752Representation of the data of the creation of a column for the mysql dialect
6853 */
@@ -90,11 +75,6 @@ pub enum CreateColumnImpl<'until_build, 'post_build> {
9075 #[ cfg( feature = "sqlite" ) ]
9176 SQLite ( CreateColumnSQLiteData < ' until_build , ' post_build > ) ,
9277 /**
93- MySQL representation of the create column operation.
94- */
95- #[ cfg( feature = "mysql" ) ]
96- MySQL ( CreateColumnMySQLData < ' until_build , ' post_build > ) ,
97- /**
9878 Postgres representation of the create column operation.
9979 */
10080 #[ cfg( feature = "postgres" ) ]
@@ -191,147 +171,6 @@ impl<'post_build> CreateColumn<'post_build> for CreateColumnImpl<'_, 'post_build
191171
192172 Ok ( ( ) )
193173 }
194- #[ cfg( feature = "mysql" ) ]
195- CreateColumnImpl :: MySQL ( mut d) => {
196- write ! ( s, "`{}` " , d. name) . unwrap ( ) ;
197-
198- match d. data_type {
199- DbType :: VarChar => {
200- let a_opt = d
201- . annotations
202- . iter ( )
203- . find ( |x| x. annotation . eq_shallow ( & Annotation :: MaxLength ( 0 ) ) ) ;
204-
205- if let Some ( a) = a_opt {
206- if let Annotation :: MaxLength ( max_length) = a. annotation {
207- // utf8mb4 is 4 bytes wide, so that's the maximum for varchar
208- if * max_length < 2i32 . pow ( 14 ) - 1 {
209- write ! ( s, "VARCHAR({max_length}) " ) . unwrap ( ) ;
210- } else {
211- write ! ( s, "LONGTEXT " ) . unwrap ( ) ;
212- }
213- } else {
214- return Err ( Error :: SQLBuildError ( String :: from (
215- "VARCHAR must have a max_length annotation" ,
216- ) ) ) ;
217- }
218- } else {
219- return Err ( Error :: SQLBuildError ( String :: from (
220- "VARCHAR must have a max_length annotation" ,
221- ) ) ) ;
222- }
223- }
224- DbType :: Binary | DbType :: Uuid => write ! ( s, "LONGBLOB " ) . unwrap ( ) ,
225- DbType :: Int8 => write ! ( s, "TINYINT(255) " ) . unwrap ( ) ,
226- DbType :: Int16 => write ! ( s, "SMALLINT(255) " ) . unwrap ( ) ,
227- DbType :: Int32 => write ! ( s, "INT(255) " ) . unwrap ( ) ,
228- DbType :: Int64 => write ! ( s, "BIGINT(255) " ) . unwrap ( ) ,
229- DbType :: Float => write ! ( s, "FLOAT(24) " ) . unwrap ( ) ,
230- DbType :: Double => write ! ( s, "DOUBLE(53) " ) . unwrap ( ) ,
231- DbType :: Boolean => write ! ( s, "BOOL " ) . unwrap ( ) ,
232- DbType :: Date => write ! ( s, "DATE " ) . unwrap ( ) ,
233- DbType :: DateTime => write ! ( s, "DATETIME " ) . unwrap ( ) ,
234- DbType :: Timestamp => write ! ( s, "TIMESTAMP " ) . unwrap ( ) ,
235- DbType :: Time => write ! ( s, "TIME " ) . unwrap ( ) ,
236- DbType :: Choices => {
237- let a_opt = d. annotations . iter ( ) . find ( |x| {
238- x. annotation
239- . eq_shallow ( & Annotation :: Choices ( Default :: default ( ) ) )
240- } ) ;
241-
242- if let Some ( a) = a_opt {
243- if let Annotation :: Choices ( values) = a. annotation {
244- write ! (
245- s,
246- "ENUM({}) " ,
247- values
248- . iter( )
249- . map( |x| mysql:: fmt( x) )
250- . collect:: <Vec <String >>( )
251- . join( ", " )
252- )
253- . unwrap ( ) ;
254- } else {
255- return Err ( Error :: SQLBuildError (
256- "VARCHAR must have a MaxLength annotation" . to_string ( ) ,
257- ) ) ;
258- }
259- } else {
260- return Err ( Error :: SQLBuildError (
261- "VARCHAR must have a MaxLength annotation" . to_string ( ) ,
262- ) ) ;
263- }
264- }
265- DbType :: BitVec | DbType :: IpNetwork | DbType :: MacAddress => {
266- unreachable ! ( "BitVec, MacAddress and IpNetwork are not available for mysql" )
267- }
268- } ;
269-
270- for ( idx, x) in d. annotations . iter ( ) . enumerate ( ) {
271- match & x. annotation {
272- Annotation :: AutoIncrement => write ! ( s, "AUTO_INCREMENT" ) . unwrap ( ) ,
273- Annotation :: AutoCreateTime => {
274- write ! (
275- s,
276- "DEFAULT {}" ,
277- match d. data_type {
278- DbType :: Date => "CURRENT_DATE" ,
279- DbType :: DateTime => "CURRENT_TIMESTAMP" ,
280- DbType :: Timestamp => "CURRENT_TIMESTAMP" ,
281- DbType :: Time => "CURRENT_TIME" ,
282- _ => "" ,
283- }
284- )
285- . unwrap ( ) ;
286- }
287- Annotation :: AutoUpdateTime => write ! (
288- s,
289- "ON UPDATE {}" ,
290- match d. data_type {
291- DbType :: Date => "CURRENT_DATE" ,
292- DbType :: DateTime => "CURRENT_TIMESTAMP" ,
293- DbType :: Timestamp => "CURRENT_TIMESTAMP" ,
294- DbType :: Time => "CURRENT_TIME" ,
295- _ => "" ,
296- }
297- )
298- . unwrap ( ) ,
299- Annotation :: DefaultValue ( v) => match v {
300- DefaultValue :: String ( dv) => {
301- if let Some ( l) = & mut d. lookup {
302- l. push ( Value :: String ( dv) )
303- }
304- write ! ( s, "DEFAULT ?" ) . unwrap ( ) ;
305- }
306- DefaultValue :: Integer ( i) => write ! ( s, "DEFAULT {i}" ) . unwrap ( ) ,
307- DefaultValue :: Float ( f) => write ! ( s, "DEFAULT {f}" ) . unwrap ( ) ,
308- DefaultValue :: Boolean ( b) => {
309- if * b {
310- write ! ( s, "DEFAULT 1" ) . unwrap ( ) ;
311- } else {
312- write ! ( s, "DEFAULT 0" ) . unwrap ( ) ;
313- }
314- }
315- } ,
316- Annotation :: NotNull => write ! ( s, "NOT NULL" ) . unwrap ( ) ,
317- Annotation :: PrimaryKey => write ! ( s, "PRIMARY KEY" ) . unwrap ( ) ,
318- Annotation :: Unique => write ! ( s, "UNIQUE" ) . unwrap ( ) ,
319- Annotation :: ForeignKey ( fk) => write ! (
320- s,
321- "REFERENCES `{}`(`{}`) ON DELETE {} ON UPDATE {}" ,
322- fk. table_name, fk. column_name, fk. on_delete, fk. on_update
323- )
324- . unwrap ( ) ,
325- _ => { }
326- }
327-
328- if idx != d. annotations . len ( ) - 1 {
329- write ! ( s, " " ) . unwrap ( ) ;
330- }
331- }
332-
333- Ok ( ( ) )
334- }
335174 #[ cfg( feature = "postgres" ) ]
336175 CreateColumnImpl :: Postgres ( mut d) => {
337176 write ! ( s, "\" {}\" " , d. name) . unwrap ( ) ;
0 commit comments