diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 5d0749c58..a59376e0c 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -1054,6 +1054,28 @@ class DBStructure } } + if (self::existsTable('user') && !DBA::exists('user', ['uid' => 0])) { + $system = User::getSystemAccount(); + $user = [ + "username" => $system['name'], + "nickname" => $system['nick'], + "register_date" => $system['created'], + "pubkey" => $system['pubkey'], + "prvkey" => $system['prvkey'], + "spubkey" => $system['spubkey'], + "sprvkey" => $system['sprvkey'], + "verified" => true, + "page-flags" => User::PAGE_FLAGS_SOAPBOX, + "account-type" => User::ACCOUNT_TYPE_RELAY, + ]; + + DBA::insert('user', $user); + $lastid = DBA::lastInsertId(); + if ($lastid != 0) { + DBA::update('user', ['uid' => 0], ['uid' => $lastid]); + } + } + if (self::existsTable('contact') && !DBA::exists('contact', ['id' => 0])) { DBA::insert('contact', ['nurl' => '']); $lastid = DBA::lastInsertId(); @@ -1101,28 +1123,6 @@ class DBStructure } } - if (self::existsTable('user') && !DBA::exists('user', ['uid' => 0])) { - $system = User::getSystemAccount(); - $user = [ - "username" => $system['name'], - "nickname" => $system['nick'], - "register_date" => $system['created'], - "pubkey" => $system['pubkey'], - "prvkey" => $system['prvkey'], - "spubkey" => $system['spubkey'], - "sprvkey" => $system['sprvkey'], - "verified" => true, - "page-flags" => User::PAGE_FLAGS_SOAPBOX, - "account-type" => User::ACCOUNT_TYPE_RELAY, - ]; - - DBA::insert('user', $user); - $lastid = DBA::lastInsertId(); - if ($lastid != 0) { - DBA::update('user', ['uid' => 0], ['uid' => $lastid]); - } - } - if (!self::existsForeignKeyForField('tokens', 'client_id')) { $tokens = DBA::p("SELECT `tokens`.`id` FROM `tokens` LEFT JOIN `clients` ON `clients`.`client_id` = `tokens`.`client_id` diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 65d7ce781..cabb48c58 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -20,6 +20,7 @@ * Main database structure configuration file. * * Here are described all the tables, fields and indexes Friendica needs to work. + * The entry order is mostly alphabetic - with the exception of tables that are used in foreign keys. * * Syntax (braces indicate optionale values): * "