web-base/core/Configuration/database.sql

85 lines
2.4 KiB
MySQL
Raw Normal View History

2020-02-09 23:02:19 +01:00
--
-- API
--
2020-02-17 00:18:37 +01:00
CREATE TABLE IF NOT EXISTS Language (
`uid` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`code` VARCHAR(5) UNIQUE NOT NULL,
`name` VARCHAR(32) UNIQUE NOT NULL
);
INSERT INTO Language (`uid`, `code`, `name`) VALUES
(1, 'en_US', 'American English'),
(2, 'de_DE', 'Deutsch Standard')
ON DUPLICATE KEY UPDATE name=name;
2020-02-09 23:02:19 +01:00
CREATE TABLE IF NOT EXISTS User (
2020-02-17 00:18:37 +01:00
`uid` INTEGER NOT NULL AUTO_INCREMENT,
2020-04-01 15:22:59 +02:00
`email` VARCHAR(64) UNIQUE DEFAULT NULL,
2020-02-09 23:02:19 +01:00
`name` VARCHAR(32) UNIQUE NOT NULL,
`salt` varchar(16) NOT NULL,
`password` varchar(64) NOT NULL,
2020-02-17 00:18:37 +01:00
`language_id` int(11) DEFAULT 1,
PRIMARY KEY (`uid`),
2020-04-02 00:02:51 +02:00
FOREIGN KEY (`language_id`) REFERENCES `Language` (`uid`) ON DELETE SET NULL
2020-02-09 23:02:19 +01:00
);
CREATE TABLE IF NOT EXISTS UserInvitation (
2020-04-02 00:02:51 +02:00
`email` VARCHAR(64) NOT NULL,
2020-02-09 23:02:19 +01:00
`token` VARCHAR(36) UNIQUE NOT NULL,
`valid_until` DATETIME NOT NULL
);
2020-02-17 00:18:37 +01:00
CREATE TABLE IF NOT EXISTS UserToken (
`user_id` INTEGER NOT NULL,
`token` VARCHAR(36) NOT NULL,
`type` ENUM('password_reset', 'confirmation') NOT NULL,
`valid_until` DATETIME NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `User` (`uid`) ON DELETE CASCADE
);
2020-02-09 23:02:19 +01:00
CREATE TABLE IF NOT EXISTS `Group` (
2020-02-17 00:18:37 +01:00
`gid` INTEGER NOT NULL AUTO_INCREMENT,
`name` VARCHAR(32) NOT NULL,
PRIMARY KEY (`gid`),
UNIQUE (`name`)
2020-02-09 23:02:19 +01:00
);
INSERT INTO `Group` (gid, name) VALUES (1, "Default"), (2, "Administrator")
ON DUPLICATE KEY UPDATE name=name;
CREATE TABLE IF NOT EXISTS UserGroup (
`uid` INTEGER NOT NULL,
`gid` INTEGER NOT NULL,
2020-02-17 00:18:37 +01:00
UNIQUE (`uid`, `gid`),
FOREIGN KEY (`uid`) REFERENCES `User` (`uid`),
FOREIGN KEY (`gid`) REFERENCES `Group` (`gid`)
2020-02-09 23:02:19 +01:00
);
2020-02-10 00:52:25 +01:00
CREATE TABLE IF NOT EXISTS Session (
2020-02-17 00:18:37 +01:00
`uid` int(11) NOT NULL AUTO_INCREMENT,
2020-02-09 23:02:19 +01:00
`expires` timestamp NOT NULL,
2020-02-17 00:18:37 +01:00
`user_id` int(11) NOT NULL,
2020-02-09 23:02:19 +01:00
`ipAddress` varchar(45) NOT NULL,
`os` varchar(64) NOT NULL,
2020-02-17 00:18:37 +01:00
`browser` varchar(64) NOT NULL,
`data` JSON NOT NULL DEFAULT '{}',
`stay_logged_in` BOOLEAN DEFAULT TRUE,
PRIMARY KEY (`uid`),
FOREIGN KEY (`user_id`) REFERENCES `User` (`uid`) ON DELETE CASCADE
2020-02-09 23:02:19 +01:00
);
CREATE TABLE IF NOT EXISTS ApiKey (
2020-02-17 00:18:37 +01:00
`uid` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
2020-02-09 23:02:19 +01:00
`api_key` VARCHAR(64) NOT NULL,
2020-02-17 00:18:37 +01:00
`valid_until` DATETIME NOT NULL,
PRIMARY KEY (`uid`),
FOREIGN KEY (`user_id`) REFERENCES `User` (`uid`)
2020-02-09 23:02:19 +01:00
);
CREATE TABLE IF NOT EXISTS ExternalSiteCache (
2020-04-01 15:22:59 +02:00
`url` VARCHAR(256) UNIQUE,
2020-02-09 23:02:19 +01:00
`data` TEXT NOT NULL,
2020-04-01 15:22:59 +02:00
`expires` DATETIME DEFAULT NULL,
2020-02-09 23:02:19 +01:00
);