3131use Doctrine \DBAL \Exception ;
3232use Doctrine \DBAL \Platforms \MySQLPlatform ;
3333use Doctrine \DBAL \Schema \AbstractAsset ;
34- use Doctrine \DBAL \Schema \Comparator ;
3534use Doctrine \DBAL \Schema \Schema ;
3635use Doctrine \DBAL \Schema \SchemaDiff ;
3736use Doctrine \DBAL \Types \StringType ;
@@ -75,7 +74,7 @@ public function generateChangeScript(Schema $targetSchema) {
7574 $ schemaDiff = $ this ->getDiff ($ targetSchema , $ this ->connection );
7675
7776 $ script = '' ;
78- $ sqls = $ schemaDiff -> toSql ( $ this ->connection ->getDatabasePlatform ());
77+ $ sqls = $ this ->connection ->getDatabasePlatform ()-> getAlterSchemaSQL ( $ schemaDiff );
7978 foreach ($ sqls as $ sql ) {
8079 $ script .= $ this ->convertStatementToScript ($ sql );
8180 }
@@ -95,18 +94,20 @@ public function createSchema() {
9594 }
9695 return preg_match ($ filterExpression , $ asset ) === 1 ;
9796 });
98- return $ this ->connection ->getSchemaManager ()->createSchema ();
97+ return $ this ->connection ->createSchemaManager ()->introspectSchema ();
9998 }
10099
101100 /**
102101 * @return SchemaDiff
103102 */
104103 protected function getDiff (Schema $ targetSchema , Connection $ connection ) {
105- // adjust varchar columns with a length higher then getVarcharMaxLength to clob
104+ // Adjust STRING columns with a length higher than 4000 to TEXT (clob)
105+ // for consistency between the supported databases and
106+ // old vs. new installations.
106107 foreach ($ targetSchema ->getTables () as $ table ) {
107108 foreach ($ table ->getColumns () as $ column ) {
108109 if ($ column ->getType () instanceof StringType) {
109- if ($ column ->getLength () > $ connection -> getDatabasePlatform ()-> getVarcharMaxLength () ) {
110+ if ($ column ->getLength () > 4000 ) {
110111 $ column ->setType (Type::getType ('text ' ));
111112 $ column ->setLength (null );
112113 }
@@ -122,7 +123,7 @@ protected function getDiff(Schema $targetSchema, Connection $connection) {
122123 }
123124 return preg_match ($ filterExpression , $ asset ) === 1 ;
124125 });
125- $ sourceSchema = $ connection ->getSchemaManager ()->createSchema ();
126+ $ sourceSchema = $ connection ->createSchemaManager ()->introspectSchema ();
126127
127128 // remove tables we don't know about
128129 foreach ($ sourceSchema ->getTables () as $ table ) {
@@ -137,9 +138,8 @@ protected function getDiff(Schema $targetSchema, Connection $connection) {
137138 }
138139 }
139140
140- /** @psalm-suppress InternalMethod */
141- $ comparator = new Comparator ();
142- return $ comparator ->compare ($ sourceSchema , $ targetSchema );
141+ $ comparator = $ connection ->createSchemaManager ()->createComparator ();
142+ return $ comparator ->compareSchemas ($ sourceSchema , $ targetSchema );
143143 }
144144
145145 /**
@@ -155,7 +155,7 @@ protected function applySchema(Schema $targetSchema, Connection $connection = nu
155155 if (!$ connection ->getDatabasePlatform () instanceof MySQLPlatform) {
156156 $ connection ->beginTransaction ();
157157 }
158- $ sqls = $ schemaDiff -> toSql ( $ connection ->getDatabasePlatform ());
158+ $ sqls = $ connection ->getDatabasePlatform ()-> getAlterSchemaSQL ( $ schemaDiff );
159159 $ step = 0 ;
160160 foreach ($ sqls as $ sql ) {
161161 $ this ->emit ($ sql , $ step ++, count ($ sqls ));
@@ -178,7 +178,7 @@ protected function convertStatementToScript($statement) {
178178 }
179179
180180 protected function getFilterExpression () {
181- return '/^ ' . preg_quote ($ this ->config ->getSystemValueString ('dbtableprefix ' , 'oc_ ' )) . '/ ' ;
181+ return '/^ ' . preg_quote ($ this ->config ->getSystemValueString ('dbtableprefix ' , 'oc_ ' ), ' / ' ) . '/ ' ;
182182 }
183183
184184 protected function emit (string $ sql , int $ step , int $ max ): void {
0 commit comments