Files
cloudron-box/migrations/schema.sql
T

134 lines
4.7 KiB
SQL
Raw Normal View History

#### WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
#### This file is not used by any code and is here to document the latest schema
#### General ideas
#### Default char set is utf8 and DEFAULT COLLATE is utf8_bin. Collate affects comparisons in WHERE and ORDER
#### Strict mode is enabled
#### VARCHAR - stored as part of table row (use for strings)
#### TEXT - stored offline from table row (use for strings)
#### BLOB - stored offline from table row (use for binary data)
#### https://dev.mysql.com/doc/refman/5.0/en/storage-requirements.html
CREATE TABLE IF NOT EXISTS users(
id VARCHAR(128) NOT NULL UNIQUE,
2016-04-05 10:54:09 +02:00
username VARCHAR(254) UNIQUE,
email VARCHAR(254) NOT NULL UNIQUE,
password VARCHAR(1024) NOT NULL,
salt VARCHAR(512) NOT NULL,
createdAt VARCHAR(512) NOT NULL,
modifiedAt VARCHAR(512) NOT NULL,
admin INTEGER NOT NULL,
2016-01-19 23:40:33 -08:00
displayName VARCHAR(512) DEFAULT '',
2016-05-06 13:55:03 +02:00
showTutorial BOOLEAN DEFAULT 0,
PRIMARY KEY(id));
2016-02-07 19:24:07 -08:00
CREATE TABLE IF NOT EXISTS groups(
id VARCHAR(128) NOT NULL UNIQUE,
2016-09-27 21:11:41 +02:00
name VARCHAR(254) NOT NULL UNIQUE,
2016-02-07 19:24:07 -08:00
PRIMARY KEY(id));
2016-02-08 08:55:37 -08:00
CREATE TABLE IF NOT EXISTS groupMembers(
groupId VARCHAR(128) NOT NULL,
userId VARCHAR(128) NOT NULL,
FOREIGN KEY(groupId) REFERENCES groups(id),
FOREIGN KEY(userId) REFERENCES users(id));
CREATE TABLE IF NOT EXISTS tokens(
accessToken VARCHAR(128) NOT NULL UNIQUE,
identifier VARCHAR(128) NOT NULL,
clientId VARCHAR(128),
scope VARCHAR(512) NOT NULL,
expires BIGINT NOT NULL, // FIXME: make this a timestamp
PRIMARY KEY(accessToken));
CREATE TABLE IF NOT EXISTS clients(
2015-10-15 16:31:45 -07:00
id VARCHAR(128) NOT NULL UNIQUE, // prefixed with cid- to identify token easily in auth routes
appId VARCHAR(128) NOT NULL,
type VARCHAR(16) NOT NULL,
clientSecret VARCHAR(512) NOT NULL,
redirectURI VARCHAR(512) NOT NULL,
scope VARCHAR(512) NOT NULL,
PRIMARY KEY(id));
CREATE TABLE IF NOT EXISTS apps(
id VARCHAR(128) NOT NULL UNIQUE,
appStoreId VARCHAR(128) NOT NULL,
installationState VARCHAR(512) NOT NULL,
2016-06-20 22:30:17 -05:00
installationProgress TEXT,
runState VARCHAR(512),
health VARCHAR(128),
containerId VARCHAR(128),
manifestJson TEXT,
httpPort INTEGER, // this is the nginx proxy port and not manifest.httpPort
location VARCHAR(128) NOT NULL UNIQUE,
dnsRecordId VARCHAR(512),
2016-05-27 11:10:36 -07:00
accessRestrictionJson TEXT, // { users: [ ], groups: [ ] }
2015-10-13 09:36:51 +02:00
oauthProxy BOOLEAN DEFAULT 0,
createdAt TIMESTAMP(2) NOT NULL DEFAULT CURRENT_TIMESTAMP,
2016-02-05 15:03:45 +01:00
memoryLimit BIGINT DEFAULT 0,
2016-04-19 00:02:45 -07:00
altDomain VARCHAR(256),
2016-07-14 15:04:52 +02:00
xFrameOptions VARCHAR(512),
2016-06-13 19:19:28 -07:00
lastBackupId VARCHAR(128), // tracks last valid backup, can be removed
2015-10-09 11:08:16 -07:00
2016-06-13 19:19:28 -07:00
oldConfigJson TEXT, // used to pass old config for apptask, can be removed when we use a queue
2015-10-09 11:08:16 -07:00
PRIMARY KEY(id));
CREATE TABLE IF NOT EXISTS appPortBindings(
hostPort INTEGER NOT NULL UNIQUE,
environmentVariable VARCHAR(128) NOT NULL,
appId VARCHAR(128) NOT NULL,
FOREIGN KEY(appId) REFERENCES apps(id),
PRIMARY KEY(hostPort));
CREATE TABLE IF NOT EXISTS authcodes(
authCode VARCHAR(128) NOT NULL UNIQUE,
userId VARCHAR(128) NOT NULL,
clientId VARCHAR(128) NOT NULL,
expiresAt BIGINT NOT NULL, // ## FIXME: make this a timestamp
PRIMARY KEY(authCode));
CREATE TABLE IF NOT EXISTS settings(
name VARCHAR(128) NOT NULL UNIQUE,
value VARCHAR(512),
PRIMARY KEY(name));
CREATE TABLE IF NOT EXISTS appAddonConfigs(
appId VARCHAR(128) NOT NULL,
addonId VARCHAR(32) NOT NULL,
value VARCHAR(512) NOT NULL,
FOREIGN KEY(appId) REFERENCES apps(id));
2016-03-07 09:26:26 -08:00
CREATE TABLE IF NOT EXISTS backups(
2016-04-29 23:28:54 -07:00
filename VARCHAR(128) NOT NULL,
2016-03-07 09:26:26 -08:00
creationTime TIMESTAMP,
version VARCHAR(128) NOT NULL, /* app version or box version */
type VARCHAR(16) NOT NULL, /* 'box' or 'app' */
dependsOn VARCHAR(4096), /* comma separate list of objects this backup depends on */
state VARCHAR(16) NOT NULL,
PRIMARY KEY (filename));
2016-04-29 23:28:54 -07:00
CREATE TABLE IF NOT EXISTS eventlog(
id VARCHAR(128) NOT NULL,
action VARCHAR(128) NOT NULL,
2016-05-01 11:50:55 -07:00
source JSON, /* { userId, username, ip }. userId can be null for cron,sysadmin */
data JSON, /* free flowing json based on action */
2016-06-02 19:43:23 -07:00
creationTime TIMESTAMP, /* FIXME: precision must be TIMESTAMP(2) */
2016-04-29 23:28:54 -07:00
PRIMARY KEY (id));
2016-05-26 18:02:22 -07:00
2016-05-27 22:28:56 -07:00
/* Future fields:
* accessRestriction - to determine who can access it. So this has foreign keys
* quota - per mailbox quota
*/
2016-05-26 18:02:22 -07:00
CREATE TABLE IF NOT EXISTS mailboxes(
2016-05-27 19:20:42 -07:00
name VARCHAR(128) NOT NULL,
2016-09-21 14:12:04 -07:00
ownerId VARCHAR(128) NOT NULL, /* app id or user id or group id */
ownerType VARCHAR(16) NOT NULL, /* 'app' or 'user' or 'group' */
2016-05-27 19:20:42 -07:00
aliasTarget VARCHAR(128), /* the target name type is an alias */
2016-05-26 18:02:22 -07:00
creationTime TIMESTAMP,
2016-09-20 13:51:00 -07:00
PRIMARY KEY (name));