1717using System . Data ;
1818using System . Globalization ;
1919using System . Linq ;
20- using System . Runtime . InteropServices ;
2120using System . Text ;
2221using System . Text . RegularExpressions ;
2322using Index = DotNetProjects . Migrator . Framework . Index ;
@@ -181,11 +180,11 @@ public override void ChangeColumn(string table, Column column)
181180
182181 var change1 = string . Format ( "{0} TYPE {1}" , QuoteColumnNameIfRequired ( mapper . Name ) , mapper . type ) ;
183182
184- if ( ( oldColumn . Type == DbType . Int16 || oldColumn . Type == DbType . Int32 || oldColumn . Type == DbType . Int64 || oldColumn . Type == DbType . Decimal ) && column . Type == DbType . Boolean )
183+ if ( ( oldColumn . MigratorDbType == MigratorDbType . Int16 || oldColumn . MigratorDbType == MigratorDbType . Int32 || oldColumn . MigratorDbType == MigratorDbType . Int64 || oldColumn . MigratorDbType == MigratorDbType . Decimal ) && column . MigratorDbType == MigratorDbType . Boolean )
185184 {
186185 change1 += string . Format ( " USING CASE {0} WHEN 1 THEN true ELSE false END" , QuoteColumnNameIfRequired ( mapper . Name ) ) ;
187186 }
188- else if ( column . Type == DbType . Boolean )
187+ else if ( column . MigratorDbType == MigratorDbType . Boolean )
189188 {
190189 change1 += string . Format ( " USING CASE {0} WHEN '1' THEN true ELSE false END" , QuoteColumnNameIfRequired ( mapper . Name ) ) ;
191190 }
@@ -286,19 +285,19 @@ public override Column[] GetColumns(string table)
286285 var numericPrecision = reader . IsDBNull ( numericPrecisionOrdinal ) ? null : ( int ? ) reader . GetInt32 ( numericPrecisionOrdinal ) ;
287286 var numericScale = reader . IsDBNull ( numericScaleOrdinal ) ? null : ( int ? ) reader . GetInt32 ( numericScaleOrdinal ) ;
288287
289- DbType dbType = 0 ;
288+ MigratorDbType dbType = 0 ;
290289 int ? precision = null ;
291290 int ? scale = null ;
292291 int ? size = null ;
293292
294293 if ( new [ ] { "timestamptz" , "timestamp with time zone" } . Contains ( dataTypeString ) )
295294 {
296- dbType = DbType . DateTimeOffset ;
295+ dbType = MigratorDbType . DateTimeOffset ;
297296 precision = dateTimePrecision ;
298297 }
299298 else if ( dataTypeString == "double precision" )
300299 {
301- dbType = DbType . Double ;
300+ dbType = MigratorDbType . Double ;
302301 scale = numericScale ;
303302 precision = numericPrecision ;
304303 }
@@ -307,77 +306,81 @@ public override Column[] GetColumns(string table)
307306 // 6 is the maximum in PostgreSQL
308307 if ( dateTimePrecision > 5 )
309308 {
310- dbType = DbType . DateTime2 ;
309+ dbType = MigratorDbType . DateTime2 ;
311310 }
312311 else
313312 {
314- dbType = DbType . DateTime ;
313+ dbType = MigratorDbType . DateTime ;
315314 }
316315
317316 precision = dateTimePrecision ;
318317 }
319318 else if ( dataTypeString == "smallint" )
320319 {
321- dbType = DbType . Int16 ;
320+ dbType = MigratorDbType . Int16 ;
322321 }
323322 else if ( dataTypeString == "integer" )
324323 {
325- dbType = DbType . Int32 ;
324+ dbType = MigratorDbType . Int32 ;
326325 }
327326 else if ( dataTypeString == "bigint" )
328327 {
329- dbType = DbType . Int64 ;
328+ dbType = MigratorDbType . Int64 ;
330329 }
331330 else if ( dataTypeString == "numeric" )
332331 {
333- dbType = DbType . Decimal ;
332+ dbType = MigratorDbType . Decimal ;
334333 precision = numericPrecision ;
335334 scale = numericScale ;
336335 }
337336 else if ( dataTypeString == "real" )
338337 {
339- dbType = DbType . Single ;
338+ dbType = MigratorDbType . Single ;
339+ }
340+ else if ( dataTypeString == "interval" )
341+ {
342+ dbType = MigratorDbType . Interval ;
340343 }
341344 else if ( dataTypeString == "money" )
342345 {
343- dbType = DbType . Currency ;
346+ dbType = MigratorDbType . Currency ;
344347 }
345348 else if ( dataTypeString == "date" )
346349 {
347- dbType = DbType . Date ;
350+ dbType = MigratorDbType . Date ;
348351 }
349352 else if ( dataTypeString == "byte" )
350353 {
351- dbType = DbType . Binary ;
354+ dbType = MigratorDbType . Binary ;
352355 }
353356 else if ( dataTypeString == "uuid" )
354357 {
355- dbType = DbType . Guid ;
358+ dbType = MigratorDbType . Guid ;
356359 }
357360 else if ( dataTypeString == "xml" )
358361 {
359- dbType = DbType . Xml ;
362+ dbType = MigratorDbType . Xml ;
360363 }
361364 else if ( dataTypeString == "time" )
362365 {
363- dbType = DbType . Time ;
366+ dbType = MigratorDbType . Time ;
364367 }
365368 else if ( dataTypeString == "interval" )
366369 {
367370 throw new NotImplementedException ( ) ;
368371 }
369372 else if ( dataTypeString == "boolean" )
370373 {
371- dbType = DbType . Boolean ;
374+ dbType = MigratorDbType . Boolean ;
372375 }
373376 else if ( dataTypeString == "text" || dataTypeString == "character varying" )
374377 {
375- dbType = DbType . String ;
378+ dbType = MigratorDbType . String ;
376379 size = characterMaximumLength ;
377380 }
378381 else if ( dataTypeString == "bytea" )
379382 {
380- dbType = DbType . Binary ;
383+ dbType = MigratorDbType . Binary ;
381384 }
382385 else if ( dataTypeString == "character" || dataTypeString . StartsWith ( "character(" ) )
383386 {
@@ -400,19 +403,19 @@ public override Column[] GetColumns(string table)
400403
401404 if ( defaultValueString != null )
402405 {
403- if ( column . Type == DbType . Int16 || column . Type == DbType . Int32 || column . Type == DbType . Int64 )
406+ if ( column . MigratorDbType == MigratorDbType . Int16 || column . MigratorDbType == MigratorDbType . Int32 || column . MigratorDbType == MigratorDbType . Int64 )
404407 {
405408 column . DefaultValue = long . Parse ( defaultValueString . ToString ( ) ) ;
406409 }
407- else if ( column . Type == DbType . UInt16 || column . Type == DbType . UInt32 || column . Type == DbType . UInt64 )
410+ else if ( column . MigratorDbType == MigratorDbType . UInt16 || column . MigratorDbType == MigratorDbType . UInt32 || column . MigratorDbType == MigratorDbType . UInt64 )
408411 {
409412 column . DefaultValue = ulong . Parse ( defaultValueString . ToString ( ) ) ;
410413 }
411- else if ( column . Type == DbType . Double || column . Type == DbType . Single )
414+ else if ( column . MigratorDbType == MigratorDbType . Double || column . MigratorDbType == MigratorDbType . Single )
412415 {
413416 column . DefaultValue = double . Parse ( defaultValueString . ToString ( ) , CultureInfo . InvariantCulture ) ;
414417 }
415- else if ( column . Type == DbType . Boolean )
418+ else if ( column . MigratorDbType == MigratorDbType . Boolean )
416419 {
417420 var truthy = new [ ] { "TRUE" , "YES" , "'true'" , "on" , "'on'" , "t" , "'t'" } ;
418421 var falsy = new [ ] { "FALSE" , "NO" , "'false'" , "off" , "'off'" , "f" , "'f'" } ;
@@ -430,7 +433,7 @@ public override Column[] GetColumns(string table)
430433 throw new NotImplementedException ( $ "Cannot interpret the given default value in column '{ column . Name } '") ;
431434 }
432435 }
433- else if ( column . Type == DbType . DateTime || column . Type == DbType . DateTime2 )
436+ else if ( column . MigratorDbType == MigratorDbType . DateTime || column . MigratorDbType == MigratorDbType . DateTime2 )
434437 {
435438 if ( defaultValueString . StartsWith ( "'" ) )
436439 {
@@ -453,7 +456,7 @@ public override Column[] GetColumns(string table)
453456 throw new NotImplementedException ( ) ;
454457 }
455458 }
456- else if ( column . Type == DbType . Guid )
459+ else if ( column . MigratorDbType == MigratorDbType . Guid )
457460 {
458461 if ( defaultValueString . StartsWith ( "'" ) )
459462 {
@@ -471,11 +474,11 @@ public override Column[] GetColumns(string table)
471474 throw new NotImplementedException ( ) ;
472475 }
473476 }
474- else if ( column . Type == DbType . Decimal )
477+ else if ( column . MigratorDbType == MigratorDbType . Decimal )
475478 {
476479 column . DefaultValue = decimal . Parse ( defaultValueString , CultureInfo . InvariantCulture ) ;
477480 }
478- else if ( column . Type == DbType . String )
481+ else if ( column . MigratorDbType == MigratorDbType . String )
479482 {
480483 if ( defaultValueString . StartsWith ( "'" ) )
481484 {
@@ -493,7 +496,7 @@ public override Column[] GetColumns(string table)
493496 throw new NotImplementedException ( ) ;
494497 }
495498 }
496- else if ( column . Type == DbType . Binary )
499+ else if ( column . MigratorDbType == MigratorDbType . Binary )
497500 {
498501 if ( defaultValueString . StartsWith ( "'" ) )
499502 {
0 commit comments