mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
Make two ancient migrations fatal if they affect data
Summary: Depends on D20106. Ref T6703. Since I plan to change the `ExternalAccount` table, these migrations (which rely on `save()`) will stop working. They could be rewritten to use raw queries, but I suspect few or no installs are affected. At least for now, just make them safe: if they would affect data, fatal and tell the user to perform a more gradual upgrade. Also remove an `ALTER IGNORE TABLE` (this syntax was removed at some point) and fix a `%Q` when adjusting certain types of primary keys. Test Plan: Ran `bin/storage upgrade --no-quickstart --force --namespace test1234` to get a complete migration since the beginning of time. Reviewers: amckinley Reviewed By: amckinley Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T6703 Differential Revision: https://secure.phabricator.com/D20107
This commit is contained in:
parent
fc3b90e1d1
commit
a46c25d2ba
4 changed files with 19 additions and 98 deletions
|
@ -1,2 +1,2 @@
|
|||
ALTER IGNORE TABLE `{$NAMESPACE}_file`.`file_imagemacro`
|
||||
ADD UNIQUE `name` (`name`);
|
||||
ALTER TABLE `{$NAMESPACE}_file`.`file_imagemacro`
|
||||
ADD UNIQUE KEY `name` (`name`);
|
||||
|
|
|
@ -1,66 +1,14 @@
|
|||
<?php
|
||||
|
||||
// NOTE: We aren't using PhabricatorUserOAuthInfo anywhere here because it is
|
||||
// getting nuked in a future diff.
|
||||
|
||||
$table = new PhabricatorUser();
|
||||
$conn = $table->establishConnection('w');
|
||||
$table_name = 'user_oauthinfo';
|
||||
$conn_w = $table->establishConnection('w');
|
||||
|
||||
$xaccount = new PhabricatorExternalAccount();
|
||||
|
||||
echo pht('Migrating OAuth to %s...', 'ExternalAccount')."\n";
|
||||
|
||||
$domain_map = array(
|
||||
'disqus' => 'disqus.com',
|
||||
'facebook' => 'facebook.com',
|
||||
'github' => 'github.com',
|
||||
'google' => 'google.com',
|
||||
);
|
||||
|
||||
try {
|
||||
$phabricator_oauth_uri = new PhutilURI(
|
||||
PhabricatorEnv::getEnvConfig('phabricator.oauth-uri'));
|
||||
$domain_map['phabricator'] = $phabricator_oauth_uri->getDomain();
|
||||
} catch (Exception $ex) {
|
||||
// Ignore; this likely indicates that we have removed `phabricator.oauth-uri`
|
||||
// in some future diff.
|
||||
foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Your Phabricator install has ancient OAuth account data and is '.
|
||||
'too old to upgrade directly to a modern version of Phabricator. '.
|
||||
'Upgrade to a version released between June 2013 and February 2019 '.
|
||||
'first, then upgrade to a modern version.'));
|
||||
}
|
||||
|
||||
$rows = queryfx_all(
|
||||
$conn_w,
|
||||
'SELECT * FROM user_oauthinfo');
|
||||
foreach ($rows as $row) {
|
||||
echo pht('Migrating row ID #%d.', $row['id'])."\n";
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'id = %d',
|
||||
$row['userID']);
|
||||
if (!$user) {
|
||||
echo pht('Bad user ID!')."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
$domain = idx($domain_map, $row['oauthProvider']);
|
||||
if (empty($domain)) {
|
||||
echo pht('Unknown OAuth provider!')."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$xaccount = id(new PhabricatorExternalAccount())
|
||||
->setUserPHID($user->getPHID())
|
||||
->setAccountType($row['oauthProvider'])
|
||||
->setAccountDomain($domain)
|
||||
->setAccountID($row['oauthUID'])
|
||||
->setAccountURI($row['accountURI'])
|
||||
->setUsername($row['accountName'])
|
||||
->setDateCreated($row['dateCreated']);
|
||||
|
||||
try {
|
||||
$xaccount->save();
|
||||
} catch (Exception $ex) {
|
||||
phlog($ex);
|
||||
}
|
||||
}
|
||||
|
||||
echo pht('Done.')."\n";
|
||||
|
|
|
@ -1,41 +1,14 @@
|
|||
<?php
|
||||
|
||||
// NOTE: We aren't using PhabricatorUserLDAPInfo anywhere here because it is
|
||||
// being nuked by this change
|
||||
|
||||
$table = new PhabricatorUser();
|
||||
$conn = $table->establishConnection('w');
|
||||
$table_name = 'user_ldapinfo';
|
||||
$conn_w = $table->establishConnection('w');
|
||||
|
||||
$xaccount = new PhabricatorExternalAccount();
|
||||
|
||||
echo pht('Migrating LDAP to %s...', 'ExternalAccount')."\n";
|
||||
|
||||
$rows = queryfx_all($conn_w, 'SELECT * FROM %T', $table_name);
|
||||
foreach ($rows as $row) {
|
||||
echo pht('Migrating row ID #%d.', $row['id'])."\n";
|
||||
$user = id(new PhabricatorUser())->loadOneWhere(
|
||||
'id = %d',
|
||||
$row['userID']);
|
||||
if (!$user) {
|
||||
echo pht('Bad user ID!')."\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$xaccount = id(new PhabricatorExternalAccount())
|
||||
->setUserPHID($user->getPHID())
|
||||
->setAccountType('ldap')
|
||||
->setAccountDomain('self')
|
||||
->setAccountID($row['ldapUsername'])
|
||||
->setUsername($row['ldapUsername'])
|
||||
->setDateCreated($row['dateCreated']);
|
||||
|
||||
try {
|
||||
$xaccount->save();
|
||||
} catch (Exception $ex) {
|
||||
phlog($ex);
|
||||
}
|
||||
foreach (new LiskRawMigrationIterator($conn, $table_name) as $row) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Your Phabricator install has ancient LDAP account data and is '.
|
||||
'too old to upgrade directly to a modern version of Phabricator. '.
|
||||
'Upgrade to a version released between June 2013 and February 2019 '.
|
||||
'first, then upgrade to a modern version.'));
|
||||
}
|
||||
|
||||
echo pht('Done.')."\n";
|
||||
|
|
|
@ -432,7 +432,7 @@ abstract class PhabricatorStorageManagementWorkflow
|
|||
case 'key':
|
||||
if (($phase == 'drop_keys') && $adjust['exists']) {
|
||||
if ($adjust['name'] == 'PRIMARY') {
|
||||
$key_name = 'PRIMARY KEY';
|
||||
$key_name = qsprintf($conn, 'PRIMARY KEY');
|
||||
} else {
|
||||
$key_name = qsprintf($conn, 'KEY %T', $adjust['name']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue