Skip to content

Commit 38a26d3

Browse files
Issue #52: Basic script to delete old tables no longer in use.
1 parent 86521e1 commit 38a26d3

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

.do/delete-old-tables.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$schema = \Drupal::service('database')->schema();
6+
7+
$tables = [
8+
'cache_permissions_by_term',
9+
'permissions_by_term_role',
10+
'permissions_by_term_user',
11+
'user__commerce_remote_id',
12+
];
13+
14+
$commerceTables = $schema->findTables('commerce%');
15+
16+
$profileTables = $schema->findTables('profile%');
17+
18+
$tables = \array_merge(
19+
$tables, \array_values($commerceTables), \array_values($profileTables),
20+
);
21+
22+
foreach ($tables as $name) {
23+
24+
if ($schema->dropTable($name) === true) {
25+
26+
\printf('Dropped "%s" table' . "\n", $name);
27+
28+
continue;
29+
30+
}
31+
32+
\printf('Table "%s" was not found' . "\n", $name);
33+
34+
}

.do/jobs/pre-deploy.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ drush -y updb
99

1010
# Import any configuration changes. This should be run after database updates.
1111
drush -y config:import
12+
13+
# Delete old tables from the Commerce days.
14+
#
15+
# @see https://github.com/neurocracy/omnipedia/issues/52
16+
drush php:script .do/delete-old-tables.php

0 commit comments

Comments
 (0)