@@ -365,10 +365,6 @@ public override Column[] GetColumns(string table)
365365 {
366366 dbType = MigratorDbType . Time ;
367367 }
368- else if ( dataTypeString == "interval" )
369- {
370- throw new NotImplementedException ( ) ;
371- }
372368 else if ( dataTypeString == "boolean" )
373369 {
374370 dbType = MigratorDbType . Boolean ;
@@ -415,6 +411,39 @@ public override Column[] GetColumns(string table)
415411 {
416412 column . DefaultValue = double . Parse ( defaultValueString . ToString ( ) , CultureInfo . InvariantCulture ) ;
417413 }
414+ else if ( column . MigratorDbType == MigratorDbType . Interval )
415+ {
416+ if ( defaultValueString . StartsWith ( "'" ) )
417+ {
418+ var match = stripSingleQuoteRegEx . Match ( defaultValueString ) ;
419+
420+ if ( ! match . Success )
421+ {
422+ throw new Exception ( "Postgre default value for interval: Single quotes around the interval string are expected." ) ;
423+ }
424+
425+ column . DefaultValue = match . Value ;
426+ var splitted = match . Value . Split ( ':' ) ;
427+ if ( splitted . Length != 3 )
428+ {
429+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column '{ column . Name } ' unexpected pattern.") ;
430+ }
431+
432+ var hours = int . Parse ( splitted [ 0 ] , CultureInfo . InvariantCulture ) ;
433+ var minutes = int . Parse ( splitted [ 1 ] , CultureInfo . InvariantCulture ) ;
434+ var splitted2 = splitted [ 2 ] . Split ( '.' ) ;
435+ var seconds = int . Parse ( splitted2 [ 0 ] , CultureInfo . InvariantCulture ) ;
436+ var milliseconds = int . Parse ( splitted2 [ 1 ] , CultureInfo . InvariantCulture ) ;
437+
438+ column . DefaultValue = new TimeSpan ( 0 , hours , minutes , seconds , milliseconds ) ;
439+ }
440+ else
441+ {
442+ // We assume that the value was added using this migrator so we do not interpret things like '2 days 01:02:03' if you
443+ // added such format you will run into this exception.
444+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column '{ column . Name } ' unexpected pattern.") ;
445+ }
446+ }
418447 else if ( column . MigratorDbType == MigratorDbType . Boolean )
419448 {
420449 var truthy = new [ ] { "TRUE" , "YES" , "'true'" , "on" , "'on'" , "t" , "'t'" } ;
@@ -430,7 +459,7 @@ public override Column[] GetColumns(string table)
430459 }
431460 else
432461 {
433- throw new NotImplementedException ( $ "Cannot interpret the given default value in column '{ column . Name } '") ;
462+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column '{ column . Name } '") ;
434463 }
435464 }
436465 else if ( column . MigratorDbType == MigratorDbType . DateTime || column . MigratorDbType == MigratorDbType . DateTime2 )
@@ -441,7 +470,7 @@ public override Column[] GetColumns(string table)
441470
442471 if ( ! match . Success )
443472 {
444- throw new Exception ( "Postgre default value for date time: Single quotes around the date time string are expected. ") ;
473+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } ' ") ;
445474 }
446475
447476 var timeString = match . Value ;
@@ -453,7 +482,7 @@ public override Column[] GetColumns(string table)
453482 }
454483 else
455484 {
456- throw new NotImplementedException ( ) ;
485+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } '" ) ;
457486 }
458487 }
459488 else if ( column . MigratorDbType == MigratorDbType . Guid )
@@ -464,14 +493,14 @@ public override Column[] GetColumns(string table)
464493
465494 if ( ! match . Success )
466495 {
467- throw new Exception ( "Postgre default value for uniqueidentifier: Single quotes around the Guid string are expected. ") ;
496+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } ' ") ;
468497 }
469498
470499 column . DefaultValue = Guid . Parse ( match . Value ) ;
471500 }
472501 else
473502 {
474- throw new NotImplementedException ( ) ;
503+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } '" ) ;
475504 }
476505 }
477506 else if ( column . MigratorDbType == MigratorDbType . Decimal )
@@ -504,7 +533,7 @@ public override Column[] GetColumns(string table)
504533
505534 if ( ! match . Success )
506535 {
507- throw new Exception ( "Postgre default value for bytea: Single quotes around the bytea string are expected. ") ;
536+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } ' ") ;
508537 }
509538
510539 var singleQuoteString = match . Value ;
@@ -524,7 +553,7 @@ public override Column[] GetColumns(string table)
524553 }
525554 else
526555 {
527- throw new NotImplementedException ( ) ;
556+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } '" ) ;
528557 }
529558 }
530559 else
0 commit comments