-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize-database-test.sql
46 lines (38 loc) · 1.07 KB
/
initialize-database-test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
DROP DATABASE IF EXISTS `mine-asterisk-test`;
CREATE DATABASE `mine-asterisk-test`;
USE `mine-asterisk-test`;
CREATE TABLE player (
id INT NOT NULL AUTO_INCREMENT,
uuid VARCHAR(36) NOT NULL,
PRIMARY KEY (id),
UNIQUE `unique_uuid` (`uuid`)
);
CREATE TABLE permission (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(20) NOT NULL,
PRIMARY KEY (id),
UNIQUE `unique_name` (`name`)
);
CREATE TABLE access (
player_id INT NOT NULL,
permission_id INT NOT NULL,
CONSTRAINT `foreign_key_access_player_player_id` FOREIGN KEY (player_id)
REFERENCES player (id),
CONSTRAINT `foreign_key_access_permission_permission_id` FOREIGN KEY (permission_id)
REFERENCES permission (id),
UNIQUE `unique_access` (`player_id`, `permission_id`)
);
INSERT INTO permission (`id`, `name`) VALUES
(1, "team.leader"),
(2, "team.member");
DELIMITER //
CREATE PROCEDURE reset()
BEGIN
DELETE FROM access;
DELETE FROM player;
DELETE FROM permission;
INSERT INTO permission (`id`, `name`) VALUES
(1, "team.leader"),
(2, "team.member");
END //
DELIMITER ;