servnest/db/schema.sql

57 lines
2.1 KiB
MySQL
Raw Normal View History

2022-04-18 21:10:15 +00:00
BEGIN TRANSACTION;
2022-09-16 22:49:07 +00:00
CREATE TABLE IF NOT EXISTS "params" (
2022-11-07 18:40:40 +00:00
"name" TEXT NOT NULL UNIQUE,
"value" TEXT NOT NULL,
PRIMARY KEY("name")
);
2023-03-09 00:35:30 +00:00
INSERT INTO "params"("name", "value") VALUES('instance_bucket_tokens', '0');
INSERT INTO "params"("name", "value") VALUES('instance_bucket_last_update', '0');
INSERT INTO "params"("name", "value") VALUES('secret_key', '0');
INSERT INTO "params"("name", "value") VALUES('secret_key_last_change', '0');
INSERT INTO "params"("name", "value") VALUES('username_salt', '00000000000000000000000000000000'); -- Should be unique and secret ; generate one using `openssl rand -hex 16` ; can't be changed without breaking current accounts login
CREATE TABLE IF NOT EXISTS "users" (
"id" TEXT NOT NULL UNIQUE CHECK (LENGTH(id) = 64),
"username" TEXT NOT NULL UNIQUE,
"password" TEXT NOT NULL,
"registration_date" TEXT NOT NULL,
"bucket_tokens" INTEGER NOT NULL,
"bucket_last_update" INTEGER NOT NULL,
"type" TEXT NOT NULL,
2023-03-09 00:35:30 +00:00
"services" TEXT NOT NULL,
PRIMARY KEY("id")
2022-09-16 22:49:07 +00:00
);
CREATE TABLE IF NOT EXISTS "approval-keys" (
"key" TEXT NOT NULL UNIQUE,
PRIMARY KEY("key")
);
2022-04-18 21:10:15 +00:00
CREATE TABLE IF NOT EXISTS "registry" (
2022-11-07 18:40:40 +00:00
"domain" TEXT NOT NULL UNIQUE,
"username" TEXT NOT NULL,
"creation" TEXT NOT NULL,
PRIMARY KEY("domain"),
FOREIGN KEY("username") REFERENCES "users"("id")
2022-04-18 21:10:15 +00:00
);
CREATE TABLE IF NOT EXISTS "registry-history" (
"domain" TEXT NOT NULL,
"creation" TEXT NOT NULL,
"expiration" TEXT NOT NULL
);
2022-04-18 21:10:15 +00:00
CREATE TABLE IF NOT EXISTS "zones" (
2022-11-07 18:40:40 +00:00
"zone" TEXT NOT NULL UNIQUE,
"username" TEXT NOT NULL,
PRIMARY KEY("zone"),
FOREIGN KEY("username") REFERENCES "users"("id")
2022-04-18 21:10:15 +00:00
);
CREATE TABLE IF NOT EXISTS "sites" (
2022-11-07 18:40:40 +00:00
"username" TEXT NOT NULL,
"site_dir" TEXT NOT NULL,
"address" TEXT NOT NULL,
"type" TEXT NOT NULL,
2022-11-07 18:40:40 +00:00
"creation_date" TEXT NOT NULL,
UNIQUE("address", "type"),
UNIQUE("username", "site_dir", "type"),
PRIMARY KEY("address", "type"),
FOREIGN KEY("username") REFERENCES "users"("id")
2022-04-18 21:10:15 +00:00
);
COMMIT;