capsul-flask/capsulflask/schema_migrations/09_up_introduce_hosts.sql

33 lines
938 B
SQL

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;