PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC] ); $table = 'tx_vitec_product_related_text'; $cols = $pdo->query('SHOW COLUMNS FROM `' . $table . '`')->fetchAll(); $names = array_column($cols, 'Field'); if (in_array('uid', $names, true)) { exit("$table already has a uid column - nothing to do.\n"); } $count = (int)$pdo->query('SELECT COUNT(*) FROM `' . $table . '`')->fetchColumn(); echo "Rebuilding $table ($count rows) ...\n"; $pdo->exec('DROP TABLE IF EXISTS `' . $table . '_new`'); $pdo->exec('CREATE TABLE `' . $table . '_new` ( uid int(11) NOT NULL auto_increment, pid int(11) DEFAULT 0 NOT NULL, product_uid int(11) DEFAULT 0 NOT NULL, related_uid int(11) DEFAULT 0 NOT NULL, sorting int(11) DEFAULT 0 NOT NULL, cardtext text, tstamp int(11) DEFAULT 0 NOT NULL, crdate int(11) DEFAULT 0 NOT NULL, PRIMARY KEY (uid), UNIQUE KEY pair (product_uid, related_uid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4'); $copied = $pdo->exec('INSERT INTO `' . $table . '_new` (pid, product_uid, related_uid, sorting, cardtext, tstamp, crdate) SELECT COALESCE(p.pid, 0), t.product_uid, t.related_uid, COALESCE(mm.sorting, 0), t.cardtext, t.tstamp, t.tstamp FROM `' . $table . '` t LEFT JOIN tx_vitec_domain_model_product p ON p.uid = t.product_uid LEFT JOIN tx_vitec_product_related_mm mm ON mm.uid_local = t.product_uid AND mm.uid_foreign = t.related_uid'); $pdo->exec('RENAME TABLE `' . $table . '` TO `' . $table . '_old`, `' . $table . '_new` TO `' . $table . '`'); $pdo->exec('DROP TABLE `' . $table . '_old`'); echo "Done: $copied rows copied, old table dropped.\n"; echo "Next: vendor/bin/typo3 extension:setup && vendor/bin/typo3 cache:flush\n";