The uri-id is now in all contact tables

This commit is contained in:
Michael 2021-07-09 07:09:33 +00:00
parent c63d3f4604
commit 6e79da0b0c
7 changed files with 51 additions and 27 deletions

View file

@ -335,6 +335,7 @@ CREATE TABLE IF NOT EXISTS `addon` (
-- --
CREATE TABLE IF NOT EXISTS `apcontact` ( CREATE TABLE IF NOT EXISTS `apcontact` (
`url` varbinary(255) NOT NULL COMMENT 'URL of the contact', `url` varbinary(255) NOT NULL COMMENT 'URL of the contact',
`uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the apcontact url',
`uuid` varchar(255) COMMENT '', `uuid` varchar(255) COMMENT '',
`type` varchar(20) NOT NULL COMMENT '', `type` varchar(20) NOT NULL COMMENT '',
`following` varchar(255) COMMENT '', `following` varchar(255) COMMENT '',
@ -367,6 +368,8 @@ CREATE TABLE IF NOT EXISTS `apcontact` (
INDEX `baseurl` (`baseurl`(190)), INDEX `baseurl` (`baseurl`(190)),
INDEX `sharedinbox` (`sharedinbox`(190)), INDEX `sharedinbox` (`sharedinbox`(190)),
INDEX `gsid` (`gsid`), INDEX `gsid` (`gsid`),
UNIQUE INDEX `uri-id` (`uri-id`),
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE,
FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT FOREIGN KEY (`gsid`) REFERENCES `gserver` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='ActivityPub compatible contacts - used in the ActivityPub implementation';
@ -598,6 +601,7 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID', `id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
`guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'unique id', `guid` varchar(255) NOT NULL DEFAULT '' COMMENT 'unique id',
`url` varchar(255) NOT NULL DEFAULT '' COMMENT '', `url` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the fcontact url',
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '', `name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`photo` varchar(255) NOT NULL DEFAULT '' COMMENT '', `photo` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`request` varchar(255) NOT NULL DEFAULT '' COMMENT '', `request` varchar(255) NOT NULL DEFAULT '' COMMENT '',
@ -614,7 +618,9 @@ CREATE TABLE IF NOT EXISTS `fcontact` (
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', `updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
PRIMARY KEY(`id`), PRIMARY KEY(`id`),
INDEX `addr` (`addr`(32)), INDEX `addr` (`addr`(32)),
UNIQUE INDEX `url` (`url`(190)) UNIQUE INDEX `url` (`url`(190)),
UNIQUE INDEX `uri-id` (`uri-id`),
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation'; ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation';
-- --

View file

@ -9,6 +9,7 @@ Fields
| Field | Description | Type | Null | Key | Default | Extra | | Field | Description | Type | Null | Key | Default | Extra |
| ---------------- | ------------------------------------------------------------------- | -------------- | ---- | --- | ------------------- | ----- | | ---------------- | ------------------------------------------------------------------- | -------------- | ---- | --- | ------------------- | ----- |
| url | URL of the contact | varbinary(255) | NO | PRI | NULL | | | url | URL of the contact | varbinary(255) | NO | PRI | NULL | |
| uri-id | Id of the item-uri table entry that contains the apcontact url | int unsigned | YES | | NULL | |
| uuid | | varchar(255) | YES | | NULL | | | uuid | | varchar(255) | YES | | NULL | |
| type | | varchar(20) | NO | | NULL | | | type | | varchar(20) | NO | | NULL | |
| following | | varchar(255) | YES | | NULL | | | following | | varchar(255) | YES | | NULL | |
@ -47,12 +48,14 @@ Indexes
| baseurl | baseurl(190) | | baseurl | baseurl(190) |
| sharedinbox | sharedinbox(190) | | sharedinbox | sharedinbox(190) |
| gsid | gsid | | gsid | gsid |
| uri-id | UNIQUE, uri-id |
Foreign Keys Foreign Keys
------------ ------------
| Field | Target Table | Target Field | | Field | Target Table | Target Field |
|-------|--------------|--------------| |-------|--------------|--------------|
| uri-id | [item-uri](help/database/db_item-uri) | id |
| gsid | [gserver](help/database/db_gserver) | id | | gsid | [gserver](help/database/db_gserver) | id |
Return to [database documentation](help/database) Return to [database documentation](help/database)

View file

@ -6,25 +6,26 @@ Diaspora compatible contacts - used in the Diaspora implementation
Fields Fields
------ ------
| Field | Description | Type | Null | Key | Default | Extra | | Field | Description | Type | Null | Key | Default | Extra |
| -------- | ------------- | ---------------- | ---- | --- | ------------------- | -------------- | | -------- | ------------------------------------------------------------- | ---------------- | ---- | --- | ------------------- | -------------- |
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment | | id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
| guid | unique id | varchar(255) | NO | | | | | guid | unique id | varchar(255) | NO | | | |
| url | | varchar(255) | NO | | | | | url | | varchar(255) | NO | | | |
| name | | varchar(255) | NO | | | | | uri-id | Id of the item-uri table entry that contains the fcontact url | int unsigned | YES | | NULL | |
| photo | | varchar(255) | NO | | | | | name | | varchar(255) | NO | | | |
| request | | varchar(255) | NO | | | | | photo | | varchar(255) | NO | | | |
| nick | | varchar(255) | NO | | | | | request | | varchar(255) | NO | | | |
| addr | | varchar(255) | NO | | | | | nick | | varchar(255) | NO | | | |
| batch | | varchar(255) | NO | | | | | addr | | varchar(255) | NO | | | |
| notify | | varchar(255) | NO | | | | | batch | | varchar(255) | NO | | | |
| poll | | varchar(255) | NO | | | | | notify | | varchar(255) | NO | | | |
| confirm | | varchar(255) | NO | | | | | poll | | varchar(255) | NO | | | |
| priority | | tinyint unsigned | NO | | 0 | | | confirm | | varchar(255) | NO | | | |
| network | | char(4) | NO | | | | | priority | | tinyint unsigned | NO | | 0 | |
| alias | | varchar(255) | NO | | | | | network | | char(4) | NO | | | |
| pubkey | | text | YES | | NULL | | | alias | | varchar(255) | NO | | | |
| updated | | datetime | NO | | 0001-01-01 00:00:00 | | | pubkey | | text | YES | | NULL | |
| updated | | datetime | NO | | 0001-01-01 00:00:00 | |
Indexes Indexes
------------ ------------
@ -34,6 +35,13 @@ Indexes
| PRIMARY | id | | PRIMARY | id |
| addr | addr(32) | | addr | addr(32) |
| url | UNIQUE, url(190) | | url | UNIQUE, url(190) |
| uri-id | UNIQUE, uri-id |
Foreign Keys
------------
| Field | Target Table | Target Field |
|-------|--------------|--------------|
| uri-id | [item-uri](help/database/db_item-uri) | id |
Return to [database documentation](help/database) Return to [database documentation](help/database)

View file

@ -349,6 +349,12 @@ class APContact
$apcontact['alias'] = null; $apcontact['alias'] = null;
} }
if (empty($apcontact['uuid'])) {
$apcontact['uri-id'] = ItemURI::getIdByURI($apcontact['url']);
} else {
$apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['uri'], 'guid' => $apcontact['uuid']]);
}
$apcontact['updated'] = DateTimeFormat::utcNow(); $apcontact['updated'] = DateTimeFormat::utcNow();
// We delete the old entry when the URL is changed // We delete the old entry when the URL is changed

