[Fix] Stability
This commit is contained in:
parent
fa0af21af5
commit
4f7260419a
20 changed files with 563 additions and 464 deletions
|
|
@ -1,3 +1,8 @@
|
|||
CREATE TABLE IF NOT EXISTS iotas (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
public_key BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
iota_id BIGINT NOT NULL,
|
||||
|
|
@ -10,14 +15,15 @@ CREATE TABLE IF NOT EXISTS users (
|
|||
sub_end BIGINT NOT NULL DEFAULT 0,
|
||||
public_key BLOB NOT NULL,
|
||||
token BLOB NOT NULL,
|
||||
|
||||
UNIQUE KEY uk_users_username (username),
|
||||
UNIQUE KEY uk_users_iota_id (iota_id)
|
||||
KEY idx_users_iota_id (iota_id),
|
||||
|
||||
CONSTRAINT fk_users_iota
|
||||
FOREIGN KEY (iota_id)
|
||||
REFERENCES iotas (id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS iotas (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
public_key BLOB NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS omikrons (
|
||||
id BIGINT NOT NULL PRIMARY KEY,
|
||||
13
migrations/002_registration_leases.sql
Normal file
13
migrations/002_registration_leases.sql
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-- Registration IDs are allocated before the user row is created. Keep the
|
||||
-- allocation durable and bound to the Iota that requested it so a completed
|
||||
-- registration can safely be retried after any response is lost.
|
||||
CREATE TABLE registration_leases (
|
||||
token CHAR(36) CHARACTER SET ascii COLLATE ascii_bin NOT NULL PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL UNIQUE,
|
||||
iota_id BIGINT NOT NULL,
|
||||
expires_at DATETIME NOT NULL,
|
||||
completed_at DATETIME NULL,
|
||||
CONSTRAINT fk_registration_leases_iota
|
||||
FOREIGN KEY (iota_id) REFERENCES iotas (id),
|
||||
INDEX idx_registration_leases_expiry (expires_at)
|
||||
);
|
||||
8
migrations/003_registration_lease_request_id.sql
Normal file
8
migrations/003_registration_lease_request_id.sql
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
-- A relay retry uses the original MTP request ID. Make allocation idempotent
|
||||
-- for that authenticated Iota/request pair, so a lost response returns the
|
||||
-- same user ID and lease rather than allocating another one.
|
||||
ALTER TABLE registration_leases
|
||||
-- Existing leases predate retry correlation; leave their request ID NULL
|
||||
-- rather than assigning a shared sentinel that could violate uniqueness.
|
||||
ADD COLUMN request_id INT UNSIGNED NULL,
|
||||
ADD CONSTRAINT uk_registration_leases_iota_request UNIQUE (iota_id, request_id);
|
||||
Loading…
Reference in a new issue