Page MenuHomePhabricator

Standardise type of timestamp database fields (MySQL)
Closed, ResolvedPublic

Description

MediaWiki is using 14 char field as binary or varbinary or data type timestamp. Please clean this up, by using only one data type for all of them.

tables.sql contains a sentence about this:

-- The MySQL table backend for MediaWiki currently uses
-- 14-character BINARY or VARBINARY fields to store timestamps.
-- The format is YYYYMMDDHHMMSS, which is derived from the
-- text format of MySQL's TIMESTAMP fields.
--
-- Historically TIMESTAMP fields were used, but abandoned
-- in early 2002 after a lot of trouble with the fields
-- auto-updating.

Following fields are timestamp:

user_newpass_time binary(14),
user_touched binary(14) NOT NULL default '',
user_email_authenticated binary(14),
user_email_token_expires binary(14),
user_registration binary(14),
user_editcount int
user_last_timestamp varbinary(14) NULL default NULL
page_touched binary(14) NOT NULL default '',
rev_timestamp binary(14) NOT NULL default '',
ar_timestamp binary(14) NOT NULL default '',
cl_timestamp timestamp NOT NULL,
ipb_timestamp binary(14) NOT NULL default '',
ipb_expiry varbinary(14) NOT NULL default '',
img_timestamp varbinary(14) NOT NULL default '',
oi_timestamp binary(14) NOT NULL default '',
fa_deleted_timestamp binary(14) default '',
fa_timestamp binary(14) default '',
us_timestamp varbinary(14) NOT NULL,
rc_timestamp varbinary(14) NOT NULL default '',
rc_cur_time varbinary(14) NOT NULL default '',
wl_notificationtimestamp varbinary(14)
exptime datetime
tc_time binary(14) NOT NULL
log_timestamp binary(14) NOT NULL default '19700101000000',
job_timestamp varbinary(14) NULL default NULL,
qci_timestamp binary(14) NOT NULL default '19700101000000'
pr_expiry varbinary(14) NULL,
pt_timestamp binary(14) NOT NULL,
pt_expiry varbinary(14) NOT NULL default '',
mr_timestamp binary(14) NOT NULL

Version: 1.20.x
Severity: normal

Related Objects

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

I encountered this when doing T230428: Migrate tables.sql to abstract schema and probably do it with this task (or do it later) but I have a question. What about Postgres? Right now, mysql uses (var)binary but postgres uses TIMESTAMPTZ. Should I change it to varbinary for consistency or do hacks to make MySQL varbinary and Postgres TIMESTAMPTZ?

It seems I need to do this to achieve the abstract schema.

Change 626854 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Introduce TimestampType for handling custom db type in doctrine

https://gerrit.wikimedia.org/r/626854

Change 626854 merged by jenkins-bot:
[mediawiki/core@master] Introduce TimestampType for handling custom db type in doctrine

https://gerrit.wikimedia.org/r/626854

Change 630955 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Migrate page_restrictions to abstract schema

https://gerrit.wikimedia.org/r/630955

Change 631936 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Trim whitespace from $expiry in Database::decodeExpiry()

https://gerrit.wikimedia.org/r/631936

Change 631937 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Migrate user_groups to abstract schema

https://gerrit.wikimedia.org/r/631937

Change 634767 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Add custom option called "allowInfinite" for Timestamp

https://gerrit.wikimedia.org/r/634767

Change 634767 merged by jenkins-bot:
[mediawiki/core@master] Add custom option called "allowInfinite" for Timestamp

https://gerrit.wikimedia.org/r/634767

Change 630955 merged by jenkins-bot:
[mediawiki/core@master] Migrate page_restrictions to abstract schema

https://gerrit.wikimedia.org/r/630955

Change 631937 merged by jenkins-bot:
[mediawiki/core@master] Migrate user_groups to abstract schema

https://gerrit.wikimedia.org/r/631937

Change 641701 had a related patch set uploaded (by Ammarpad; owner: Ammarpad):
[mediawiki/core@master] Migrate job to abstract schema