View file

@ -185,11 +185,7 @@ class Contact
$fields['gsid'] = GServer::getID($fields['baseurl'], true); $fields['gsid'] = GServer::getID($fields['baseurl'], true);
} }
if (!empty($fields['url']) && !empty($fields['guid'])) { $fields['uri-id'] = ItemURI::getIdByURI($fields['url']);
$fields['uri-id'] = ItemURI::insert(['uri' => $fields['url'], 'guid' => $fields['guid']]);
} elseif (!empty($fields['url'])) {
$fields['uri-id'] = ItemURI::getIdByURI($fields['url']);
}
if (empty($fields['created'])) { if (empty($fields['created'])) {
$fields['created'] = DateTimeFormat::utcNow(); $fields['created'] = DateTimeFormat::utcNow();
@ -2161,7 +2157,7 @@ class Contact
if (empty($guid)) { if (empty($guid)) {
$ret['uri-id'] = ItemURI::getIdByURI($ret['url']); $ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
} else { } else {
$ret['uri-id'] = ItemURI::insert(['uri' => $ret['uri'], 'guid' => $guid]); $ret['uri-id'] = ItemURI::insert(['uri' => $ret['uri'], 'guid' => $guid]);
} }
$ret['nurl'] = Strings::normaliseLink($ret['url']); $ret['nurl'] = Strings::normaliseLink($ret['url']);

View file

@ -100,6 +100,7 @@ class FContact
'batch' => $arr["batch"], 'notify' => $arr["notify"], 'batch' => $arr["batch"], 'notify' => $arr["notify"],
'poll' => $arr["poll"], 'confirm' => $arr["confirm"], 'poll' => $arr["poll"], 'confirm' => $arr["confirm"],
'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"], 'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"],
'uri-id' => ItemURI::insert(['uri' => $arr['url'], 'guid' => $arr['guid']]),
'updated' => DateTimeFormat::utcNow()]; 'updated' => DateTimeFormat::utcNow()];
$condition = ['url' => $arr["url"], 'network' => $arr["network"]]; $condition = ['url' => $arr["url"], 'network' => $arr["network"]];

