From 89fbc6bb8defb4a385723d7c3f5b6e700441f886 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Aug 2020 20:06:06 +0000 Subject: [PATCH 1/3] Foreign keys added --- static/dbstructure.config.php | 290 ++++++++++++++++------------------ update.php | 154 +++++++++++++++++- 2 files changed, 290 insertions(+), 154 deletions(-) diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index e37c343f1e..65a14536e4 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -54,7 +54,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1363); + define('DB_UPDATE_VERSION', 1364); } return [ @@ -89,20 +89,6 @@ return [ "nurl" => ["UNIQUE", "nurl(190)"], ] ], - "clients" => [ - "comment" => "OAuth usage", - "fields" => [ - "client_id" => ["type" => "varchar(20)", "not null" => "1", "primary" => "1", "comment" => ""], - "pw" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""], - "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""], - "name" => ["type" => "text", "comment" => ""], - "icon" => ["type" => "text", "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], - ], - "indexes" => [ - "PRIMARY" => ["client_id"], - ] - ], "contact" => [ "comment" => "contact table", "fields" => [ @@ -220,6 +206,89 @@ return [ "guid" => ["guid"] ] ], + "tag" => [ + "comment" => "tags and mentions", + "fields" => [ + "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""], + "name" => ["type" => "varchar(96)", "not null" => "1", "default" => "", "comment" => ""], + "url" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""] + ], + "indexes" => [ + "PRIMARY" => ["id"], + "type_name_url" => ["UNIQUE", "name", "url"], + "url" => ["url"] + ] + ], + "user" => [ + "comment" => "The local users", + "fields" => [ + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], + "parent-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], + "comment" => "The parent user that has full control about this user"], + "guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this user"], + "username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this user is known by"], + "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "encrypted password"], + "legacy_password" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Is the password hash double-hashed?"], + "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "nick- and user name"], + "email" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "the users email address"], + "openid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], + "timezone" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => "PHP-legal timezone"], + "language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"], + "register_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of registration"], + "login_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last login"], + "default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"], + "allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"], + "theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"], + "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"], + "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"], + "spubkey" => ["type" => "text", "comment" => ""], + "sprvkey" => ["type" => "text", "comment" => ""], + "verified" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "user is verified through email"], + "blocked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 for user is blocked"], + "blockwall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to post to the profile page of the user"], + "hidewall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide profile details from unkown viewers"], + "blocktags" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to tag the post of this user"], + "unkmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Permit unknown people to send private mails to this user"], + "cntunkmail" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""], + "notify-flags" => ["type" => "smallint unsigned", "not null" => "1", "default" => "65535", "comment" => "email notification options"], + "page-flags" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "page/profile type"], + "account-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], + "prvnets" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], + "pwdreset" => ["type" => "varchar(255)", "comment" => "Password reset request token"], + "pwdreset_time" => ["type" => "datetime", "comment" => "Timestamp of the last password reset request"], + "maxreq" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""], + "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], + "account_removed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if 1 the account is removed"], + "account_expired" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], + "account_expires_on" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp when account expires and will be deleted"], + "expire_notification_sent" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last warning of account expiration"], + "def_gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], + "allow_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"], + "allow_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"], + "deny_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"], + "deny_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"], + "openidserver" => ["type" => "text", "comment" => ""], + ], + "indexes" => [ + "PRIMARY" => ["uid"], + "nickname" => ["nickname(32)"], + ] + ], + "clients" => [ + "comment" => "OAuth usage", + "fields" => [ + "client_id" => ["type" => "varchar(20)", "not null" => "1", "primary" => "1", "comment" => ""], + "pw" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""], + "redirect_uri" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""], + "name" => ["type" => "text", "comment" => ""], + "icon" => ["type" => "text", "comment" => ""], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], + ], + "indexes" => [ + "PRIMARY" => ["client_id"], + "uid" => ["uid"], + ] + ], "permissionset" => [ "comment" => "", "fields" => [ @@ -235,25 +304,12 @@ return [ "uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"], ] ], - "tag" => [ - "comment" => "tags and mentions", - "fields" => [ - "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""], - "name" => ["type" => "varchar(96)", "not null" => "1", "default" => "", "comment" => ""], - "url" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => ""] - ], - "indexes" => [ - "PRIMARY" => ["id"], - "type_name_url" => ["UNIQUE", "name", "url"], - "url" => ["url"] - ] - ], // Main tables "2fa_app_specific_password" => [ "comment" => "Two-factor app-specific _password", "fields" => [ "id" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "Password ID for revocation"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "relation" => ["user" => "uid"], "comment" => "User ID"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "foreign" => ["user" => "uid"], "comment" => "User ID"], "description" => ["type" => "varchar(255)", "comment" => "Description of the usage of the password"], "hashed_password" => ["type" => "varchar(255)", "not null" => "1", "comment" => "Hashed password"], "generated" => ["type" => "datetime", "not null" => "1", "comment" => "Datetime the password was generated"], @@ -267,7 +323,7 @@ return [ "2fa_recovery_codes" => [ "comment" => "Two-factor authentication recovery codes", "fields" => [ - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User ID"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "User ID"], "code" => ["type" => "varchar(50)", "not null" => "1", "primary" => "1", "comment" => "Recovery code string"], "generated" => ["type" => "datetime", "not null" => "1", "comment" => "Datetime the code was generated"], "used" => ["type" => "datetime", "comment" => "Datetime the code was used"], @@ -333,7 +389,7 @@ return [ "comment" => "file attachments", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "generated index"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "hash" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "hash"], "filename" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "filename of original"], "filetype" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "mimetype"], @@ -350,6 +406,7 @@ return [ ], "indexes" => [ "PRIMARY" => ["id"], + "uid" => ["uid"], ] ], "auth_codes" => [ @@ -427,7 +484,7 @@ return [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this conversation"], "recips" => ["type" => "text", "comment" => "sender_handle;recipient_handle"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "creator" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "handle of creator"], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation timestamp"], "updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "edited timestamp"], @@ -472,7 +529,7 @@ return [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], - "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact_id (ID of the contact in contact table)"], + "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact_id (ID of the contact in contact table)"], "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "creation time"], "edited" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "last edit time"], @@ -493,6 +550,7 @@ return [ "indexes" => [ "PRIMARY" => ["id"], "uid_start" => ["uid", "start"], + "cid" => ["cid"], ] ], "fcontact" => [ @@ -526,8 +584,8 @@ return [ "comment" => "friend suggestion stuff", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], - "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], + "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => ""], "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], @@ -537,13 +595,15 @@ return [ ], "indexes" => [ "PRIMARY" => ["id"], + "cid" => ["cid"], + "uid" => ["uid"], ] ], "group" => [ "comment" => "privacy groups, group info", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the member list is not private"], "deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 indicates the group has been deleted"], "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "human readable name of group"], @@ -557,8 +617,8 @@ return [ "comment" => "privacy groups, member info", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["group" => "id"], "comment" => "groups.id of the associated group"], - "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"], + "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["group" => "id"], "comment" => "groups.id of the associated group"], + "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"], ], "indexes" => [ "PRIMARY" => ["id"], @@ -569,7 +629,7 @@ return [ "gserver-tag" => [ "comment" => "Tags that the server has subscribed", "fields" => [ - "gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gserver" => "id"], "primary" => "1", + "gserver-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["gserver" => "id"], "primary" => "1", "comment" => "The id of the gserver"], "tag" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "primary" => "1", "comment" => "Tag that the server has subscribed"], ], @@ -613,7 +673,7 @@ return [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], "fid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["fcontact" => "id"], "comment" => ""], - "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""], + "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => ""], "knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "duplex" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], "note" => ["type" => "text", "comment" => ""], @@ -624,6 +684,8 @@ return [ ], "indexes" => [ "PRIMARY" => ["id"], + "contact-id" => ["contact-id"], + "uid" => ["uid"], ] ], "item" => [ @@ -806,7 +868,7 @@ return [ "comment" => "private messages", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this private message"], "from-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "name of the sender"], "from-photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "contact photo link of the sender"], @@ -836,7 +898,7 @@ return [ "comment" => "Mail account data for fetching mails", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "server" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "port" => ["type" => "smallint unsigned", "not null" => "1", "default" => "0", "comment" => ""], "ssltype" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""], @@ -851,18 +913,20 @@ return [ ], "indexes" => [ "PRIMARY" => ["id"], + "uid" => ["uid"], ] ], "manage" => [ "comment" => "table of accounts that can manage each other", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], - "mid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], + "mid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], ], "indexes" => [ "PRIMARY" => ["id"], "uid_mid" => ["UNIQUE", "uid", "mid"], + "mid" => ["mid"], ] ], "notify" => [ @@ -875,7 +939,7 @@ return [ "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], "msg" => ["type" => "mediumtext", "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => "item.id"], "parent" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""], @@ -902,12 +966,13 @@ return [ "master-parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["item" => "id"], "comment" => ""], "master-parent-uri-id" => ["type" => "int unsigned", "relation" => ["item-uri" => "id"], "comment" => "Item-uri id of the parent of the related post"], "parent-item" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], - "receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], + "receiver-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], ], "indexes" => [ "PRIMARY" => ["id"], "master-parent-uri-id" => ["master-parent-uri-id"], + "receiver-uid" => ["receiver-uid"], ] ], "oembed" => [ @@ -927,7 +992,7 @@ return [ "comment" => "Store OpenWebAuth token to verify contacts", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "type" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Verify type"], "token" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A generated token"], "meta" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], @@ -935,6 +1000,7 @@ return [ ], "indexes" => [ "PRIMARY" => ["id"], + "uid" => ["uid"], ] ], "parsed_url" => [ @@ -954,10 +1020,10 @@ return [ "participation" => [ "comment" => "Storage for participation messages from Diaspora", "fields" => [ - "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => ""], + "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "foreign" => ["item" => "id"], "comment" => ""], "server" => ["type" => "varchar(60)", "not null" => "1", "primary" => "1", "comment" => ""], - "cid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["contact" => "id"], "comment" => ""], - "fid" => ["type" => "int unsigned", "not null" => "1", "relation" => ["fcontact" => "id"], "comment" => ""], + "cid" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["contact" => "id"], "comment" => ""], + "fid" => ["type" => "int unsigned", "not null" => "1", "foreign" => ["fcontact" => "id"], "comment" => ""], ], "indexes" => [ "PRIMARY" => ["iid", "server"], @@ -969,7 +1035,7 @@ return [ "comment" => "personal (per user) configuration storage", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "cat" => ["type" => "varbinary(50)", "not null" => "1", "default" => "", "comment" => ""], "k" => ["type" => "varbinary(100)", "not null" => "1", "default" => "", "comment" => ""], "v" => ["type" => "mediumtext", "comment" => ""], @@ -1019,39 +1085,6 @@ return [ "resource-id" => ["resource-id"], ] ], - "poll" => [ - "comment" => "Currently unused table for storing poll results", - "fields" => [ - "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], - "q0" => ["type" => "text", "comment" => ""], - "q1" => ["type" => "text", "comment" => ""], - "q2" => ["type" => "text", "comment" => ""], - "q3" => ["type" => "text", "comment" => ""], - "q4" => ["type" => "text", "comment" => ""], - "q5" => ["type" => "text", "comment" => ""], - "q6" => ["type" => "text", "comment" => ""], - "q7" => ["type" => "text", "comment" => ""], - "q8" => ["type" => "text", "comment" => ""], - "q9" => ["type" => "text", "comment" => ""], - ], - "indexes" => [ - "PRIMARY" => ["id"], - "uid" => ["uid"], - ] - ], - "poll_result" => [ - "comment" => "data for polls - currently unused", - "fields" => [ - "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "poll_id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["poll" => "id"]], - "choice" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], - ], - "indexes" => [ - "PRIMARY" => ["id"], - "poll_id" => ["poll_id"], - ] - ], "post-category" => [ "comment" => "post relation to categories", "fields" => [ @@ -1114,7 +1147,7 @@ return [ "comment" => "user profiles data", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner User id"], "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"], @@ -1166,21 +1199,23 @@ return [ "comment" => "DFRN remote auth use", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], - "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], + "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => "contact.id"], "dfrn_id" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "sec" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], ], "indexes" => [ "PRIMARY" => ["id"], + "uid" => ["uid"], + "cid" => ["cid"], ] ], "profile_field" => [ "comment" => "Custom profile fields", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner user id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "Owner user id"], "order" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "1", "comment" => "Field ordering per user"], "psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this profile field - 0 = public"], "label" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Label of the field"], @@ -1199,7 +1234,7 @@ return [ "comment" => "Used for OStatus: Contains feed subscribers", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "callback_url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "topic" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], @@ -1212,6 +1247,7 @@ return [ "indexes" => [ "PRIMARY" => ["id"], "next_try" => ["next_try"], + "uid" => ["uid"] ] ], "register" => [ @@ -1220,20 +1256,21 @@ return [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "hash" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "language" => ["type" => "varchar(16)", "not null" => "1", "default" => "", "comment" => ""], "note" => ["type" => "text", "comment" => ""], ], "indexes" => [ "PRIMARY" => ["id"], + "uid" => ["uid"], ] ], "search" => [ "comment" => "", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "term" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], ], "indexes" => [ @@ -1320,66 +1357,12 @@ return [ "client_id" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "foreign" => ["clients" => "client_id"]], "expires" => ["type" => "int", "not null" => "1", "default" => "0", "comment" => ""], "scope" => ["type" => "varchar(200)", "not null" => "1", "default" => "", "comment" => ""], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], ], "indexes" => [ "PRIMARY" => ["id"], - "client_id" => ["client_id"] - ] - ], - "user" => [ - "comment" => "The local users", - "fields" => [ - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "parent-uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], - "comment" => "The parent user that has full control about this user"], - "guid" => ["type" => "varchar(64)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this user"], - "username" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name that this user is known by"], - "password" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "encrypted password"], - "legacy_password" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Is the password hash double-hashed?"], - "nickname" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "nick- and user name"], - "email" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "the users email address"], - "openid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], - "timezone" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => "PHP-legal timezone"], - "language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"], - "register_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of registration"], - "login_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last login"], - "default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"], - "allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"], - "theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"], - "pubkey" => ["type" => "text", "comment" => "RSA public key 4096 bit"], - "prvkey" => ["type" => "text", "comment" => "RSA private key 4096 bit"], - "spubkey" => ["type" => "text", "comment" => ""], - "sprvkey" => ["type" => "text", "comment" => ""], - "verified" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "user is verified through email"], - "blocked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 for user is blocked"], - "blockwall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to post to the profile page of the user"], - "hidewall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Hide profile details from unkown viewers"], - "blocktags" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Prohibit contacts to tag the post of this user"], - "unkmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Permit unknown people to send private mails to this user"], - "cntunkmail" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""], - "notify-flags" => ["type" => "smallint unsigned", "not null" => "1", "default" => "65535", "comment" => "email notification options"], - "page-flags" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "page/profile type"], - "account-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], - "prvnets" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], - "pwdreset" => ["type" => "varchar(255)", "comment" => "Password reset request token"], - "pwdreset_time" => ["type" => "datetime", "comment" => "Timestamp of the last password reset request"], - "maxreq" => ["type" => "int unsigned", "not null" => "1", "default" => "10", "comment" => ""], - "expire" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], - "account_removed" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "if 1 the account is removed"], - "account_expired" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], - "account_expires_on" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp when account expires and will be deleted"], - "expire_notification_sent" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last warning of account expiration"], - "def_gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => ""], - "allow_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"], - "allow_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"], - "deny_cid" => ["type" => "mediumtext", "comment" => "default permission for this user"], - "deny_gid" => ["type" => "mediumtext", "comment" => "default permission for this user"], - "openidserver" => ["type" => "text", "comment" => ""], - ], - "indexes" => [ - "PRIMARY" => ["uid"], - "nickname" => ["nickname(32)"], + "client_id" => ["client_id"], + "uid" => ["uid"] ] ], "userd" => [ @@ -1396,21 +1379,22 @@ return [ "user-contact" => [ "comment" => "User specific public contact data", "fields" => [ - "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["contact" => "id"], "comment" => "Contact id of the linked public contact"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"], + "cid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "foreign" => ["contact" => "id"], "comment" => "Contact id of the linked public contact"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "User id"], "blocked" => ["type" => "boolean", "comment" => "Contact is completely blocked for this user"], "ignored" => ["type" => "boolean", "comment" => "Posts from this contact are ignored"], "collapsed" => ["type" => "boolean", "comment" => "Posts from this contact are collapsed"] ], "indexes" => [ - "PRIMARY" => ["uid", "cid"] + "PRIMARY" => ["uid", "cid"], + "cid" => ["cid"], ] ], "user-item" => [ "comment" => "User specific item data", "fields" => [ - "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["user" => "uid"], "comment" => "User id"], + "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "foreign" => ["item" => "id"], "comment" => "Item id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "primary" => "1", "foreign" => ["user" => "uid"], "comment" => "User id"], "hidden" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "Marker to hide an item from the user"], "ignored" => ["type" => "boolean", "comment" => "Ignore this thread if set"], "pinned" => ["type" => "boolean", "comment" => "The item is pinned on the profile page"], diff --git a/update.php b/update.php index f8ec8075c8..a740019a82 100644 --- a/update.php +++ b/update.php @@ -451,6 +451,9 @@ function pre_update_1348() update_1348(); + DBA::e("DELETE FROM `auth_codes` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)"); + DBA::e("DELETE FROM `tokens` WHERE NOT `client_id` IN (SELECT `client_id` FROM `clients`)"); + return Update::SUCCESS; } @@ -579,4 +582,153 @@ function pre_update_1363() { Photo::delete(["`contact-id` != ? AND NOT `contact-id` IN (SELECT `id` FROM `contact`)", 0]); return Update::SUCCESS; -} \ No newline at end of file +} + +function pre_update_1364() +{ + if (!DBA::e("DELETE FROM `2fa_recovery_codes` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `2fa_app_specific_password` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `attach` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `clients` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `conv` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `group` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `manage` WHERE NOT `mid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `mail` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `mailacct` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `notify` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `openwebauth-token` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `pconfig` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `profile` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `profile_field` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `push_subscriber` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `register` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `search` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `tokens` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `user-item` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `notify-threads` WHERE NOT `receiver-uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `event` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `fsuggest` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `group_member` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `intro` WHERE NOT `contact-id` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `participation` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `profile_check` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `user-contact` WHERE NOT `cid` IN (SELECT `id` FROM `contact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `participation` WHERE NOT `fid` IN (SELECT `id` FROM `fcontact`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `group_member` WHERE NOT `gid` IN (SELECT `id` FROM `group`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `gserver-tag` WHERE NOT `gserver-id` IN (SELECT `id` FROM `gserver`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `participation` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) { + return Update::FAILED; + } + + if (!DBA::e("DELETE FROM `user-item` WHERE NOT `iid` IN (SELECT `id` FROM `item`)")) { + return Update::FAILED; + } + + return Update::SUCCESS; +} From 9113b7e393acf0f74b42104b687f1ad5c8711b07 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Aug 2020 20:09:03 +0000 Subject: [PATCH 2/3] database.sql added --- database.sql | 294 +++++++++++++++++++++++++++------------------------ 1 file changed, 158 insertions(+), 136 deletions(-) diff --git a/database.sql b/database.sql index 3622e27930..cc90509bcc 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2020.09-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1363 +-- DB_UPDATE_VERSION 1364 -- ------------------------------------------ @@ -33,19 +33,6 @@ CREATE TABLE IF NOT EXISTS `gserver` ( UNIQUE INDEX `nurl` (`nurl`(190)) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Global servers'; --- --- TABLE clients --- -CREATE TABLE IF NOT EXISTS `clients` ( - `client_id` varchar(20) NOT NULL COMMENT '', - `pw` varchar(20) NOT NULL DEFAULT '' COMMENT '', - `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '', - `name` text COMMENT '', - `icon` text COMMENT '', - `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', - PRIMARY KEY(`client_id`) -) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage'; - -- -- TABLE contact -- @@ -162,6 +149,86 @@ CREATE TABLE IF NOT EXISTS `item-uri` ( INDEX `guid` (`guid`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='URI and GUID for items'; +-- +-- TABLE tag +-- +CREATE TABLE IF NOT EXISTS `tag` ( + `id` int unsigned NOT NULL auto_increment COMMENT '', + `name` varchar(96) NOT NULL DEFAULT '' COMMENT '', + `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '', + PRIMARY KEY(`id`), + UNIQUE INDEX `type_name_url` (`name`,`url`), + INDEX `url` (`url`) +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions'; + +-- +-- TABLE user +-- +CREATE TABLE IF NOT EXISTS `user` ( + `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID', + `parent-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'The parent user that has full control about this user', + `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user', + `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by', + `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password', + `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?', + `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name', + `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address', + `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '', + `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone', + `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language', + `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration', + `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login', + `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location', + `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location', + `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference', + `pubkey` text COMMENT 'RSA public key 4096 bit', + `prvkey` text COMMENT 'RSA private key 4096 bit', + `spubkey` text COMMENT '', + `sprvkey` text COMMENT '', + `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email', + `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked', + `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user', + `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers', + `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user', + `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user', + `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '', + `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options', + `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type', + `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', + `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '', + `pwdreset` varchar(255) COMMENT 'Password reset request token', + `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request', + `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '', + `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '', + `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed', + `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '', + `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted', + `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration', + `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '', + `allow_cid` mediumtext COMMENT 'default permission for this user', + `allow_gid` mediumtext COMMENT 'default permission for this user', + `deny_cid` mediumtext COMMENT 'default permission for this user', + `deny_gid` mediumtext COMMENT 'default permission for this user', + `openidserver` text COMMENT '', + PRIMARY KEY(`uid`), + INDEX `nickname` (`nickname`(32)) +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users'; + +-- +-- TABLE clients +-- +CREATE TABLE IF NOT EXISTS `clients` ( + `client_id` varchar(20) NOT NULL COMMENT '', + `pw` varchar(20) NOT NULL DEFAULT '' COMMENT '', + `redirect_uri` varchar(200) NOT NULL DEFAULT '' COMMENT '', + `name` text COMMENT '', + `icon` text COMMENT '', + `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', + PRIMARY KEY(`client_id`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE +) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage'; + -- -- TABLE permissionset -- @@ -176,18 +243,6 @@ CREATE TABLE IF NOT EXISTS `permissionset` ( INDEX `uid_allow_cid_allow_gid_deny_cid_deny_gid` (`allow_cid`(50),`allow_gid`(30),`deny_cid`(50),`deny_gid`(30)) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT=''; --- --- TABLE tag --- -CREATE TABLE IF NOT EXISTS `tag` ( - `id` int unsigned NOT NULL auto_increment COMMENT '', - `name` varchar(96) NOT NULL DEFAULT '' COMMENT '', - `url` varbinary(255) NOT NULL DEFAULT '' COMMENT '', - PRIMARY KEY(`id`), - UNIQUE INDEX `type_name_url` (`name`,`url`), - INDEX `url` (`url`) -) DEFAULT COLLATE utf8mb4_general_ci COMMENT='tags and mentions'; - -- -- TABLE 2fa_app_specific_password -- @@ -199,7 +254,8 @@ CREATE TABLE IF NOT EXISTS `2fa_app_specific_password` ( `generated` datetime NOT NULL COMMENT 'Datetime the password was generated', `last_used` datetime COMMENT 'Datetime the password was last used', PRIMARY KEY(`id`), - INDEX `uid_description` (`uid`,`description`(190)) + INDEX `uid_description` (`uid`,`description`(190)), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor app-specific _password'; -- @@ -210,7 +266,8 @@ CREATE TABLE IF NOT EXISTS `2fa_recovery_codes` ( `code` varchar(50) NOT NULL COMMENT 'Recovery code string', `generated` datetime NOT NULL COMMENT 'Datetime the code was generated', `used` datetime COMMENT 'Datetime the code was used', - PRIMARY KEY(`uid`,`code`) + PRIMARY KEY(`uid`,`code`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Two-factor authentication recovery codes'; -- @@ -284,7 +341,9 @@ CREATE TABLE IF NOT EXISTS `attach` ( `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups', `backend-class` tinytext COMMENT 'Storage backend class', `backend-ref` text COMMENT 'Storage backend data reference', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='file attachments'; -- @@ -366,7 +425,8 @@ CREATE TABLE IF NOT EXISTS `conv` ( `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'edited timestamp', `subject` text COMMENT 'subject of initial message', PRIMARY KEY(`id`), - INDEX `uid` (`uid`) + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages'; -- @@ -421,7 +481,9 @@ CREATE TABLE IF NOT EXISTS `event` ( `deny_cid` mediumtext COMMENT 'Access Control - list of denied contact.id', `deny_gid` mediumtext COMMENT 'Access Control - list of denied groups', PRIMARY KEY(`id`), - INDEX `uid_start` (`uid`,`start`) + INDEX `uid_start` (`uid`,`start`), + INDEX `cid` (`cid`), + FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Events'; -- @@ -463,7 +525,11 @@ CREATE TABLE IF NOT EXISTS `fsuggest` ( `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '', `note` text COMMENT '', `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `cid` (`cid`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='friend suggestion stuff'; -- @@ -476,7 +542,8 @@ CREATE TABLE IF NOT EXISTS `group` ( `deleted` boolean NOT NULL DEFAULT '0' COMMENT '1 indicates the group has been deleted', `name` varchar(255) NOT NULL DEFAULT '' COMMENT 'human readable name of group', PRIMARY KEY(`id`), - INDEX `uid` (`uid`) + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, group info'; -- @@ -488,7 +555,9 @@ CREATE TABLE IF NOT EXISTS `group_member` ( `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'contact.id of the member assigned to the associated group', PRIMARY KEY(`id`), INDEX `contactid` (`contact-id`), - UNIQUE INDEX `gid_contactid` (`gid`,`contact-id`) + UNIQUE INDEX `gid_contactid` (`gid`,`contact-id`), + FOREIGN KEY (`gid`) REFERENCES `group` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='privacy groups, member info'; -- @@ -498,7 +567,8 @@ CREATE TABLE IF NOT EXISTS `gserver-tag` ( `gserver-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'The id of the gserver', `tag` varchar(100) NOT NULL DEFAULT '' COMMENT 'Tag that the server has subscribed', PRIMARY KEY(`gserver-id`,`tag`), - INDEX `tag` (`tag`) + INDEX `tag` (`tag`), + FOREIGN KEY (`gserver-id`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Tags that the server has subscribed'; -- @@ -543,7 +613,10 @@ CREATE TABLE IF NOT EXISTS `intro` ( `datetime` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `blocked` boolean NOT NULL DEFAULT '1' COMMENT '', `ignore` boolean NOT NULL DEFAULT '0' COMMENT '', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `contact-id` (`contact-id`), + INDEX `uid` (`uid`), + FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT=''; -- @@ -746,7 +819,8 @@ CREATE TABLE IF NOT EXISTS `mail` ( INDEX `convid` (`convid`), INDEX `uri` (`uri`(64)), INDEX `parent-uri` (`parent-uri`(64)), - INDEX `contactid` (`contact-id`(32)) + INDEX `contactid` (`contact-id`(32)), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='private messages'; -- @@ -766,7 +840,9 @@ CREATE TABLE IF NOT EXISTS `mailacct` ( `movetofolder` varchar(255) NOT NULL DEFAULT '' COMMENT '', `pubmail` boolean NOT NULL DEFAULT '0' COMMENT '', `last_check` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Mail account data for fetching mails'; -- @@ -777,7 +853,10 @@ CREATE TABLE IF NOT EXISTS `manage` ( `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `mid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', PRIMARY KEY(`id`), - UNIQUE INDEX `uid_mid` (`uid`,`mid`) + UNIQUE INDEX `uid_mid` (`uid`,`mid`), + INDEX `mid` (`mid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`mid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='table of accounts that can manage each other'; -- @@ -805,7 +884,8 @@ CREATE TABLE IF NOT EXISTS `notify` ( PRIMARY KEY(`id`), INDEX `seen_uid_date` (`seen`,`uid`,`date`), INDEX `uid_date` (`uid`,`date`), - INDEX `uid_type_link` (`uid`,`type`,`link`(190)) + INDEX `uid_type_link` (`uid`,`type`,`link`(190)), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='notifications'; -- @@ -819,7 +899,9 @@ CREATE TABLE IF NOT EXISTS `notify-threads` ( `parent-item` int unsigned NOT NULL DEFAULT 0 COMMENT '', `receiver-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', PRIMARY KEY(`id`), - INDEX `master-parent-uri-id` (`master-parent-uri-id`) + INDEX `master-parent-uri-id` (`master-parent-uri-id`), + INDEX `receiver-uid` (`receiver-uid`), + FOREIGN KEY (`receiver-uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT=''; -- @@ -844,7 +926,9 @@ CREATE TABLE IF NOT EXISTS `openwebauth-token` ( `token` varchar(255) NOT NULL DEFAULT '' COMMENT 'A generated token', `meta` varchar(255) NOT NULL DEFAULT '' COMMENT '', `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'datetime of creation', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Store OpenWebAuth token to verify contacts'; -- @@ -870,7 +954,10 @@ CREATE TABLE IF NOT EXISTS `participation` ( `fid` int unsigned NOT NULL COMMENT '', PRIMARY KEY(`iid`,`server`), INDEX `cid` (`cid`), - INDEX `fid` (`fid`) + INDEX `fid` (`fid`), + FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`fid`) REFERENCES `fcontact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Storage for participation messages from Diaspora'; -- @@ -883,7 +970,8 @@ CREATE TABLE IF NOT EXISTS `pconfig` ( `k` varbinary(100) NOT NULL DEFAULT '' COMMENT '', `v` mediumtext COMMENT '', PRIMARY KEY(`id`), - UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`) + UNIQUE INDEX `uid_cat_k` (`uid`,`cat`,`k`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='personal (per user) configuration storage'; -- @@ -926,37 +1014,6 @@ CREATE TABLE IF NOT EXISTS `photo` ( FOREIGN KEY (`contact-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='photo storage'; --- --- TABLE poll --- -CREATE TABLE IF NOT EXISTS `poll` ( - `id` int unsigned NOT NULL auto_increment COMMENT '', - `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', - `q0` text COMMENT '', - `q1` text COMMENT '', - `q2` text COMMENT '', - `q3` text COMMENT '', - `q4` text COMMENT '', - `q5` text COMMENT '', - `q6` text COMMENT '', - `q7` text COMMENT '', - `q8` text COMMENT '', - `q9` text COMMENT '', - PRIMARY KEY(`id`), - INDEX `uid` (`uid`) -) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Currently unused table for storing poll results'; - --- --- TABLE poll_result --- -CREATE TABLE IF NOT EXISTS `poll_result` ( - `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID', - `poll_id` int unsigned NOT NULL DEFAULT 0, - `choice` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', - PRIMARY KEY(`id`), - INDEX `poll_id` (`poll_id`) -) DEFAULT COLLATE utf8mb4_general_ci COMMENT='data for polls - currently unused'; - -- -- TABLE post-category -- @@ -1065,7 +1122,8 @@ CREATE TABLE IF NOT EXISTS `profile` ( `net-publish` boolean NOT NULL DEFAULT '0' COMMENT 'publish profile in global directory', PRIMARY KEY(`id`), INDEX `uid_is-default` (`uid`,`is-default`), - FULLTEXT INDEX `pub_keywords` (`pub_keywords`) + FULLTEXT INDEX `pub_keywords` (`pub_keywords`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='user profiles data'; -- @@ -1078,7 +1136,11 @@ CREATE TABLE IF NOT EXISTS `profile_check` ( `dfrn_id` varchar(255) NOT NULL DEFAULT '' COMMENT '', `sec` varchar(255) NOT NULL DEFAULT '' COMMENT '', `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `uid` (`uid`), + INDEX `cid` (`cid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='DFRN remote auth use'; -- @@ -1097,6 +1159,7 @@ CREATE TABLE IF NOT EXISTS `profile_field` ( INDEX `uid` (`uid`), INDEX `order` (`order`), INDEX `psid` (`psid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Custom profile fields'; @@ -1115,7 +1178,9 @@ CREATE TABLE IF NOT EXISTS `push_subscriber` ( `renewed` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'Date of last subscription renewal', `secret` varchar(255) NOT NULL DEFAULT '' COMMENT '', PRIMARY KEY(`id`), - INDEX `next_try` (`next_try`) + INDEX `next_try` (`next_try`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Used for OStatus: Contains feed subscribers'; -- @@ -1129,7 +1194,9 @@ CREATE TABLE IF NOT EXISTS `register` ( `password` varchar(255) NOT NULL DEFAULT '' COMMENT '', `language` varchar(16) NOT NULL DEFAULT '' COMMENT '', `note` text COMMENT '', - PRIMARY KEY(`id`) + PRIMARY KEY(`id`), + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='registrations requiring admin approval'; -- @@ -1140,7 +1207,8 @@ CREATE TABLE IF NOT EXISTS `search` ( `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `term` varchar(255) NOT NULL DEFAULT '' COMMENT '', PRIMARY KEY(`id`), - INDEX `uid` (`uid`) + INDEX `uid` (`uid`), + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT=''; -- @@ -1223,62 +1291,11 @@ CREATE TABLE IF NOT EXISTS `tokens` ( `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', PRIMARY KEY(`id`), INDEX `client_id` (`client_id`), - FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE + INDEX `uid` (`uid`), + FOREIGN KEY (`client_id`) REFERENCES `clients` (`client_id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='OAuth usage'; --- --- TABLE user --- -CREATE TABLE IF NOT EXISTS `user` ( - `uid` mediumint unsigned NOT NULL auto_increment COMMENT 'sequential ID', - `parent-uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'The parent user that has full control about this user', - `guid` varchar(64) NOT NULL DEFAULT '' COMMENT 'A unique identifier for this user', - `username` varchar(255) NOT NULL DEFAULT '' COMMENT 'Name that this user is known by', - `password` varchar(255) NOT NULL DEFAULT '' COMMENT 'encrypted password', - `legacy_password` boolean NOT NULL DEFAULT '0' COMMENT 'Is the password hash double-hashed?', - `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT 'nick- and user name', - `email` varchar(255) NOT NULL DEFAULT '' COMMENT 'the users email address', - `openid` varchar(255) NOT NULL DEFAULT '' COMMENT '', - `timezone` varchar(128) NOT NULL DEFAULT '' COMMENT 'PHP-legal timezone', - `language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language', - `register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration', - `login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login', - `default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location', - `allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location', - `theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference', - `pubkey` text COMMENT 'RSA public key 4096 bit', - `prvkey` text COMMENT 'RSA private key 4096 bit', - `spubkey` text COMMENT '', - `sprvkey` text COMMENT '', - `verified` boolean NOT NULL DEFAULT '0' COMMENT 'user is verified through email', - `blocked` boolean NOT NULL DEFAULT '0' COMMENT '1 for user is blocked', - `blockwall` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to post to the profile page of the user', - `hidewall` boolean NOT NULL DEFAULT '0' COMMENT 'Hide profile details from unkown viewers', - `blocktags` boolean NOT NULL DEFAULT '0' COMMENT 'Prohibit contacts to tag the post of this user', - `unkmail` boolean NOT NULL DEFAULT '0' COMMENT 'Permit unknown people to send private mails to this user', - `cntunkmail` int unsigned NOT NULL DEFAULT 10 COMMENT '', - `notify-flags` smallint unsigned NOT NULL DEFAULT 65535 COMMENT 'email notification options', - `page-flags` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'page/profile type', - `account-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', - `prvnets` boolean NOT NULL DEFAULT '0' COMMENT '', - `pwdreset` varchar(255) COMMENT 'Password reset request token', - `pwdreset_time` datetime COMMENT 'Timestamp of the last password reset request', - `maxreq` int unsigned NOT NULL DEFAULT 10 COMMENT '', - `expire` int unsigned NOT NULL DEFAULT 0 COMMENT '', - `account_removed` boolean NOT NULL DEFAULT '0' COMMENT 'if 1 the account is removed', - `account_expired` boolean NOT NULL DEFAULT '0' COMMENT '', - `account_expires_on` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp when account expires and will be deleted', - `expire_notification_sent` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last warning of account expiration', - `def_gid` int unsigned NOT NULL DEFAULT 0 COMMENT '', - `allow_cid` mediumtext COMMENT 'default permission for this user', - `allow_gid` mediumtext COMMENT 'default permission for this user', - `deny_cid` mediumtext COMMENT 'default permission for this user', - `deny_gid` mediumtext COMMENT 'default permission for this user', - `openidserver` text COMMENT '', - PRIMARY KEY(`uid`), - INDEX `nickname` (`nickname`(32)) -) DEFAULT COLLATE utf8mb4_general_ci COMMENT='The local users'; - -- -- TABLE userd -- @@ -1298,7 +1315,10 @@ CREATE TABLE IF NOT EXISTS `user-contact` ( `blocked` boolean COMMENT 'Contact is completely blocked for this user', `ignored` boolean COMMENT 'Posts from this contact are ignored', `collapsed` boolean COMMENT 'Posts from this contact are collapsed', - PRIMARY KEY(`uid`,`cid`) + PRIMARY KEY(`uid`,`cid`), + INDEX `cid` (`cid`), + FOREIGN KEY (`cid`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific public contact data'; -- @@ -1313,7 +1333,9 @@ CREATE TABLE IF NOT EXISTS `user-item` ( `notification-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', PRIMARY KEY(`uid`,`iid`), INDEX `uid_pinned` (`uid`,`pinned`), - INDEX `iid_uid` (`iid`,`uid`) + INDEX `iid_uid` (`iid`,`uid`), + FOREIGN KEY (`iid`) REFERENCES `item` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`uid`) REFERENCES `user` (`uid`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='User specific item data'; -- From 88eee2b9c132528f2d6e3ac11faea8d4f3fe37d8 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Aug 2020 21:03:00 +0000 Subject: [PATCH 3/3] Another foreign key added --- src/Worker/RepairDatabase.php | 4 ++-- static/dbstructure.config.php | 2 +- update.php | 4 ++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Worker/RepairDatabase.php b/src/Worker/RepairDatabase.php index 9d951dadc6..2d7526953c 100644 --- a/src/Worker/RepairDatabase.php +++ b/src/Worker/RepairDatabase.php @@ -57,9 +57,9 @@ class RepairDatabase // Add intro entries for pending contacts // We don't do this for DFRN entries since such revived contact requests seem to mostly fail. $pending_contacts = DBA::p("SELECT `uid`, `id`, `url`, `network`, `created` FROM `contact` - WHERE `pending` AND `rel` IN (?, ?) AND `network` != ? + WHERE `pending` AND `rel` IN (?, ?) AND `network` != ? AND `uid` != ? AND NOT EXISTS (SELECT `id` FROM `intro` WHERE `contact-id` = `contact`.`id`)", - 0, Contact::FOLLOWER, Protocol::DFRN); + 0, Contact::FOLLOWER, Protocol::DFRN, 0); while ($contact = DBA::fetch($pending_contacts)) { DBA::insert('intro', ['uid' => $contact['uid'], 'contact-id' => $contact['id'], 'blocked' => false, 'hash' => Strings::getRandomHex(), 'datetime' => $contact['created']]); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 65a14536e4..8284ff8383 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -671,7 +671,7 @@ return [ "comment" => "", "fields" => [ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], - "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], + "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"], "fid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["fcontact" => "id"], "comment" => ""], "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => ""], "knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], diff --git a/update.php b/update.php index a740019a82..f163faf02f 100644 --- a/update.php +++ b/update.php @@ -614,6 +614,10 @@ function pre_update_1364() return Update::FAILED; } + if (!DBA::e("DELETE FROM `intro` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { + return Update::FAILED; + } + if (!DBA::e("DELETE FROM `manage` WHERE NOT `uid` IN (SELECT `uid` FROM `user`)")) { return Update::FAILED; }