Skip to content

Commit

Permalink
fix migration after recent structual changes
Browse files Browse the repository at this point in the history
  • Loading branch information
andymck committed Aug 9, 2023
1 parent ae8fb06 commit b5f767b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mobile_verifier/migrations/15_speedtests_one_to_one.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ CREATE TABLE speedtests_migration (
upload_speed bigint,
download_speed bigint,
latency integer,
serial text,
timestamp timestamptz NOT NULL,
inserted_at timestamptz default now(),
PRIMARY KEY(pubkey, timestamp)
);
CREATE INDEX idx_speedtests_pubkey on speedtests_migration (pubkey);

INSERT INTO speedtests_migration (pubkey, upload_speed, download_speed, latency, timestamp)
SELECT id, (st).upload_speed, (st).download_speed, (st).latency, (st).timestamp
FROM (select id, unnest(speedtests) as st from speedtests) as tmp;
INSERT INTO speedtests_migration (pubkey, upload_speed, download_speed, latency, serial, timestamp)
SELECT id, (st).upload_speed, (st).download_speed, (st).latency, '', (st).timestamp
FROM (select id, unnest(speedtests) as st from speedtests) as tmp
ON CONFLICT DO NOTHING;

ALTER TABLE speedtests RENAME TO speedtests_old;
ALTER TABLE speedtests_migration RENAME TO speedtests;
Expand Down

0 comments on commit b5f767b

Please sign in to comment.