@@ -365,10 +365,6 @@ public override Column[] GetColumns(string table)
365
365
{
366
366
dbType = MigratorDbType . Time ;
367
367
}
368
- else if ( dataTypeString == "interval" )
369
- {
370
- throw new NotImplementedException ( ) ;
371
- }
372
368
else if ( dataTypeString == "boolean" )
373
369
{
374
370
dbType = MigratorDbType . Boolean ;
@@ -415,6 +411,39 @@ public override Column[] GetColumns(string table)
415
411
{
416
412
column . DefaultValue = double . Parse ( defaultValueString . ToString ( ) , CultureInfo . InvariantCulture ) ;
417
413
}
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
+ }
418
447
else if ( column . MigratorDbType == MigratorDbType . Boolean )
419
448
{
420
449
var truthy = new [ ] { "TRUE" , "YES" , "'true'" , "on" , "'on'" , "t" , "'t'" } ;
@@ -430,7 +459,7 @@ public override Column[] GetColumns(string table)
430
459
}
431
460
else
432
461
{
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 } '") ;
434
463
}
435
464
}
436
465
else if ( column . MigratorDbType == MigratorDbType . DateTime || column . MigratorDbType == MigratorDbType . DateTime2 )
@@ -441,7 +470,7 @@ public override Column[] GetColumns(string table)
441
470
442
471
if ( ! match . Success )
443
472
{
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 } ' ") ;
445
474
}
446
475
447
476
var timeString = match . Value ;
@@ -453,7 +482,7 @@ public override Column[] GetColumns(string table)
453
482
}
454
483
else
455
484
{
456
- throw new NotImplementedException ( ) ;
485
+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } '" ) ;
457
486
}
458
487
}
459
488
else if ( column . MigratorDbType == MigratorDbType . Guid )
@@ -464,14 +493,14 @@ public override Column[] GetColumns(string table)
464
493
465
494
if ( ! match . Success )
466
495
{
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 } ' ") ;
468
497
}
469
498
470
499
column . DefaultValue = Guid . Parse ( match . Value ) ;
471
500
}
472
501
else
473
502
{
474
- throw new NotImplementedException ( ) ;
503
+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } '" ) ;
475
504
}
476
505
}
477
506
else if ( column . MigratorDbType == MigratorDbType . Decimal )
@@ -504,7 +533,7 @@ public override Column[] GetColumns(string table)
504
533
505
534
if ( ! match . Success )
506
535
{
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 } ' ") ;
508
537
}
509
538
510
539
var singleQuoteString = match . Value ;
@@ -524,7 +553,7 @@ public override Column[] GetColumns(string table)
524
553
}
525
554
else
526
555
{
527
- throw new NotImplementedException ( ) ;
556
+ throw new NotImplementedException ( $ "Cannot interpret { defaultValueString } in column ' { column . Name } '" ) ;
528
557
}
529
558
}
530
559
else
0 commit comments