Migrate slots table to abstract schema

Three fields were BIGINT in MySQL (and Sqlite) but INT in Postgres
so making Postgres BIGINT as well:
 - slot_revision_id
 - slot_content_id
 - slot_origin

Bug: T230428
Bug: T164898
Change-Id: I5333cc0cbdc36356bd865ae118b883bc367c31eb
This commit is contained in:
Amir Sarabadani 2020-07-20 02:15:45 +02:00
parent e8b06fe503
commit aa3c07964c
7 changed files with 75 additions and 42 deletions

View file

@ -699,6 +699,9 @@ class PostgresUpdater extends DatabaseUpdater {
[ 'dropFkey', 'user_former_groups', 'ufg_user' ],
[ 'setDefault', 'bot_passwords', 'bp_token', '' ],
[ 'changeField', 'comment', 'comment_id', 'BIGINT', '' ],
[ 'changeField', 'slots', 'slot_revision_id', 'BIGINT', '' ],
[ 'changeField', 'slots', 'slot_content_id', 'BIGINT', '' ],
[ 'changeField', 'slots', 'slot_origin', 'BIGINT', '' ],
];
}

View file

@ -44,4 +44,14 @@ CREATE TABLE comment (
comment_data TEXT DEFAULT NULL,
PRIMARY KEY(comment_id)
);
CREATE INDEX comment_hash ON comment (comment_hash);
CREATE INDEX comment_hash ON comment (comment_hash);
CREATE TABLE slots (
slot_revision_id BIGINT NOT NULL,
slot_role_id SMALLINT NOT NULL,
slot_content_id BIGINT NOT NULL,
slot_origin BIGINT NOT NULL,
PRIMARY KEY(slot_revision_id, slot_role_id)
);
CREATE INDEX slot_revision_origin_role ON slots (
slot_revision_id, slot_origin, slot_role_id
);

View file

@ -214,18 +214,6 @@ CREATE INDEX archive_name_title_timestamp ON archive (ar_namespace,ar_title,ar_t
CREATE INDEX archive_actor ON archive (ar_actor);
CREATE UNIQUE INDEX ar_revid_uniq ON archive (ar_rev_id);
CREATE TABLE slots (
slot_revision_id INTEGER NOT NULL,
slot_role_id SMALLINT NOT NULL,
slot_content_id INTEGER NOT NULL,
slot_origin INTEGER NOT NULL,
PRIMARY KEY (slot_revision_id, slot_role_id)
);
CREATE INDEX slot_revision_origin_role ON slots (slot_revision_id, slot_origin, slot_role_id);
CREATE SEQUENCE content_content_id_seq;
CREATE TABLE content (
content_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('content_content_id_seq'),

View file

@ -41,4 +41,14 @@ CREATE TABLE /*_*/comment (
comment_hash INTEGER NOT NULL, comment_text BLOB NOT NULL,
comment_data BLOB DEFAULT NULL
);
CREATE INDEX comment_hash ON /*_*/comment (comment_hash);
CREATE INDEX comment_hash ON /*_*/comment (comment_hash);
CREATE TABLE /*_*/slots (
slot_revision_id BIGINT UNSIGNED NOT NULL,
slot_role_id SMALLINT UNSIGNED NOT NULL,
slot_content_id BIGINT UNSIGNED NOT NULL,
slot_origin BIGINT UNSIGNED NOT NULL,
PRIMARY KEY(slot_revision_id, slot_role_id)
);
CREATE INDEX slot_revision_origin_role ON /*_*/slots (
slot_revision_id, slot_origin, slot_role_id
);

View file

@ -50,3 +50,14 @@ CREATE TABLE /*_*/comment (
INDEX comment_hash (comment_hash),
PRIMARY KEY(comment_id)
) /*$wgDBTableOptions*/;
CREATE TABLE /*_*/slots (
slot_revision_id BIGINT UNSIGNED NOT NULL,
slot_role_id SMALLINT UNSIGNED NOT NULL,
slot_content_id BIGINT UNSIGNED NOT NULL,
slot_origin BIGINT UNSIGNED NOT NULL,
INDEX slot_revision_origin_role (
slot_revision_id, slot_origin, slot_role_id
),
PRIMARY KEY(slot_revision_id, slot_role_id)
) /*$wgDBTableOptions*/;

View file

@ -171,5 +171,44 @@
{ "name": "comment_hash", "columns": [ "comment_hash" ], "unique": false }
],
"pk": [ "comment_id" ]
},
{
"name": "slots",
"comment": "Slots represent an n:m relation between revisions and content objects. A content object can have a specific \"role\" in one or more revisions. Each revision can have multiple content objects, each having a different role.",
"columns": [
{
"name": "slot_revision_id",
"comment": "reference to rev_id or ar_rev_id",
"type": "bigint",
"options": { "unsigned": true, "notnull": true }
},
{
"name": "slot_role_id",
"comment": "reference to role_id",
"type": "smallint",
"options": { "unsigned": true, "notnull": true }
},
{
"name": "slot_content_id",
"comment": "reference to content_id",
"type": "bigint",
"options": { "unsigned": true, "notnull": true }
},
{
"name": "slot_origin",
"comment": "The revision ID of the revision that originated the slot's content. To find revisions that changed slots, look for slot_origin = slot_revision_id. TODO: Is that actually true? Rollback seems to violate it by setting slot_origin to an older rev_id. Undeletions could result in the same situation.",
"type": "bigint",
"options": { "unsigned": true, "notnull": true }
}
],
"indexes": [
{
"name": "slot_revision_origin_role",
"columns": [ "slot_revision_id", "slot_origin", "slot_role_id" ],
"comment": "Index for finding revisions that modified a specific slot",
"unique": false
}
],
"pk": [ "slot_revision_id", "slot_role_id" ]
}
]

View file

@ -515,34 +515,6 @@ CREATE INDEX /*i*/ar_actor_timestamp ON /*_*/archive (ar_actor,ar_timestamp);
-- rows, such as change_tag.
CREATE UNIQUE INDEX /*i*/ar_revid_uniq ON /*_*/archive (ar_rev_id);
--
-- Slots represent an n:m relation between revisions and content objects.
-- A content object can have a specific "role" in one or more revisions.
-- Each revision can have multiple content objects, each having a different role.
--
CREATE TABLE /*_*/slots (
-- reference to rev_id or ar_rev_id
slot_revision_id bigint unsigned NOT NULL,
-- reference to role_id
slot_role_id smallint unsigned NOT NULL,
-- reference to content_id
slot_content_id bigint unsigned NOT NULL,
-- The revision ID of the revision that originated the slot's content.
-- To find revisions that changed slots, look for slot_origin = slot_revision_id.
-- TODO: Is that actually true? Rollback seems to violate it by setting
-- slot_origin to an older rev_id. Undeletions could result in the same situation.
slot_origin bigint unsigned NOT NULL,
PRIMARY KEY ( slot_revision_id, slot_role_id )
) /*$wgDBTableOptions*/;
-- Index for finding revisions that modified a specific slot
CREATE INDEX /*i*/slot_revision_origin_role ON /*_*/slots (slot_revision_id, slot_origin, slot_role_id);
--
-- The content table represents content objects. It's primary purpose is to provide the necessary
-- meta-data for loading and interpreting a serialized data blob to create a content object.