View file

@ -395,6 +395,7 @@ return [
"comment" => "ActivityPub compatible contacts - used in the ActivityPub implementation", "comment" => "ActivityPub compatible contacts - used in the ActivityPub implementation",
"fields" => [ "fields" => [
"url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "URL of the contact"], "url" => ["type" => "varbinary(255)", "not null" => "1", "primary" => "1", "comment" => "URL of the contact"],
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the apcontact url"],
"uuid" => ["type" => "varchar(255)", "comment" => ""], "uuid" => ["type" => "varchar(255)", "comment" => ""],
"type" => ["type" => "varchar(20)", "not null" => "1", "comment" => ""], "type" => ["type" => "varchar(20)", "not null" => "1", "comment" => ""],
"following" => ["type" => "varchar(255)", "comment" => ""], "following" => ["type" => "varchar(255)", "comment" => ""],
@ -428,7 +429,8 @@ return [
"followers" => ["followers(190)"], "followers" => ["followers(190)"],
"baseurl" => ["baseurl(190)"], "baseurl" => ["baseurl(190)"],
"sharedinbox" => ["sharedinbox(190)"], "sharedinbox" => ["sharedinbox(190)"],
"gsid" => ["gsid"] "gsid" => ["gsid"],
"uri-id" => ["UNIQUE", "uri-id"],
] ]
], ],
"application" => [ "application" => [
@ -660,6 +662,7 @@ return [
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"], "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
"guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "unique id"], "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "unique id"],
"url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "url" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the fcontact url"],
"name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "photo" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""], "request" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
@ -679,6 +682,7 @@ return [
"PRIMARY" => ["id"], "PRIMARY" => ["id"],
"addr" => ["addr(32)"], "addr" => ["addr(32)"],
"url" => ["UNIQUE", "url(190)"], "url" => ["UNIQUE", "url(190)"],
"uri-id" => ["UNIQUE", "uri-id"],
] ]
], ],
"fsuggest" => [ "fsuggest" => [