put numerical index on xchan table, instead of unique xchan_hash

This commit is contained in:
Mike Macgirvin 2024-03-15 10:06:38 +11:00
parent ffe27ab571
commit 91cc67cc6f
4 changed files with 50 additions and 3 deletions

View file

@ -27,7 +27,7 @@ use Code\Lib\Url;
*/
const REPOSITORY_ID = 'streams';
const DB_UPDATE_VERSION = 1276;
const DB_UPDATE_VERSION = 1277;
const PROJECT_BASE = __DIR__;
const ACTIVITYPUB_ENABLED = true;
const NOMAD_PROTOCOL_VERSION = '13.3';

View file

@ -1161,6 +1161,7 @@ CREATE TABLE IF NOT EXISTS `verify` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE IF NOT EXISTS `xchan` (
`xchan_id` int unsigned NOT NULL AUTO_INCREMENT,
`xchan_hash` varchar(255) NOT NULL,
`xchan_guid` varchar(255) NOT NULL DEFAULT '',
`xchan_guid_sig` text NOT NULL,
@ -1188,7 +1189,8 @@ CREATE TABLE IF NOT EXISTS `xchan` (
`xchan_system` tinyint NOT NULL DEFAULT 0 ,
`xchan_type` tinyint NOT NULL DEFAULT 0 ,
`xchan_deleted` tinyint NOT NULL DEFAULT 0 ,
PRIMARY KEY (`xchan_hash`(191)),
PRIMARY KEY (`xchan_id`),
UNIQUE `xchan_hash` (`xchan_hash`(191)),
KEY `xchan_guid` (`xchan_guid`(191)),
KEY `xchan_addr` (`xchan_addr`(191)),
KEY `xchan_name` (`xchan_name`(191)),

View file

@ -1230,6 +1230,7 @@ create index "vote_guid" on vote ("vote_guid");
create index "vote_poll" on vote ("vote_poll");
create index "vote_element" on vote ("vote_element");
CREATE TABLE "xchan" (
"xchan_id" serial NOT NULL,
"xchan_hash" text NOT NULL,
"xchan_guid" text NOT NULL DEFAULT '',
"xchan_guid_sig" text NOT NULL DEFAULT '',
@ -1257,8 +1258,9 @@ CREATE TABLE "xchan" (
"xchan_system" smallint NOT NULL DEFAULT '0',
"xchan_type" smallint NOT NULL DEFAULT '0',
"xchan_deleted" smallint NOT NULL DEFAULT '0',
PRIMARY KEY ("xchan_hash")
PRIMARY KEY ("xchan_id")
);
create unique index "xchan_hash" on xchan ("xchan_hash");
create index "xchan_guid" on xchan ("xchan_guid");
create index "xchan_addr" on xchan ("xchan_addr");
create index "xchan_name" on xchan ("xchan_name");

43
src/Update/_1277.php Normal file
View file

@ -0,0 +1,43 @@
<?php
namespace Code\Update;
class _1277
{
public function run()
{
q("START TRANSACTION");
if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
$r1 = q("ALTER TABLE xchan DROP CONSTRAINT xchan_pkey");
$r2 = q("ALTER TABLE xchan ADD UNIQUE (xchan_hash)");
$r3 = q("ALTER TABLE xchan ADD xchan_id serial NOT NULL, ADD PRIMARY KEY (xchan_id)");
$r = $r1 && $r2 && $r3;
} else {
$r1 = q("ALTER TABLE xchan DROP PRIMARY KEY");
$r2 = q("ALTER TABLE xchan ADD UNIQUE (xchan_hash)");
$r3 = q("ALTER TABLE xchan ADD xchan_id INT UNSIGNED NOT NULL AUTO_INCREMENT, ADD PRIMARY KEY (xchan_id)");
$r = $r1 && $r2 && $r3;
}
if ($r) {
q("COMMIT");
return UPDATE_SUCCESS;
}
q("ROLLBACK");
return UPDATE_FAILED;
}
public function verify()
{
$columns = db_columns('xchan');
return in_array('xchan_id', $columns);
}
}