@@ -526,6 +526,7 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment)
526
526
protected function _getCreateTableSQL ($ tableName , array $ columns , array $ options = [])
527
527
{
528
528
$ engine = !empty ($ options ['engine ' ]) ? $ options ['engine ' ] : 'ReplacingMergeTree ' ;
529
+ $ engineOptions = '' ;
529
530
530
531
if (isset ($ options ['uniqueConstraints ' ]) && ! empty ($ options ['uniqueConstraints ' ])) {
531
532
throw DBALException::notSupported ('uniqueConstraints ' );
@@ -535,11 +536,10 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
535
536
throw DBALException::notSupported ('uniqueConstraints ' );
536
537
}
537
538
538
-
539
539
/**
540
540
* MergeTree* specific section
541
541
*/
542
- if ( in_array ($ engine , ['MergeTree ' , 'CollapsingMergeTree ' , 'SummingMergeTree ' , 'AggregatingMergeTree ' , 'ReplacingMergeTree ' ]) ) {
542
+ if ( in_array ($ engine , ['MergeTree ' , 'CollapsingMergeTree ' , 'SummingMergeTree ' , 'AggregatingMergeTree ' , 'ReplacingMergeTree ' ], true ) ) {
543
543
$ indexGranularity = !empty ($ options ['indexGranularity ' ]) ? $ options ['indexGranularity ' ] : 8192 ;
544
544
545
545
/**
@@ -572,9 +572,7 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
572
572
$ dateColumnParams ['default ' ] =
573
573
$ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof IntegerType ||
574
574
$ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof SmallIntType ||
575
- $ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof BigIntType ||
576
- $ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof FloatType ||
577
- $ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof DecimalType ?
575
+ $ columns [$ options ['eventDateProviderColumn ' ]]['type ' ] instanceof FloatType ?
578
576
('toDate(toDateTime( ' . $ options ['eventDateProviderColumn ' ] . ')) ' ) :
579
577
('toDate( ' . $ options ['eventDateProviderColumn ' ] . ') ' );
580
578
} else {
@@ -613,18 +611,12 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
613
611
throw new \Exception ('You need specify PrimaryKey for MergeTree* tables ' );
614
612
}
615
613
616
- }
617
-
618
- $ columnListSql = $ this ->getColumnDeclarationListSQL ($ columns );
619
- $ query = 'CREATE TABLE ' . $ tableName . ' ( ' . $ columnListSql . ') ENGINE = ' . $ engine ;
620
-
621
- if ( in_array ($ engine , ['MergeTree ' , 'CollapsingMergeTree ' , 'SummingMergeTree ' , 'AggregatingMergeTree ' , 'ReplacingMergeTree ' ]) ) {
622
- $ query .= '( ' . $ eventDateColumnName . ', ( ' . implode (', ' , array_unique (array_values ($ options ['primary ' ]))) . '), ' . $ indexGranularity ;
614
+ $ engineOptions = '( ' . $ eventDateColumnName . ', ( ' . implode (', ' , array_unique (array_values ($ options ['primary ' ]))) . '), ' . $ indexGranularity ;
623
615
624
616
/**
625
617
* any specific MergeTree* table parameters
626
618
*/
627
- if ('ReplacingMergeTree ' == $ engine ) {
619
+ if ('ReplacingMergeTree ' === $ engine ) {
628
620
if (! empty ($ options ['versionColumn ' ])) {
629
621
if (! isset ($ columns [$ options ['versionColumn ' ]]) ) {
630
622
throw new \Exception ('If you specify `versionColumn` for ReplacingMergeTree table -- you must add this column manually (any of UInt*, Date or DateTime types) ' );
@@ -640,13 +632,16 @@ protected function _getCreateTableSQL($tableName, array $columns, array $options
640
632
throw new \Exception ('For ReplacingMergeTree tables `versionColumn` must be any of UInt* family, or Date, or DateTime types. ' . get_class ($ columns [$ options ['versionColumn ' ]]['type ' ]) . ' given. ' );
641
633
}
642
634
643
- $ query .= ', ' . $ columns [$ options ['versionColumn ' ]]['name ' ];
635
+ $ engineOptions .= ', ' . $ columns [$ options ['versionColumn ' ]]['name ' ];
644
636
}
645
637
}
646
638
647
- $ query .= ') ' ;
639
+ $ engineOptions .= ') ' ;
648
640
}
649
641
642
+ $ columnListSql = $ this ->getColumnDeclarationListSQL ($ columns );
643
+ $ query = 'CREATE TABLE ' . $ tableName . ' ( ' . $ columnListSql . ') ENGINE = ' . $ engine . $ engineOptions ;
644
+
650
645
$ sql [] = $ query ;
651
646
652
647
return $ sql ;
@@ -940,7 +935,12 @@ public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration)
940
935
*/
941
936
public function getDateTimeTzTypeDeclarationSQL (array $ fieldDeclaration )
942
937
{
943
- throw DBALException::notSupported (__METHOD__ );
938
+ return 'DateTime ' ;
939
+ }
940
+
941
+ public function getTimeTypeDeclarationSQL (array $ fieldDeclaration )
942
+ {
943
+ return 'String ' ;
944
944
}
945
945
946
946
/**
@@ -1092,7 +1092,7 @@ public function getDefaultValueDeclarationSQL($field)
1092
1092
1093
1093
$ default = " DEFAULT ' " . $ field ['default ' ] . "' " ;
1094
1094
if ( isset ($ field ['type ' ]) ) {
1095
- if (in_array ((string )$ field ['type ' ], ['Integer ' , 'BigInt ' , 'SmallInt ' , ' Float ' ] )) {
1095
+ if (in_array ((string )$ field ['type ' ], ['Integer ' , 'SmallInt ' , 'Float ' ]) || ( ' BigInt ' === $ field [ ' type ' ] && \ PDO :: PARAM_INT === Type:: getType ( ' BigInt ' )-> getBindingType () )) {
1096
1096
$ default = ' DEFAULT ' . $ field ['default ' ];
1097
1097
} else if (in_array ((string )$ field ['type ' ], ['DateTime ' ]) && $ field ['default ' ] == $ this ->getCurrentTimestampSQL ()) {
1098
1098
$ default = ' DEFAULT ' . $ this ->getCurrentTimestampSQL ();
0 commit comments