-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.sql
81 lines (77 loc) · 2.88 KB
/
schema.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
-- -----------------------------------------------------
-- Table `users`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `users` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`email` VARCHAR(255) NOT NULL ,
`first_name` VARCHAR(255) NOT NULL ,
`last_name` VARCHAR(255) NOT NULL ,
`password` VARCHAR(65) NOT NULL ,
`salt` VARCHAR(255) DEFAULT NULL ,
-- Additional fields can be added ...
PRIMARY KEY (`id`) ,
UNIQUE INDEX `uniq_email` (`email` ASC))
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `user_roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `user_roles` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`name` VARCHAR(32) NULL ,
-- Additional fields can be added ...
PRIMARY KEY (`id`) ,
UNIQUE INDEX `uniq_name` (`name` ASC));
-- -----------------------------------------------------
-- Table `users_user_roles`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `users_user_roles` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`user_id` INT(11) UNSIGNED NOT NULL ,
`user_role_id` INT(11) UNSIGNED NOT NULL ,
PRIMARY KEY (`id`) ,
INDEX `fk_users_user_roles_user_id` (`user_id` ASC) ,
INDEX `fk_users_user_roles_user_role_id` (`user_role_id` ASC) ,
CONSTRAINT `fk_users_user_roles_user_id`
FOREIGN KEY (`user_id`)
REFERENCES `users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION,
CONSTRAINT `fk_users_user_roles_user_role_id`
FOREIGN KEY (`user_role_id`)
REFERENCES `user_roles` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
-- -----------------------------------------------------
-- Table `user_logins`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `user_logins` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`ip` VARCHAR(65) NOT NULL ,
`agent` VARCHAR(65) NOT NULL ,
`login` VARCHAR(255) NOT NULL ,
`created` INT(11) UNSIGNED NOT NULL ,
`user_id` INT(11) DEFAULT NULL ,
PRIMARY KEY (`id`))
DEFAULT CHARACTER SET = utf8;
-- -----------------------------------------------------
-- Table `user_tokens`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `user_tokens` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`token` VARCHAR(40) NOT NULL ,
`user_id` INT(11) UNSIGNED NOT NULL ,
`user_agent` VARCHAR(64) NOT NULL ,
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL ,
`expires` INT(11) UNSIGNED NOT NULL ,
PRIMARY KEY (`id`) ,
UNIQUE INDEX `uniq_token` (`token`) ,
INDEX `fk_user_tokens_user_id` (`user_id` ASC) ,
CONSTRAINT `fk_user_tokens_user_id`
FOREIGN KEY (`user_id`)
REFERENCES `users` (`id`)
ON DELETE CASCADE
ON UPDATE NO ACTION)
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;