https://gerrit.wikimedia.org/r/641701

Change 642685 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Add patch to set wl_notificationtimestamp BINARY(14)

https://gerrit.wikimedia.org/r/642685

Change 641701 merged by jenkins-bot:
[mediawiki/core@master] Migrate job to abstract schema

https://gerrit.wikimedia.org/r/641701

Change 642685 merged by jenkins-bot:
[mediawiki/core@master] Add patch to set wl_notificationtimestamp BINARY(14)

https://gerrit.wikimedia.org/r/642685

Change 649102 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Migrate uploadstash to abstract schema

https://gerrit.wikimedia.org/r/649102

Change 649102 merged by jenkins-bot:
[mediawiki/core@master] Migrate uploadstash to abstract schema

https://gerrit.wikimedia.org/r/649102

Change 651001 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] [WIP] Migrate filearchive to abstract schema

https://gerrit.wikimedia.org/r/651001

Change 651001 merged by jenkins-bot:
[mediawiki/core@master] Migrate filearchive to abstract schema

https://gerrit.wikimedia.org/r/651001

Change 657949 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Migrate ipblocks to abstract schema

https://gerrit.wikimedia.org/r/657949

Change 657949 merged by jenkins-bot:
[mediawiki/core@master] Migrate ipblocks to abstract schema

https://gerrit.wikimedia.org/r/657949

Change 667158 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Migrate recentchanges table to abstract schema

https://gerrit.wikimedia.org/r/667158

Change 667158 merged by jenkins-bot:
[mediawiki/core@master] Migrate recentchanges table to abstract schema

https://gerrit.wikimedia.org/r/667158

So far this happens with timestamp types in MySQL:

  • Most of them are being migrated to use binary(14) instead of varbinary(14)
  • Except the ones that hold expiry dates. These fields hold "infinite" as value and that's a valid Postgres timestamp so it works across platforms *shrugs*
  • We are dropping empty string as default value of these fields, empty string is not a valid timestamp, use null instead.
  • categorylinks uses mysql native datetime datatype which is really really hard to turn into binary(14). We left it like that for now.
  • objectcache was also similar but it gets cleaned up in new installations so we changed it to binary(14).

Change 668548 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Add schema change for img_timestamp varbinary(14) to binary(14)

https://gerrit.wikimedia.org/r/668548

Change 668548 merged by jenkins-bot:
[mediawiki/core@master] Add schema change for img_timestamp varbinary(14) to binary(14)

https://gerrit.wikimedia.org/r/668548

Change 671679 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/core@master] Migrate archive table to abstract schema

https://gerrit.wikimedia.org/r/671679

Change 671683 had a related patch set uploaded (by Ladsgroup; owner: Ladsgroup):
[mediawiki/extensions/Wikibase@master] Set ar_timestamp in PurgeEntityDataJobTest

https://gerrit.wikimedia.org/r/671683

Change 671683 merged by jenkins-bot:
[mediawiki/extensions/Wikibase@master] Set ar_timestamp in PurgeEntityDataJobTest

https://gerrit.wikimedia.org/r/671683

Change 671679 merged by jenkins-bot:
[mediawiki/core@master] Migrate archive table to abstract schema

https://gerrit.wikimedia.org/r/671679

With migration of all tables that have timestamp to abstract schema, this is now done (T230428: Migrate tables.sql to abstract schema)

To recap:

  • All timestamps are now binary(14), without empty string as default (some have null, some have 1970lotsofzeros)
  • The exception being timestamps that are used for expiry and then can accept "infinity". They are varbinary(14).
  • Only one exception: categorylinks (cl_timestamp). It's timestamp and hopefully will be tackled once categorylinks is normalized (T222224) and stops being the monster it is now. (T283461: Change datatype of cl_timestamp from timestamp to binary(14))

Change 631936 abandoned by Ladsgroup:

[mediawiki/core@master] Trim whitespace from $expiry in Database::decodeExpiry()

Reason:

not needed anymore. Feel free to restore if you need it

https://gerrit.wikimedia.org/r/631936