]> git.mxchange.org Git - friendica.git/commitdiff
[Database 1525] Deprecate profile.name in favor of user.username
authorHypolite Petovan <hypolite@mrpetovan.com>
Thu, 10 Aug 2023 23:04:08 +0000 (01:04 +0200)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 20 Aug 2023 18:00:01 +0000 (14:00 -0400)
database.sql
doc/database/db_profile.md
static/dbstructure.config.php
update.php

index 74b7552c30af00483081603be3de3428d9ba7c19..7305e65d2b7e77abb1f848bc5136667f01990028 100644 (file)
@@ -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 '',
index ec47b94ec6d72c71e3fdc929dda02da3bed564b5..c4a8b01709ad185b1f3f60c67770109d190e8d9a 100644 (file)
@@ -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   |     |            |                |
index 970aeb9ccf481f4bbdcc14d737dfc746ec1c1e67..c7575528e96d3e520cd45501f3a394b03115f23a 100644 (file)
@@ -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" => ""],
index 980ec721ab281db90676eab2cb59e03953c3f730..78295921a14faf9461494342a7bd84488cb1f2a8 100644 (file)
@@ -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;
+}