From 38f04616d2e8812243819881cb2c9b6be83f9f4c Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 11 Aug 2023 01:04:08 +0200 Subject: [PATCH] [Database 1525] Deprecate profile.name in favor of user.username --- database.sql | 4 ++-- doc/database/db_profile.md | 2 +- static/dbstructure.config.php | 4 ++-- update.php | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/database.sql b/database.sql index 74b7552c30..7305e65d2b 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2023.09-dev (Giant Rhubarb) --- DB_UPDATE_VERSION 1524 +-- DB_UPDATE_VERSION 1525 -- ------------------------------------------ @@ -1586,7 +1586,7 @@ CREATE TABLE IF NOT EXISTS `profile` ( `profile-name` varchar(255) COMMENT 'Deprecated', `is-default` boolean COMMENT 'Deprecated', `hide-friends` boolean NOT NULL DEFAULT '0' COMMENT 'Hide friend list from viewers of this profile', - `name` varchar(255) NOT NULL DEFAULT '' COMMENT '', + `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'Unused in favor of user.username', `pdesc` varchar(255) COMMENT 'Deprecated', `dob` varchar(32) NOT NULL DEFAULT '0000-00-00' COMMENT 'Day of birth', `address` varchar(255) NOT NULL DEFAULT '' COMMENT '', diff --git a/doc/database/db_profile.md b/doc/database/db_profile.md index ec47b94ec6..c4a8b01709 100644 --- a/doc/database/db_profile.md +++ b/doc/database/db_profile.md @@ -13,7 +13,7 @@ Fields | profile-name | Deprecated | varchar(255) | YES | | NULL | | | is-default | Deprecated | boolean | YES | | NULL | | | hide-friends | Hide friend list from viewers of this profile | boolean | NO | | 0 | | -| name | | varchar(255) | NO | | | | +| name | Unused in favor of user.username | varchar(255) | NO | | | | | pdesc | Deprecated | varchar(255) | YES | | NULL | | | dob | Day of birth | varchar(32) | NO | | 0000-00-00 | | | address | | varchar(255) | NO | | | | diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 970aeb9ccf..c7575528e9 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -56,7 +56,7 @@ use Friendica\Database\DBA; // This file is required several times during the test in DbaDefinition which justifies this condition if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1524); + define('DB_UPDATE_VERSION', 1525); } return [ @@ -1583,7 +1583,7 @@ return [ "profile-name" => ["type" => "varchar(255)", "comment" => "Deprecated"], "is-default" => ["type" => "boolean", "comment" => "Deprecated"], "hide-friends" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide friend list from viewers of this profile"], - "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], + "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Unused in favor of user.username"], "pdesc" => ["type" => "varchar(255)", "comment" => "Deprecated"], "dob" => ["type" => "varchar(32)", "not null" => "1", "default" => "0000-00-00", "comment" => "Day of birth"], "address" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], diff --git a/update.php b/update.php index 980ec721ab..78295921a1 100644 --- a/update.php +++ b/update.php @@ -1349,3 +1349,30 @@ function update_1524(): int return Update::SUCCESS; } + +function update_1525(): int +{ + // Use expected value for user.username + if (!DBA::e('UPDATE `user` u + JOIN `profile` p + ON p.`uid` = u.`uid` + SET u.`username` = p.`name`')) { + return Update::FAILED; + } + + // Blank out deprecated field profile.name to avoid future confusion + if (!DBA::e('UPDATE `profile` p + SET p.`name` = ""')) { + return Update::FAILED; + } + + // Update users' self-contact name if needed + if (!DBA::e('UPDATE `contact` c + JOIN `user` u + ON u.`uid` = c.`uid` AND c.`self` = 1 + SET c.`name` = u.`username`')) { + return Update::FAILED; + } + + return Update::SUCCESS; +}