Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drush command for deleting orphaned legacy datastore tables #2839

Merged
merged 2 commits into from Mar 7, 2019

Conversation

dharizza
Copy link
Contributor

@dharizza dharizza commented Feb 27, 2019

User story

The ghost datastore tables are those for which there doesn't exist a related node, for example there exist a table feeds_datastore_dkan_file_10000 but there isn't a node with id 10000. Here we're adding a new drush command drush dkan-datastore-delete-ghost-tables with alias drush dkan-datastore-dgt to find ghost datastore tables and delete them.

QA Steps

  • When you run drush dkan-datastore-drop-orphan-tables or drush dkan-datastore-dot you'll get the following behaviour:
    • If there are no datastore tables, you'll get a message saying "There are currently no datastore tables on this site." (this will happen on a fresh install when you haven't imported anything to datastore).
    • If there are datastore tables, you'll get a message displaying the node IDs it is looking for (node IDs for which there is a datastore table).
    • Number of ghost tables found.
    • If there are ghost tables, it deletes them and shows the respective table names.

Connects NuCivic/dkan_management#171

@dafeder dafeder self-assigned this Feb 28, 2019
@kimwdavidson kimwdavidson added this to the DKAN Sprint 16 milestone Mar 5, 2019
Copy link
Member

@dafeder dafeder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this by creating an empty table called "feeds_datastore_dkan_file_130" and the command did remove it. So let's make these small wording changes and I'll merge it.

// Delete ghost datastore tables.
$items['dkan-datastore-delete-ghost-tables'] = array(
'aliases' => array('dkan-datastore-dgt'),
'description' => 'Delete ghost datastore tables if they exist.',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been using the term "ghost" casually for this but I don't think it's very clear to others. Let's switch "ghost" for "orphan," and "deleted" for "dropped" while we're at it. So let's call it dkan-datastore-drop-orphan-tables) And while we're at it let's make that alias a little shorter and consistent with our conventions: dkan-dot.

}
}
if (!empty($nids)) {
drush_print("Looking through " . implode(', ', $nids));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say for this "Checking for the following nodes: "

drush_print("Deleted ghost table $table");
}
} else {
drush_print("There is currently no datastore tables.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"There are currently no datastore tables on this site."

drush_print("Ghost tables found: $ghosts");
foreach ($to_truncate as $table) {
$query = db_drop_table($table);
drush_print("Deleted ghost table $table");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Deleted orphan table $table"

@dharizza dharizza assigned dharizza and unassigned dafeder Mar 7, 2019
@dharizza
Copy link
Contributor Author

dharizza commented Mar 7, 2019

@dafeder fixed.

@dafeder dafeder changed the title Added drush command for finding and deleting ghost datastore tables. Drush command for deleting orphaned legacy datastore tables Mar 7, 2019
@dafeder dafeder merged commit d0b121f into 7.x-1.x Mar 7, 2019
@dafeder dafeder deleted the delete-ghost-datastore-tables branch March 7, 2019 19:00
@dharizza dharizza mentioned this pull request May 14, 2019
3 tasks
dafeder pushed a commit that referenced this pull request Apr 24, 2020
Drush command for deleting orphaned legacy datastore tables
dafeder pushed a commit that referenced this pull request Apr 24, 2020
Drush command for deleting orphaned legacy datastore tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants