BEGIN;


--
-- Table: rights
--

create table if not exists "rights" (
    "id" bigserial not null primary key,
    "target" varchar(255),
    "action" varchar(255),
    "category" varchar(255),
    "fine_param" boolean);

--
-- Table: groups
--

create table if not exists "groups" (
    "id" bigserial not null primary key ,
    "name" varchar(255) unique);

--
-- Table: user_groups
--

create table if not exists "user_groups" (
    "user_id" bigint not null,
    "group_id" bigint not null, primary key ("user_id", "group_id"));

--
-- Table: owner_rights
--

create table if not exists "owner_rights" (
    "owner_type" varchar(255) not null,
    "owner_id" bigint not null,
    "right_id" bigint not null, primary key ("owner_type", "owner_id", "right_id"));

insert into rights
    values
        (1,'site','view','infrastructure',false),
        (2,'site','edit','infrastructure',false),
        (3,'site','delete','infrastructure',false),
        (4,'route','view','infrastructure',false),
        (5,'route','edit','infrastructure',false),
        (6,'route','delete','infrastructure',false),
        (7,'instance','view','infrastructure',false),
        (8,'instance','edit','infrastructure',false),
        (9,'instance','delete','infrastructure',false),
        (10,'flow','view','infrastructure',false),
        (11,'flow','edit','infrastructure',false),
        (12,'flow','delete','infrastructure',false),
--        (13,'monitoring','restart','monitoring',false),
--        (14,'monitoring','stop','monitoring',false),
        (15,'monitoring','access','monitoring',false),
        (16,'administration','access','administration',false),
        (17,'installer','install','installation',false),
        (18,'reporting','access','reporting',false);

insert into groups
    values (1,'administrateurs');

insert into user_groups
    values(1,1);

insert into owner_rights(owner_type,owner_id,right_id)
    values
        ('group',1,1),
        ('group',1,2),
        ('group',1,3),
        ('group',1,4),
        ('group',1,5),
        ('group',1,6),
        ('group',1,7),
        ('group',1,8),
        ('group',1,9),
        ('group',1,10),
        ('group',1,11),
        ('group',1,12),
--        ('group',1,13),
--        ('group',1,14),
        ('group',1,15),
        ('group',1,16),
        ('group',1,17),
        ('group',1,18);

alter sequence groups_id_seq restart with 2;
alter sequence rights_id_seq restart with 19;

COMMIT;