2023-12-11 23:29:55 +00:00
|
|
|
--creating system table
|
2023-12-08 22:26:16 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS system (
|
|
|
|
`key` VARCHAR(32) PRIMARY KEY,
|
|
|
|
`value` TEXT
|
|
|
|
);
|
|
|
|
|
2023-12-11 23:29:55 +00:00
|
|
|
--creating roles table
|
|
|
|
CREATE TABLE IF NOT EXISTS roles (
|
|
|
|
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`name` VARCHAR(256) UNIQUE NOT NULL,
|
|
|
|
`color` INTEGER UNSIGNED DEFAULT 0
|
|
|
|
);
|
|
|
|
|
|
|
|
--creating accounts table
|
|
|
|
CREATE TABLE IF NOT EXISTS accounts (
|
|
|
|
`id` INTEGER UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`login` VARCHAR(256) UNIQUE NOT NULL,
|
|
|
|
`nick` VARCHAR(256),
|
|
|
|
`type` INTEGER UNSIGNED NOT NULL,
|
2023-12-20 22:42:13 +00:00
|
|
|
`password` VARCHAR(128),
|
|
|
|
`created` TIMESTAMP DEFAULT UTC_TIMESTAMP()
|
|
|
|
);
|
|
|
|
|
|
|
|
--creating role bindings table
|
|
|
|
CREATE TABLE IF NOT EXISTS roleBindings (
|
|
|
|
`account` INTEGER UNSIGNED NOT NULL,
|
2023-12-11 23:29:55 +00:00
|
|
|
`role` INTEGER UNSIGNED NOT NULL,
|
|
|
|
|
2023-12-20 22:42:13 +00:00
|
|
|
PRIMARY KEY (account, role),
|
|
|
|
FOREIGN KEY (account) REFERENCES accounts(id),
|
2023-12-11 23:29:55 +00:00
|
|
|
FOREIGN KEY (role) REFERENCES roles(id)
|
|
|
|
);
|
|
|
|
|
2023-12-20 22:42:13 +00:00
|
|
|
--creating sessings table
|
|
|
|
CREATE TABLE IF NOT EXISTS sessions (
|
|
|
|
`id` INTEGER AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`owner` INTEGER UNSIGNED NOT NULL,
|
|
|
|
`started` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
|
|
|
|
`latest` TIMESTAMP DEFAULT UTC_TIMESTAMP(),
|
|
|
|
`salt` CHAR(16),
|
|
|
|
`persist` BOOLEAN NOT NULL,
|
|
|
|
|
|
|
|
FOREIGN KEY (owner) REFERENCES accounts(id)
|
|
|
|
);
|
|
|
|
|
2023-12-11 23:29:55 +00:00
|
|
|
--creating defailt roles
|
|
|
|
INSERT IGNORE INTO roles (`name`)
|
2023-12-20 22:42:13 +00:00
|
|
|
VALUES ('root'),
|
|
|
|
('default');
|
2023-12-11 23:29:55 +00:00
|
|
|
|
|
|
|
--inserting initial version
|
2023-12-08 22:26:16 +00:00
|
|
|
INSERT INTO system (`key`, `value`) VALUES ('version', '0');
|
2023-12-11 23:29:55 +00:00
|
|
|
|
|
|
|
--recording initial time
|
|
|
|
INSERT INTO system (`key`, `value`) VALUES ('created', UTC_TIMESTAMP());
|