capsul-flask/capsulflask/schema_migrations/02_up_accounts_vms_etc.sql

82 lines
2.8 KiB
MySQL
Raw Normal View History

2020-05-10 01:36:14 +00:00
CREATE TABLE accounts (
email TEXT PRIMARY KEY NOT NULL,
created TIMESTAMP NOT NULL DEFAULT NOW()
);
CREATE TABLE os_images (
id TEXT PRIMARY KEY NOT NULL,
template_image_file_name TEXT NOT NULL,
description TEXT NOT NULL
);
CREATE TABLE vm_sizes (
id TEXT PRIMARY KEY NOT NULL,
dollars_per_month NUMERIC(8, 2) NOT NULL,
2020-05-11 01:23:00 +00:00
vcpus INTEGER NOT NULL,
memory_mb INTEGER NOT NULL,
bandwidth_gb_per_month INTEGER NOT NULL
);
CREATE TABLE ssh_public_keys (
id SERIAL PRIMARY KEY,
email TEXT REFERENCES accounts(email) ON DELETE RESTRICT,
name TEXT NOT NULL,
content TEXT NOT NULL,
UNIQUE (id, email)
2020-05-10 01:36:14 +00:00
);
CREATE TABLE vms (
id TEXT PRIMARY KEY NOT NULL,
email TEXT REFERENCES accounts(email) ON DELETE RESTRICT,
os TEXT REFERENCES os_images(id) ON DELETE RESTRICT,
size TEXT REFERENCES vm_sizes(id) ON DELETE RESTRICT,
2020-05-11 01:23:00 +00:00
last_seen_ipv4 TEXT,
last_seen_ipv6 TEXT,
created TIMESTAMP NOT NULL DEFAULT NOW(),
deleted TIMESTAMP,
UNIQUE (id, email)
);
CREATE TABLE vm_ssh_public_key (
ssh_public_key_id INTEGER NOT NULL,
email TEXT NOT NULL,
vm_id TEXT NOT NULL,
FOREIGN KEY (email, ssh_public_key_id) REFERENCES ssh_public_keys(email, id) ON DELETE RESTRICT,
FOREIGN KEY (email, vm_id) REFERENCES vms(email, id) ON DELETE RESTRICT,
PRIMARY KEY (email, vm_id, ssh_public_key_id)
2020-05-10 01:36:14 +00:00
);
CREATE TABLE payments (
email TEXT REFERENCES accounts(email) ON DELETE RESTRICT,
2020-05-10 03:59:22 +00:00
created TIMESTAMP NOT NULL DEFAULT NOW(),
2020-05-10 18:51:54 +00:00
dollars NUMERIC(8, 2) NOT NULL,
2020-05-10 01:36:14 +00:00
PRIMARY KEY (email, created)
);
CREATE TABLE login_tokens (
2020-05-10 01:36:14 +00:00
email TEXT REFERENCES accounts(email) ON DELETE RESTRICT,
2020-05-10 03:59:22 +00:00
created TIMESTAMP NOT NULL DEFAULT NOW(),
2020-05-10 01:36:14 +00:00
token TEXT NOT NULL,
PRIMARY KEY (email, created)
);
INSERT INTO os_images (id, template_image_file_name, description)
VALUES ('debian10', 'debian-10-genericcloud-amd64-20191117-80.qcow2', 'Debian 10 (Buster)'),
('centos7', 'CentOS-7-x86_64-GenericCloud.qcow2', 'CentOS 7'),
('centos8', 'CentOS-8-GenericCloud-8.1.1911-20200113.3.x86_64.qcow2', 'CentOS 8'),
('ubuntu18', 'ubuntu-18.04-minimal-cloudimg-amd64.img', 'Ubuntu 18.04 LTS (Bionic Beaver)'),
('alpine311', 'alpine-cloud-2020-04-18.qcow2', 'Alpine Linux 3.11'),
('openbsd66', 'openbsd-cloud-2020-05.qcow2', 'OpenBSD 6.6'),
('guix110', 'guixsystem-cloud-2020-05.qcow2', 'Guix System 1.1.0');
2020-05-11 01:23:00 +00:00
INSERT INTO vm_sizes (id, dollars_per_month, memory_mb, vcpus, bandwidth_gb_per_month)
VALUES ('f1-s', 5.33, 512, 1, 500),
('f1-m', 7.16, 1024, 1, 1000),
('f1-l', 8.92, 2048, 1, 2000),
('f1-x', 16.16, 4096, 2, 4000),
('f1-xx', 29.66, 8192, 4, 8000),
('f1-xxx', 57.58, 16384, 8, 16000);
2020-05-10 01:36:14 +00:00
UPDATE schemaversion SET version = 2;