Semaphore/db/sql/migrations/v0.0.0.sql

113 lines
3.1 KiB
MySQL
Raw Normal View History

2020-11-28 22:49:44 +01:00
create table `user` (
`id` integer primary key autoincrement,
2016-04-29 09:33:08 +02:00
`created` datetime not null,
2020-11-28 22:49:44 +01:00
`username` varchar(255) not null,
`name` varchar(255) not null,
`email` varchar(255) not null,
`password` varchar(255) not null,
unique (`username`),
unique (`email`)
);
create table `project` (
`id` integer primary key autoincrement,
`created` datetime not null,
`name` varchar(255) not null
);
create table `project__user` (
`project_id` int not null,
`user_id` int not null,
2021-08-24 17:20:34 +02:00
`admin` boolean not null default false,
2020-11-28 22:49:44 +01:00
unique (`project_id`, `user_id`),
2016-04-02 14:40:07 +02:00
foreign key (`project_id`) references project(`id`) on delete cascade,
2020-11-28 22:49:44 +01:00
foreign key (`user_id`) references `user`(`id`) on delete cascade
);
2016-01-05 00:32:53 +01:00
2020-11-28 22:49:44 +01:00
create table `access_key` (
`id` integer primary key autoincrement,
2016-04-02 14:40:07 +02:00
`name` varchar(255) not null,
2020-11-28 22:49:44 +01:00
`type` varchar(255) not null,
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
`project_id` int null,
2016-04-02 14:40:07 +02:00
`key` text null,
`secret` text null,
foreign key (`project_id`) references project(`id`) on delete set null
2020-11-28 22:49:44 +01:00
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `project__repository` (
`id` integer primary key autoincrement,
`project_id` int not null,
2016-04-02 14:40:07 +02:00
`git_url` text not null,
2020-11-28 22:49:44 +01:00
`ssh_key_id` int not null,
2016-04-02 14:40:07 +02:00
foreign key (`project_id`) references project(`id`) on delete cascade,
foreign key (`ssh_key_id`) references access_key(`id`)
2020-11-28 22:49:44 +01:00
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `project__inventory` (
`id` integer primary key autoincrement,
`project_id` int not null,
`type` varchar(255) not null,
`key_id` int null,
2016-04-02 14:40:07 +02:00
`inventory` longtext not null,
foreign key (`project_id`) references project(`id`) on delete cascade,
foreign key (`key_id`) references access_key(`id`)
2020-11-28 22:49:44 +01:00
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `project__environment` (
`id` integer primary key autoincrement,
`project_id` int not null,
2016-04-02 14:40:07 +02:00
`password` varchar(255) null,
`json` longtext not null,
foreign key (`project_id`) references project(`id`) on delete cascade
2020-11-28 22:49:44 +01:00
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `project__template` (
`id` integer primary key autoincrement,
`ssh_key_id` int not null,
`project_id` int not null,
`inventory_id` int not null,
`repository_id` int not null,
`environment_id` int null,
`playbook` varchar(255) not null,
2016-04-02 14:40:07 +02:00
foreign key (`project_id`) references project(`id`) on delete cascade,
foreign key (`ssh_key_id`) references access_key(`id`),
foreign key (`inventory_id`) references project__inventory(`id`),
foreign key (`repository_id`) references project__repository(`id`),
foreign key (`environment_id`) references project__environment(`id`)
2020-11-28 22:49:44 +01:00
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `project__template_schedule` (
`template_id` int primary key,
2016-04-02 14:40:07 +02:00
`cron_format` varchar(255) not null,
foreign key (`template_id`) references project__template(`id`) on delete cascade
2020-11-28 22:49:44 +01:00
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `task` (
`id` integer primary key autoincrement,
`template_id` int not null,
2016-04-02 14:40:07 +02:00
`status` varchar(255) not null,
2020-11-28 22:49:44 +01:00
`playbook` varchar(255) not null,
`environment` longtext null,
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
foreign key (`template_id`) references project__template(`id`) on delete cascade
);
2016-04-02 14:40:07 +02:00
2020-11-28 22:49:44 +01:00
create table `task__output` (
`task_id` int not null,
`task` varchar(255) not null,
2016-04-29 09:33:08 +02:00
`time` datetime not null,
2016-04-02 14:40:07 +02:00
`output` longtext not null,
2020-11-28 22:49:44 +01:00
unique (`task_id`, `time`),
2016-04-02 14:40:07 +02:00
foreign key (`task_id`) references task(`id`) on delete cascade
2020-11-28 22:49:44 +01:00
);