first steps towards multiple hosts -- schema & heartbeat

This commit is contained in:
2020-12-10 20:32:43 -06:00
parent 7f1f5ac976
commit 44738c78a9
4 changed files with 87 additions and 0 deletions

View File

@ -0,0 +1,11 @@
DROP TABLE host_operation;
DROP TABLE operations;
ALTER TABLE vms DROP COLUMN host;
DROP TABLE hosts;
UPDATE schemaversion SET version = 8;

View File

@ -0,0 +1,33 @@
CREATE TABLE hosts (
id TEXT PRIMARY KEY NOT NULL,
last_health_check TIMESTAMP NOT NULL DEFAULT NOW(),
token TEXT NOT NULL
);
INSERT INTO hosts (id, token) VALUES ('baikal', 'changeme');
ALTER TABLE vms
ADD COLUMN host TEXT REFERENCES hosts(id) ON DELETE RESTRICT DEFAULT 'baikal';
CREATE TABLE operations (
id TEXT PRIMARY KEY NOT NULL,
email TEXT REFERENCES accounts(email) ON DELETE RESTRICT,
assigned_host TEXT NULL,
host_status TEXT NULL,
created TIMESTAMP NOT NULL DEFAULT NOW(),
assigned TIMESTAMP NULL,
completed TIMESTAMP NULL,
payload TEXT NOT NULL,
);
CREATE TABLE host_operation (
host TEXT NOT NULL,
operation TEXT NOT NULL,
assignment_status TEXT NULL,
assignment_status_timestamp TIMESTAMP,
PRIMARY KEY (host, operation)
);
UPDATE schemaversion SET version = 9;