Skip to content

Conversation

@deer-wmde
Copy link
Contributor

@deer-wmde deer-wmde commented Nov 10, 2025

Adds a wbs-wiki:DropDatabase Command

  • drops the actual MediaWiki database
  • keeps wiki metadata intact (soft delete)
  • uses a scoped database connection

Bug: T409936

$wikiDb = $wiki->wikidb;
$prefix = $wikiDb->prefix;

// Replaces current mw database connection config with scoped wiki credentials
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this work after being run? I'm not certain what this is replacing but I think this was the wikimanager type credentials right?

Doesn't this mean that unless the app is restarted then this connection will no longer have sufficient powers to do work on other Wikis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this changes this configuration at runtime - which should only affect this very instance of php running this command, not affecting other instances where Laravel runs (try scrambling the config in tinker like this for example)

It serves several purposes:

  1. scope the db access to only the affected wiki
  2. use the connection settings usually used to connect to the mw dbs
  3. allow to run this command on any API pods (as only the queue deployment gets the root(!) credentials for the mw dbs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored to not directly use the mw connection config, but to create a new one by copying and altering it at runtime

}

$mediawikiPdo = $mwConn->getPdo();
$statement = $mediawikiPdo->prepare("UPDATE ${prefix}_user SET user_real_name = '', user_email = '', user_password = ''");
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO rather than poking in the raw internals of MW it would make more sense to run a MW maintenance script that does this;

I think this better follows the pattern we have been following before of keeping MW writing to MW's DB.

What would you think about that? I could imagine that either being run from the platform API or just as a standalone command run from a devs laptop.

Maybe following the pattern like https://github.com/wmde/wbaas-deploy/blob/937b2d1a7cf16899d53ad8bd9bfa49a57c88e836/k8s/jobs/addPlatformReservedUserToBotGroup.sh

but running https://github.com/wbstack/mediawiki/blob/main/dist/maintenance/deleteUserEmail.php , https://github.com/wbstack/mediawiki/blob/main/dist/maintenance/changePassword.php ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in theory yes

in reality currently i want to make sure we dont mess up the db while satisfying user requests and minimizing unplanned work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactored to drop the whole wiki database instead of blanking certain fields

@deer-wmde deer-wmde changed the title extend Wiki/Delete Command Add Wiki/DropDatabase Command Nov 11, 2025
class DropDatabaseTest extends TestCase {
use DatabaseTransactions;

public function testWikiNotFound() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks fine to me, integration testing this is almost always more hassle than it's worth

}

// Creates a temporary DB connection with wiki scoped credentials
private function getWikiDbConnection(WikiDb $wikiDb): mixed {
Copy link
Contributor

Choose a reason for hiding this comment

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

I love that you managed to make this work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

me too - there seems to be quite the difference though between calling config() and app->config and i didn't find out what it is yet (i.e., with config() this didn't work iirc)

@deer-wmde deer-wmde marked this pull request as draft November 13, 2025 12:36
@deer-wmde
Copy link
Contributor Author

deer-wmde commented Nov 13, 2025

Converted to Draft state as this possibly won't be needed

Short-term as we opted to do this manually for now (see https://phabricator.wikimedia.org/T409428)

Long-term the drop should probably happen either via Jobs/DeleteWikiDbJob.php or in a new dedicated, regularly scheduled pruning Job (see https://phabricator.wikimedia.org/T309588)

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.

3 participants