From 550b9e3c949e5e1d588ff811867a4e1675d2a195 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 24 Jun 2016 16:19:39 -0700 Subject: [PATCH] db: add v2->v3 upgrader --- .../server/db-schemas/upgrade-to-v3.sql | 66 +++++++++++++++++++ src/wormhole/test/test_database.py | 1 - 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/wormhole/server/db-schemas/upgrade-to-v3.sql diff --git a/src/wormhole/server/db-schemas/upgrade-to-v3.sql b/src/wormhole/server/db-schemas/upgrade-to-v3.sql new file mode 100644 index 0000000..0a01581 --- /dev/null +++ b/src/wormhole/server/db-schemas/upgrade-to-v3.sql @@ -0,0 +1,66 @@ +DROP TABLE `nameplates`; +DROP TABLE `messages`; +DROP TABLE `mailboxes`; + + +-- Wormhole codes use a "nameplate": a short name which is only used to +-- reference a specific (long-named) mailbox. The codes only use numeric +-- nameplates, but the protocol and server allow can use arbitrary strings. +CREATE TABLE `nameplates` +( + `id` INTEGER PRIMARY KEY AUTOINCREMENT, + `app_id` VARCHAR, + `name` VARCHAR, + `mailbox_id` VARCHAR REFERENCES `mailboxes`(`id`), + `request_id` VARCHAR, -- from 'allocate' message, for future deduplication + `updated` INTEGER -- time of last activity, used for pruning +); +CREATE INDEX `nameplates_idx` ON `nameplates` (`app_id`, `name`); +CREATE INDEX `nameplates_updated_idx` ON `nameplates` (`app_id`, `updated`); +CREATE INDEX `nameplates_mailbox_idx` ON `nameplates` (`app_id`, `mailbox_id`); +CREATE INDEX `nameplates_request_idx` ON `nameplates` (`app_id`, `request_id`); + +CREATE TABLE `nameplate_sides` +( + `nameplates_id` REFERENCES `nameplates`(`id`), + `claimed` BOOLEAN, -- True after claim(), False after release() + `side` VARCHAR, + `added` INTEGER -- time when this side first claimed the nameplate +); + + +-- Clients exchange messages through a "mailbox", which has a long (randomly +-- unique) identifier and a queue of messages. +-- `id` is randomly-generated and unique across all apps. +CREATE TABLE `mailboxes` +( + `app_id` VARCHAR, + `id` VARCHAR PRIMARY KEY, + `updated` INTEGER -- time of last activity, used for pruning +); +CREATE INDEX `mailboxes_idx` ON `mailboxes` (`app_id`, `id`); + +CREATE TABLE `mailbox_sides` +( + `mailbox_id` REFERENCES `mailboxes`(`id`), + `opened` BOOLEAN, -- True after open(), False after close() + `side` VARCHAR, + `added` INTEGER, -- time when this side first claimed the nameplate + `mood` VARCHAR +); + +CREATE TABLE `messages` +( + `app_id` VARCHAR, + `mailbox_id` VARCHAR, + `side` VARCHAR, + `phase` VARCHAR, -- numeric or string + `body` VARCHAR, + `server_rx` INTEGER, + `msg_id` VARCHAR +); +CREATE INDEX `messages_idx` ON `messages` (`app_id`, `mailbox_id`); + + +DELETE FROM `version`; +INSERT INTO `version` (`version`) VALUES (3); diff --git a/src/wormhole/test/test_database.py b/src/wormhole/test/test_database.py index 460508e..7a7b491 100644 --- a/src/wormhole/test/test_database.py +++ b/src/wormhole/test/test_database.py @@ -50,4 +50,3 @@ class DB(unittest.TestCase): with open("new.sql","w") as f: f.write(latest_text) # check with "diff -u _trial_temp/up.sql _trial_temp/new.sql" self.assertEqual(dbA_text, latest_text) - test_upgrade.skip = "disabled until at least one upgrader is written"