-
Notifications
You must be signed in to change notification settings - Fork 336
/
Copy pathMySQL.sql
82 lines (68 loc) · 2.59 KB
/
MySQL.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
82
create table `abilities` (
`id` int unsigned not null auto_increment primary key,
`name` varchar(255) not null,
`title` varchar(255) null,
`entity_id` int unsigned null,
`entity_type` varchar(255) null,
`only_owned` tinyint(1) not null default '0',
`options` json null,
`scope` int null,
`created_at` timestamp null,
`updated_at` timestamp null
) default character set utf8mb4 collate utf8mb4_unicode_ci;
alter table `abilities`
add index `abilities_scope_index`(`scope`);
create table `roles` (
`id` int unsigned not null auto_increment primary key,
`name` varchar(255) not null,
`title` varchar(255) null,
`level` int unsigned null,
`scope` int null,
`created_at` timestamp null,
`updated_at` timestamp null
) default character set utf8mb4 collate utf8mb4_unicode_ci;
alter table `roles`
add unique `roles_name_unique`(`name`, `scope`);
alter table `roles`
add index `roles_scope_index`(`scope`);
create table `assigned_roles` (
`id` int unsigned not null auto_increment primary key,
`role_id` int unsigned not null,
`entity_id` int unsigned not null,
`entity_type` varchar(255) not null,
`restricted_to_id` int unsigned null,
`restricted_to_type` varchar(255) null,
`scope` int null
) default character set utf8mb4 collate utf8mb4_unicode_ci;
alter table `assigned_roles`
add index `assigned_roles_entity_index`(`entity_id`, `entity_type`, `scope`);
alter table `assigned_roles`
add constraint `assigned_roles_role_id_foreign`
foreign key (`role_id`)
references `roles` (`id`)
on delete cascade
on update cascade;
alter table `assigned_roles`
add index `assigned_roles_role_id_index`(`role_id`);
alter table `assigned_roles`
add index `assigned_roles_scope_index`(`scope`);
create table `permissions` (
`id` int unsigned not null auto_increment primary key,
`ability_id` int unsigned not null,
`entity_id` int unsigned null,
`entity_type` varchar(255) null,
`forbidden` tinyint(1) not null default '0',
`scope` int null
) default character set utf8mb4 collate utf8mb4_unicode_ci;
alter table `permissions`
add index `permissions_entity_index`(`entity_id`, `entity_type`, `scope`);
alter table `permissions`
add constraint `permissions_ability_id_foreign`
foreign key (`ability_id`)
references `abilities` (`id`)
on delete cascade
on update cascade;
alter table `permissions`
add index `permissions_ability_id_index`(`ability_id`);
alter table `permissions`
add index `permissions_scope_index`(`scope`);