Created
October 2, 2018 20:23
-
-
Save cesarmiquel/5dd22140b494a739d658806036915511 to your computer and use it in GitHub Desktop.
Rename Drupal Tables (remove prefix)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$cn = \Drupal\Core\Database\Database::getConnection('default', 'default'); | |
// This is prefix you want your tables to remove. | |
$prefix = 's3cr3t_'; | |
// Read all tables | |
$result = $cn->query("SHOW TABLES"); | |
if ($result) { | |
while ($row = $result->fetch(PDO::FETCH_NUM)) { | |
// rename table | |
$table_old = $row[0]; | |
$table_new = str_replace($prefix, '', $table_old); | |
$cn->query("RENAME TABLE {$table_old} TO {$table_new}"); | |
// show progress | |
print " $table_old -> $table_new\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment