2023-05-30 03:26:46 +00:00
|
|
|
-- migrate:up
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `jwt_keys`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`public_key` TEXT NOT NULL,
|
|
|
|
`private_key` TEXT NOT NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `user`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`nickname` VARCHAR(50) NOT NULL,
|
|
|
|
`email` VARCHAR(255) NOT NULL,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_system` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`is_disabled` BOOLEAN NOT NULL DEFAULT FALSE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `capability`
|
|
|
|
(
|
|
|
|
`name` VARCHAR(50) PRIMARY KEY,
|
|
|
|
UNIQUE (`name`)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `user_has_capability`
|
|
|
|
(
|
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`capability_name` VARCHAR(50) NOT NULL,
|
|
|
|
UNIQUE (`user_id`, `capability_name`),
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`capability_name`) REFERENCES `capability`(`name`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `auth`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`type` VARCHAR(50) NOT NULL,
|
|
|
|
`secret` VARCHAR(255) NOT NULL,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE,
|
2023-05-30 03:26:46 +00:00
|
|
|
UNIQUE (`user_id`, `type`)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `setting`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`description` VARCHAR(255) NOT NULL DEFAULT '',
|
|
|
|
`value` TEXT NOT NULL,
|
|
|
|
UNIQUE (`name`)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `audit_log`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`object_type` VARCHAR(50) NOT NULL,
|
|
|
|
`object_id` INT NOT NULL,
|
|
|
|
`action` VARCHAR(50) NOT NULL,
|
|
|
|
`meta` TEXT NOT NULL,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `certificate_authority`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`acmesh_server` VARCHAR(255) NOT NULL DEFAULT '',
|
|
|
|
`ca_bundle` VARCHAR(255) NOT NULL DEFAULT '',
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_wildcard_supported` BOOLEAN NOT NULL DEFAULT FALSE, -- specific to each CA, acme v1 doesn't usually have wildcards
|
2023-05-30 03:26:46 +00:00
|
|
|
`max_domains` INT NOT NULL DEFAULT 5, -- per request
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_readonly` BOOLEAN NOT NULL DEFAULT FALSE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `dns_provider`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`acmesh_name` VARCHAR(50) NOT NULL,
|
|
|
|
`dns_sleep` INT NOT NULL DEFAULT 0,
|
|
|
|
`meta` TEXT NOT NULL,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
2023-05-30 11:18:12 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS `certificate`
|
2023-05-30 03:26:46 +00:00
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`type` VARCHAR(50) NOT NULL, -- custom,dns,http
|
2023-05-30 11:18:12 +00:00
|
|
|
`certificate_authority_id` INT, -- null for a custom cert
|
2023-05-30 03:26:46 +00:00
|
|
|
`dns_provider_id` INT, -- 0, for a http or custom cert
|
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`domain_names` TEXT NOT NULL,
|
2023-05-30 12:26:44 +00:00
|
|
|
`expires_on` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 03:26:46 +00:00
|
|
|
`status` VARCHAR(50) NOT NULL, -- ready,requesting,failed,provided
|
|
|
|
`error_message` TEXT NOT NULL,
|
|
|
|
`meta` TEXT NOT NULL,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_ecc` BOOLEAN NOT NULL DEFAULT FALSE,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`certificate_authority_id`) REFERENCES `certificate_authority`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`dns_provider_id`) REFERENCES `dns_provider`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `stream`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`listen_interface` VARCHAR(50) NOT NULL,
|
|
|
|
`incoming_port` INT NOT NULL,
|
|
|
|
`tcp_forwarding` INT NOT NULL DEFAULT 0,
|
|
|
|
`udp_forwarding` INT NOT NULL DEFAULT 0,
|
|
|
|
`advanced_config` TEXT NOT NULL,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_disabled` BOOLEAN NOT NULL DEFAULT FALSE,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `nginx_template`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`type` VARCHAR(50) NOT NULL,
|
|
|
|
`template` TEXT NOT NULL,
|
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `upstream`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`nginx_template_id` INT NOT NULL,
|
2023-05-30 05:51:57 +00:00
|
|
|
`ip_hash` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`ntlm` BOOLEAN NOT NULL DEFAULT FALSE,
|
2023-05-30 03:26:46 +00:00
|
|
|
`keepalive` INT NOT NULL DEFAULT 0,
|
|
|
|
`keepalive_requests` INT NOT NULL DEFAULT 0,
|
|
|
|
`keepalive_time` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`keepalive_timeout` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`advanced_config` TEXT NOT NULL,
|
|
|
|
`status` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`error_message` TEXT NOT NULL,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`nginx_template_id`) REFERENCES `nginx_template`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `upstream_server`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`upstream_id` INT NOT NULL,
|
|
|
|
`server` VARCHAR(50) NOT NULL,
|
|
|
|
`weight` INT NOT NULL DEFAULT 0,
|
|
|
|
`max_conns` INT NOT NULL DEFAULT 0,
|
|
|
|
`max_fails` INT NOT NULL DEFAULT 0,
|
|
|
|
`fail_timeout` INT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_backup` BOOLEAN NOT NULL DEFAULT FALSE,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`upstream_id`) REFERENCES `upstream`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS `access_list`
|
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`name` VARCHAR(50) NOT NULL,
|
|
|
|
`meta` TEXT NOT NULL,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
2023-05-30 12:26:44 +00:00
|
|
|
CREATE TABLE IF NOT EXISTS `host`
|
2023-05-30 03:26:46 +00:00
|
|
|
(
|
|
|
|
`id` INT AUTO_INCREMENT PRIMARY KEY,
|
|
|
|
`created_at` BIGINT NOT NULL DEFAULT 0,
|
|
|
|
`updated_at` BIGINT NOT NULL DEFAULT 0,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_deleted` INT NOT NULL DEFAULT 0, -- int on purpose, gormism
|
2023-05-30 03:26:46 +00:00
|
|
|
`user_id` INT NOT NULL,
|
|
|
|
`type` VARCHAR(50) NOT NULL,
|
|
|
|
`nginx_template_id` INT NOT NULL,
|
|
|
|
`listen_interface` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`domain_names` TEXT NOT NULL,
|
2023-05-30 11:18:12 +00:00
|
|
|
`upstream_id` INT,
|
2023-05-30 03:26:46 +00:00
|
|
|
`proxy_scheme` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`proxy_host` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`proxy_port` INT NOT NULL DEFAULT 0,
|
2023-05-30 11:18:12 +00:00
|
|
|
`certificate_id` INT,
|
|
|
|
`access_list_id` INT,
|
2023-05-30 05:51:57 +00:00
|
|
|
`ssl_forced` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`caching_enabled` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`block_exploits` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`allow_websocket_upgrade` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`http2_support` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`hsts_enabled` BOOLEAN NOT NULL DEFAULT FALSE,
|
|
|
|
`hsts_subdomains` BOOLEAN NOT NULL DEFAULT FALSE,
|
2023-05-30 03:26:46 +00:00
|
|
|
`paths` TEXT NOT NULL,
|
|
|
|
`advanced_config` TEXT NOT NULL,
|
|
|
|
`status` VARCHAR(50) NOT NULL DEFAULT '',
|
|
|
|
`error_message` TEXT NOT NULL,
|
2023-05-30 05:51:57 +00:00
|
|
|
`is_disabled` BOOLEAN NOT NULL DEFAULT FALSE,
|
2023-05-30 08:11:48 +00:00
|
|
|
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`nginx_template_id`) REFERENCES `nginx_template`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`upstream_id`) REFERENCES `upstream`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`certificate_id`) REFERENCES `certificate`(`id`) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (`access_list_id`) REFERENCES `access_list`(`id`) ON DELETE CASCADE
|
2023-05-30 03:26:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
-- migrate:down
|
|
|
|
|
|
|
|
-- Not allowed to go down from initial
|