@@ -586,6 +586,22 @@ private function normalizeIdentifier($name)
586
586
return $ identifier ->isQuoted () ? $ identifier : new Identifier (strtoupper ($ name ));
587
587
}
588
588
589
+ /**
590
+ * Adds suffix to identifier,
591
+ *
592
+ * if the new string exceeds max identifier length,
593
+ * keeps $suffix, cuts from $identifier as much as the part exceeding.
594
+ */
595
+ private function addSuffix (string $ identifier , string $ suffix ) : string
596
+ {
597
+ $ maxPossibleLengthWithoutSuffix = $ this ->getMaxIdentifierLength () - strlen ($ suffix );
598
+ if (strlen ($ identifier ) > $ maxPossibleLengthWithoutSuffix ) {
599
+ $ identifier = substr ($ identifier , 0 , $ maxPossibleLengthWithoutSuffix );
600
+ }
601
+
602
+ return $ identifier . $ suffix ;
603
+ }
604
+
589
605
/**
590
606
* Returns the autoincrement primary key identifier name for the given table identifier.
591
607
*
@@ -598,7 +614,7 @@ private function normalizeIdentifier($name)
598
614
*/
599
615
private function getAutoincrementIdentifierName (Identifier $ table )
600
616
{
601
- $ identifierName = $ table ->getName () . '_AI_PK ' ;
617
+ $ identifierName = $ this -> addSuffix ( $ table ->getName (), '_AI_PK ' ) ;
602
618
603
619
return $ table ->isQuoted ()
604
620
? $ this ->quoteSingleIdentifier ($ identifierName )
@@ -966,7 +982,7 @@ public function getIdentitySequenceName($tableName, $columnName)
966
982
$ table = new Identifier ($ tableName );
967
983
968
984
// No usage of column name to preserve BC compatibility with <2.5
969
- $ identitySequenceName = $ table ->getName () . '_SEQ ' ;
985
+ $ identitySequenceName = $ this -> addSuffix ( $ table ->getName (), '_SEQ ' ) ;
970
986
971
987
if ($ table ->isQuoted ()) {
972
988
$ identitySequenceName = '" ' . $ identitySequenceName . '" ' ;
0 commit comments