diff --git a/database/upgrades/00-latest-revision.sql b/database/upgrades/00-latest-revision.sql index f0a1b6e..5920ffa 100644 --- a/database/upgrades/00-latest-revision.sql +++ b/database/upgrades/00-latest-revision.sql @@ -1,4 +1,4 @@ --- v0 -> v48: Latest revision +-- v0 -> v49: Latest revision CREATE TABLE "user" ( mxid TEXT PRIMARY KEY, @@ -127,7 +127,7 @@ CREATE TABLE backfill_state ( portal_receiver TEXT, processing_batch BOOLEAN, backfill_complete BOOLEAN, - first_expected_ts TIMESTAMP, + first_expected_ts BIGINT, PRIMARY KEY (user_mxid, portal_jid, portal_receiver), FOREIGN KEY (user_mxid) REFERENCES "user" (mxid) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal (jid, receiver) ON DELETE CASCADE diff --git a/database/upgrades/47-room-backfill-state.sql b/database/upgrades/47-room-backfill-state.sql index 40e052a..18d3efe 100644 --- a/database/upgrades/47-room-backfill-state.sql +++ b/database/upgrades/47-room-backfill-state.sql @@ -6,7 +6,7 @@ CREATE TABLE backfill_state ( portal_receiver TEXT, processing_batch BOOLEAN, backfill_complete BOOLEAN, - first_expected_ts TIMESTAMP, + first_expected_ts INTEGER, PRIMARY KEY (user_mxid, portal_jid, portal_receiver), FOREIGN KEY (user_mxid) REFERENCES "user" (mxid) ON DELETE CASCADE ON UPDATE CASCADE, FOREIGN KEY (portal_jid, portal_receiver) REFERENCES portal (jid, receiver) ON DELETE CASCADE diff --git a/database/upgrades/49-backfill-state-timestamp-bigint.sql b/database/upgrades/49-backfill-state-timestamp-bigint.sql index b2128ee..fb32a53 100644 --- a/database/upgrades/49-backfill-state-timestamp-bigint.sql +++ b/database/upgrades/49-backfill-state-timestamp-bigint.sql @@ -1,7 +1,13 @@ --- v49: Convert first_expected_ts to BIGINT so that we can use zero-values. - --- only: sqlite -UPDATE backfill_state SET first_expected_ts=unixepoch(first_expected_ts); - +-- v49: Convert first_expected_ts to BIGINT -- only: postgres -ALTER TABLE backfill_state ALTER COLUMN first_expected_ts TYPE BIGINT USING extract(epoch from first_expected_ts); + +DO +$do$ +BEGIN + IF (SELECT data_type FROM information_schema.columns WHERE table_name='backfill_state' AND column_name='first_expected_ts') = 'integer' THEN + ALTER TABLE backfill_state ALTER COLUMN first_expected_ts TYPE BIGINT; + ELSE + ALTER TABLE backfill_state ALTER COLUMN first_expected_ts TYPE BIGINT USING EXTRACT(EPOCH FROM first_expected_ts); + END IF; +END +$do$