mirror of https://github.com/certd/certd
perf: 支持mysql
parent
228fdf0a0d
commit
7cde1fdc4a
|
@ -33,7 +33,7 @@ services:
|
|||
# 配置规则: certd_ + 配置项, 点号用_代替
|
||||
# #↓↓↓↓ ----------------------------- 如果忘记管理员密码,可以设置为true,重启之后,管理员密码将改成123456,然后请及时修改回false
|
||||
- certd_system_resetAdminPasswd=false
|
||||
# #↓↓↓↓ ----------------------------- 使用postgresql数据库
|
||||
# #↓↓↓↓ ----------------------------- 使用postgresql数据库,需要提前创建数据库
|
||||
# - certd_flyway_scriptDir=./db/migration-pg # 升级脚本目录
|
||||
# - certd_typeorm_dataSource_default_type=postgres # 数据库类型
|
||||
# - certd_typeorm_dataSource_default_host=localhost # 数据库地址
|
||||
|
@ -42,6 +42,19 @@ services:
|
|||
# - certd_typeorm_dataSource_default_password=yourpasswd # 密码
|
||||
# - certd_typeorm_dataSource_default_database=certd # 数据库名
|
||||
|
||||
# #↓↓↓↓ ----------------------------- 使用mysql数据库,需要提前创建数据库 charset=utf8mb4, collation=utf8mb4_bin
|
||||
# - certd_flyway_scriptDir=./db/migration-mysql # 升级脚本目录
|
||||
# - certd_typeorm_dataSource_default_type=mysql # 数据库类型, 或者 mariadb
|
||||
# - certd_typeorm_dataSource_default_host=localhost # 数据库地址
|
||||
# - certd_typeorm_dataSource_default_port=3306 # 数据库端口
|
||||
# - certd_typeorm_dataSource_default_username=root # 用户名
|
||||
# - certd_typeorm_dataSource_default_password=yourpasswd # 密码
|
||||
# - certd_typeorm_dataSource_default_database=certd # 数据库名
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# #↓↓↓↓ ------------------------------------------------------------- 启用ipv6网络
|
||||
# networks:
|
||||
# - ip6net
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
"use strict";
|
||||
/**
|
||||
* acme-client type definition tests
|
||||
*/
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var acme = require("acme-client");
|
||||
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var accountKey, client, order, authorizations, authorization, challenge, _a, certKey, certCsr;
|
||||
return __generator(this, function (_b) {
|
||||
switch (_b.label) {
|
||||
case 0: return [4 /*yield*/, acme.crypto.createPrivateKey()];
|
||||
case 1:
|
||||
accountKey = _b.sent();
|
||||
client = new acme.Client({
|
||||
accountKey: accountKey,
|
||||
directoryUrl: acme.directory.letsencrypt.staging
|
||||
});
|
||||
/* Account */
|
||||
return [4 /*yield*/, client.createAccount({
|
||||
termsOfServiceAgreed: true,
|
||||
contact: ['mailto:test@example.com']
|
||||
})];
|
||||
case 2:
|
||||
/* Account */
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.createOrder({
|
||||
identifiers: [
|
||||
{ type: 'dns', value: 'example.com' },
|
||||
{ type: 'dns', value: '*.example.com' },
|
||||
]
|
||||
})];
|
||||
case 3:
|
||||
order = _b.sent();
|
||||
return [4 /*yield*/, client.getOrder(order)];
|
||||
case 4:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.getAuthorizations(order)];
|
||||
case 5:
|
||||
authorizations = _b.sent();
|
||||
authorization = authorizations[0];
|
||||
challenge = authorization.challenges[0];
|
||||
return [4 /*yield*/, client.getChallengeKeyAuthorization(challenge)];
|
||||
case 6:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.verifyChallenge(authorization, challenge)];
|
||||
case 7:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.completeChallenge(challenge)];
|
||||
case 8:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.waitForValidStatus(challenge)];
|
||||
case 9:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, acme.crypto.createCsr({
|
||||
commonName: 'example.com',
|
||||
altNames: ['example.com', '*.example.com']
|
||||
})];
|
||||
case 10:
|
||||
_a = _b.sent(), certKey = _a[0], certCsr = _a[1];
|
||||
return [4 /*yield*/, client.finalizeOrder(order, certCsr)];
|
||||
case 11:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.getCertificate(order)];
|
||||
case 12:
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.getCertificate(order, 'DST Root CA X3')];
|
||||
case 13:
|
||||
_b.sent();
|
||||
/* Auto */
|
||||
return [4 /*yield*/, client.auto({
|
||||
csr: certCsr,
|
||||
challengeCreateFn: function (authz, challenge, keyAuthorization) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
}); }); },
|
||||
challengeRemoveFn: function (authz, challenge, keyAuthorization) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
}); }); }
|
||||
})];
|
||||
case 14:
|
||||
/* Auto */
|
||||
_b.sent();
|
||||
return [4 /*yield*/, client.auto({
|
||||
csr: certCsr,
|
||||
email: 'test@example.com',
|
||||
termsOfServiceAgreed: false,
|
||||
skipChallengeVerification: false,
|
||||
challengePriority: ['http-01', 'dns-01'],
|
||||
preferredChain: 'DST Root CA X3',
|
||||
challengeCreateFn: function (authz, challenge, keyAuthorization) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
}); }); },
|
||||
challengeRemoveFn: function (authz, challenge, keyAuthorization) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
||||
return [2 /*return*/];
|
||||
}); }); }
|
||||
})];
|
||||
case 15:
|
||||
_b.sent();
|
||||
return [2 /*return*/];
|
||||
}
|
||||
});
|
||||
}); })();
|
|
@ -0,0 +1,14 @@
|
|||
flyway:
|
||||
scriptDir: './db/migration-mysql'
|
||||
|
||||
typeorm:
|
||||
dataSource:
|
||||
default:
|
||||
type: mysql # mariadb
|
||||
host: localhost
|
||||
port: 3306
|
||||
username: root
|
||||
password: root
|
||||
database: certd
|
||||
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
-- 表:sys_permission
|
||||
CREATE TABLE `sys_permission` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `title` varchar(100) NOT NULL, `permission` varchar(100), `parent_id` bigint NOT NULL DEFAULT -1, `sort` bigint NOT NULL, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (1, '系统管理', 'sys', -1, 1 );
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (2, '权限管理', 'sys:auth', 1, 1 );
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (3, '用户管理', 'sys:auth:user', 2, 1);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (4, '查看', 'sys:auth:user:view', 3, 100);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (5, '权限管理', 'sys:auth:per', 2, 1 );
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (6, '查看', 'sys:auth:per:view', 5, 100);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (7, '角色管理', 'sys:auth:role', 2, 1 );
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (8, '查看', 'sys:auth:role:view', 7, 1);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (9, '修改', 'sys:auth:user:edit', 3, 300);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (10, '删除', 'sys:auth:user:remove', 3, 400);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (11, '添加', 'sys:auth:user:add', 3, 200);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (12, '修改', 'sys:auth:role:edit', 7, 1);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (13, '删除', 'sys:auth:role:remove', 7, 1);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (14, '添加', 'sys:auth:role:add', 7, 1);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (15, '修改', 'sys:auth:per:edit', 5, 300);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (16, '删除', 'sys:auth:per:remove', 5, 400);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (17, '添加', 'sys:auth:per:add', 5, 200);
|
||||
INSERT INTO sys_permission (id, title, permission, parent_id, sort) VALUES (18,'授权','sys:auth:role:authz',7,100);
|
||||
|
||||
|
||||
|
||||
-- 表:sys_role
|
||||
CREATE TABLE `sys_role` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `name` varchar(100) NOT NULL, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO sys_role (id, name) VALUES (1, '管理员');
|
||||
INSERT INTO sys_role (id, name) VALUES (2, '只读角色');
|
||||
|
||||
-- 表:sys_role_permission
|
||||
CREATE TABLE `sys_role_permission` (`role_id` bigint NOT NULL, `permission_id` bigint NOT NULL, PRIMARY KEY (`role_id`, `permission_id`));
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 1);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 2);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 3);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 4);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 5);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 6);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 7);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 8);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 9);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 10);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 11);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 12);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 13);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 14);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 15);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 16);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 17);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, 18);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, -1);
|
||||
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 4);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 6);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 8);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 1);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 2);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 3);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 5);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, 7);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (2, -1);
|
||||
|
||||
-- 表:sys_user
|
||||
CREATE TABLE `sys_user` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `username` varchar(100) NOT NULL, `password` varchar(100) NOT NULL, `nick_name` varchar(50), `avatar` varchar(255), `phone_code` varchar(20), `mobile` varchar(20), `email` varchar(100),`remark` varchar(100), `status` bigint NOT NULL DEFAULT 1, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
INSERT INTO sys_user (id, username, password, nick_name, avatar, phone_code, mobile, email, status,remark) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 'admin', NULL, NULL, NULL, NULL, 1, NULL);
|
||||
INSERT INTO sys_user (id, username, password, nick_name, avatar, phone_code, mobile, email, status,remark) VALUES (2, 'readonly', 'e10adc3949ba59abbe56e057f20f883e', '只读用户', NULL, NULL, NULL, NULL, 0, '密码:123456');
|
||||
|
||||
-- 表:sys_user_role
|
||||
CREATE TABLE `sys_user_role` (`role_id` bigint NOT NULL, `user_id` bigint NOT NULL, PRIMARY KEY (`role_id`, `user_id`));
|
||||
INSERT INTO sys_user_role (role_id, user_id) VALUES (1, 1);
|
||||
INSERT INTO sys_user_role (role_id, user_id) VALUES (2, 2);
|
||||
|
||||
-- 索引:IDX_223de54d6badbe43a5490450c3
|
||||
CREATE UNIQUE INDEX `IDX_223de54d6badbe43a5490450c3` ON `sys_role` (`name`);
|
||||
|
||||
-- 索引:IDX_9e7164b2f1ea1348bc0eb0a7da
|
||||
CREATE UNIQUE INDEX `IDX_9e7164b2f1ea1348bc0eb0a7da` ON `sys_user` (`username`);
|
||||
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
-- for preview 限制演示环境的数据修改
|
||||
ALTER TABLE sys_user AUTO_INCREMENT = 1000;
|
||||
ALTER TABLE sys_permission AUTO_INCREMENT = 1000;
|
||||
ALTER TABLE sys_role AUTO_INCREMENT = 1000;
|
|
@ -0,0 +1,24 @@
|
|||
--
|
||||
-- 由SQLiteStudio v3.3.3 产生的文件 周六 7月 3 00:38:02 2021
|
||||
--
|
||||
-- 文本编码:UTF-8
|
||||
--
|
||||
|
||||
-- 表:cd_access
|
||||
CREATE TABLE `cd_access` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `name` varchar(100) NOT NULL, `type` varchar(100) NOT NULL, `setting` varchar(1024), `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
-- 表:cd_cert
|
||||
CREATE TABLE `cd_cert` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `domains` varchar(2048) NOT NULL, `email` varchar(100) NOT NULL, `cert_issuer_id` bigint, `challenge_type` varchar(100), `challenge_dns_type` varchar(100),`challenge_access_id` bigint, `country` varchar(100), `state` varchar(100), `locality` varchar(100), `organization` varchar(100), `organization_unit` varchar(100), `remark` varchar(100), `last_history_id` bigint, `last_success_id` bigint, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
-- 表:cd_cert_apply_history
|
||||
CREATE TABLE `cd_cert_apply_history` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `cert_id` bigint NOT NULL, `success` boolean, `result` varchar(1024), `cert_crt` varchar(1024), `cert_key` varchar(1024), `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
-- 表:cd_cert_issuer
|
||||
CREATE TABLE `cd_cert_issuer` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `type` varchar(20) NOT NULL, `account` varchar(100) NOT NULL, `private_key` varchar(1024), `setting` varchar(1024), `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
-- 表:cd_task
|
||||
CREATE TABLE `cd_task` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `name` varchar(100), `type` varchar(100), `setting` varchar(2048), `cert_id` bigint NOT NULL, `last_history_id` bigint, `last_success_id` bigint, `remark` varchar(100), `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
-- 表:cd_task_history
|
||||
CREATE TABLE `cd_task_history` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `task_id` bigint NOT NULL, `cert_id` bigint NOT NULL, `cert_apply_history_id` bigint NOT NULL, `success` boolean, `result` varchar(2048), `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE `pi_history` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `pipeline_id` bigint NOT NULL, `pipeline` TEXT, `status` varchar(20), `end_time` timestamp, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
CREATE TABLE `pi_history_log` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `pipeline_id` bigint NOT NULL, `history_id` bigint NOT NULL, `node_id` varchar(100), `logs` TEXT, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
CREATE TABLE `pi_pipeline` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `title` varchar(200) NOT NULL, `content` TEXT NOT NULL, `keep_history_count` bigint, `remark` varchar(100), `status` varchar(100), `disabled` boolean DEFAULT 0, `last_history_time` bigint, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
|
||||
CREATE TABLE `pi_storage` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `scope` varchar(100) NOT NULL, `namespace` varchar(100) NOT NULL, `version` varchar(100),`key` varchar(100), `value` TEXT, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
|
@ -0,0 +1,9 @@
|
|||
CREATE TABLE `sys_settings` (
|
||||
`id` bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`user_id` bigint NOT NULL,
|
||||
`key` varchar(100) NOT NULL,
|
||||
`title` varchar(100) NOT NULL,
|
||||
`setting` varchar(1024),
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
|
@ -0,0 +1 @@
|
|||
INSERT INTO sys_role (id, name) VALUES (3, '普通用户');
|
|
@ -0,0 +1,22 @@
|
|||
ALTER TABLE `sys_settings` RENAME TO `user_settings`;
|
||||
|
||||
CREATE TABLE `sys_settings` (
|
||||
`id` bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`key` varchar(100) NOT NULL,
|
||||
`title` varchar(100) NOT NULL,
|
||||
`setting` varchar(1024),
|
||||
`access` varchar(100) NOT NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
SET @parent_id = (SELECT id FROM sys_permission WHERE permission = 'sys');
|
||||
INSERT INTO sys_permission (title, permission, parent_id, sort) VALUES ('系统设置', 'sys:settings', @parent_id, 1);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, LAST_INSERT_ID());
|
||||
|
||||
SET @parent_id = (SELECT id FROM sys_permission WHERE permission = 'sys:settings');
|
||||
INSERT INTO sys_permission (title, permission, parent_id, sort) VALUES ('查看', 'sys:settings:view',@parent_id, 1);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, LAST_INSERT_ID());
|
||||
INSERT INTO sys_permission (title, permission, parent_id, sort) VALUES ('编辑', 'sys:settings:edit', @parent_id, 1);
|
||||
INSERT INTO sys_role_permission (role_id, permission_id) VALUES (1, LAST_INSERT_ID());
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
INSERT INTO sys_settings (`key`, title, setting, access)
|
||||
VALUES (
|
||||
'sys.install',
|
||||
'安装信息',
|
||||
CONCAT('{"installTime":', (SELECT timestamp FROM flyway_history WHERE id = 1), '}'),
|
||||
'private'
|
||||
);
|
||||
|
||||
ALTER TABLE sys_user ADD COLUMN password_version bigint DEFAULT 1;
|
||||
ALTER TABLE sys_user ADD COLUMN password_salt varchar(36);
|
|
@ -0,0 +1,3 @@
|
|||
alter table pi_pipeline add COLUMN `order` bigint default 0;
|
||||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
alter table cd_access add COLUMN `encrypt_setting` text;
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
CREATE TABLE `cd_cname_provider`
|
||||
(
|
||||
`id` bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`domain` varchar(100) NOT NULL,
|
||||
`dns_provider_type` varchar(100) NOT NULL,
|
||||
`access_id` bigint NOT NULL,
|
||||
`is_default` boolean NOT NULL,
|
||||
`remark` varchar(200),
|
||||
`disabled` boolean NOT NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE `cd_cname_record`
|
||||
(
|
||||
`id` bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`user_id` bigint NOT NULL,
|
||||
`domain` varchar(100) NOT NULL,
|
||||
`host_record` varchar(100) NOT NULL,
|
||||
`record_value` varchar(200) NOT NULL,
|
||||
`cname_provider_id` bigint NOT NULL,
|
||||
`status` varchar(100) NOT NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
CREATE TABLE `pi_plugin`
|
||||
(
|
||||
`id` bigint NOT NULL PRIMARY KEY AUTO_INCREMENT,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`icon` varchar(100),
|
||||
`title` varchar(200),
|
||||
`desc` varchar(500),
|
||||
`group` varchar(100),
|
||||
`version` varchar(100),
|
||||
`setting` text,
|
||||
`sys_setting` text,
|
||||
`content` text,
|
||||
`type` varchar(100) NOT NULL,
|
||||
`disabled` boolean NOT NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ALTER TABLE cd_cname_provider ADD COLUMN user_id bigint;
|
||||
|
||||
update cd_cname_provider set user_id = 1;
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
update sys_user set status = 0 where id = 2;
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
CREATE TABLE `pi_notification` (`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL, `user_id` bigint NOT NULL, `name` varchar(100) NOT NULL, `type` varchar(100) NOT NULL, `setting` text, `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
|
@ -0,0 +1 @@
|
|||
ALTER TABLE pi_notification ADD COLUMN is_default boolean DEFAULT 0;
|
|
@ -0,0 +1,13 @@
|
|||
CREATE TABLE `pi_pipeline_group`
|
||||
(
|
||||
`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
`user_id` bigint NOT NULL,
|
||||
`name` varchar(100) NOT NULL,
|
||||
`icon` varchar(100),
|
||||
`favorite` boolean NOT NULL DEFAULT false,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
ALTER TABLE pi_pipeline
|
||||
ADD COLUMN group_id bigint;
|
|
@ -0,0 +1,30 @@
|
|||
|
||||
CREATE INDEX `index_access_user_id` ON `cd_access` (`user_id`);
|
||||
|
||||
CREATE INDEX `index_cname_record_user_id` ON `cd_cname_record` (`user_id`);
|
||||
|
||||
|
||||
CREATE INDEX `index_history_user_id` ON `pi_history` (`user_id`);
|
||||
|
||||
CREATE INDEX `index_history_log_user_id` ON `pi_history_log` (`user_id`);
|
||||
|
||||
CREATE INDEX `index_history_log_pipeline_id` ON `pi_history_log` (`pipeline_id`);
|
||||
|
||||
CREATE INDEX `index_notification_user_id` ON `pi_notification` (`user_id`);
|
||||
|
||||
CREATE INDEX `index_pipeline_user_id` ON `pi_pipeline` (`user_id`);
|
||||
CREATE INDEX `index_pipeline_group_user_id` ON `pi_pipeline_group` (`user_id`);
|
||||
|
||||
|
||||
CREATE INDEX `index_storage_default_get` ON `pi_storage` (`scope`(50), `namespace`(50), `key`(50));
|
||||
CREATE INDEX `index_storage_user_id` ON `pi_storage` (`user_id`);
|
||||
|
||||
|
||||
CREATE INDEX `index_user_email` ON `sys_user` (`email`);
|
||||
CREATE INDEX `index_user_mobile` ON `sys_user` (`mobile`);
|
||||
|
||||
CREATE INDEX `index_permission` ON `sys_permission` (`permission`);
|
||||
|
||||
|
||||
CREATE INDEX `index_user_settings_user_id` ON `user_settings` (`user_id`);
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
CREATE INDEX "index_access_user_id" ON "cd_access" ("user_id");
|
||||
|
||||
CREATE INDEX "index_cname_record_user_id" ON "cd_cname_record" ("user_id");
|
||||
|
||||
|
||||
CREATE INDEX "index_history_user_id" ON "pi_history" ("user_id");
|
||||
|
||||
CREATE INDEX "index_history_log_user_id" ON "pi_history_log" ("user_id");
|
||||
|
||||
CREATE INDEX "index_history_log_pipeline_id" ON "pi_history_log" ("pipeline_id");
|
||||
|
||||
CREATE INDEX "index_notification_user_id" ON "pi_notification" ("user_id");
|
||||
|
||||
CREATE INDEX "index_pipeline_user_id" ON "pi_pipeline" ("user_id");
|
||||
CREATE INDEX "index_pipeline_group_user_id" ON "pi_pipeline_group" ("user_id");
|
||||
|
||||
|
||||
|
||||
CREATE INDEX "index_storage_default_get" ON "pi_storage" ("scope", "namespace", "key");
|
||||
CREATE INDEX "index_storage_user_id" ON "pi_storage" ("user_id");
|
||||
|
||||
|
||||
CREATE INDEX "index_user_email" ON "sys_user" ("email");
|
||||
CREATE INDEX "index_user_mobile" ON "sys_user" ("mobile");
|
||||
|
||||
CREATE INDEX "index_permission" ON "sys_permission" ("permission");
|
||||
|
||||
|
||||
CREATE INDEX "index_user_settings_user_id" ON "user_settings" ("user_id");
|
||||
|
|
@ -25,21 +25,21 @@ import fs from 'fs';
|
|||
* sqlite: integer
|
||||
* postgresql: bigint
|
||||
*/
|
||||
function transform() {
|
||||
function transformPG() {
|
||||
// 读取文件列表
|
||||
const sqliteFiles = fs.readdirSync('./migration/');
|
||||
const pgFiles = fs.readdirSync('./migration-pg');
|
||||
const pgFiles = fs.readdirSync('./migration-pg/');
|
||||
//找出pg里面没有的文件
|
||||
const notFiles = sqliteFiles.filter(file => !pgFiles.includes(file));
|
||||
for (const notFile of notFiles) {
|
||||
//开始转换
|
||||
const sqliteSql = fs.readFileSync(`./migration/${notFile}`, 'utf-8');
|
||||
let pgSql = sqliteSql.replace(/AUTOINCREMENT/g, 'GENERATED BY DEFAULT AS IDENTITY');
|
||||
pgSql = pgSql.replace(/datetime/g, 'timestamp');
|
||||
pgSql = pgSql.replace(/boolean DEFAULT \(0\)/g, 'boolean DEFAULT (false)');
|
||||
pgSql = pgSql.replace(/boolean.*NOT NULL DEFAULT \(0\)/g, 'boolean NOT NULL DEFAULT (false)');
|
||||
pgSql = pgSql.replace(/integer/g, 'bigint');
|
||||
pgSql = pgSql.replace(/last_insert_rowid\(\)/g, 'LASTVAL()');
|
||||
let pgSql = sqliteSql.replaceAll(/AUTOINCREMENT/g, 'GENERATED BY DEFAULT AS IDENTITY');
|
||||
pgSql = pgSql.replaceAll(/datetime/g, 'timestamp');
|
||||
pgSql = pgSql.replaceAll(/boolean DEFAULT \(0\)/g, 'boolean DEFAULT (false)');
|
||||
pgSql = pgSql.replaceAll(/boolean.*NOT NULL DEFAULT \(0\)/g, 'boolean NOT NULL DEFAULT (false)');
|
||||
pgSql = pgSql.replaceAll(/integer/g, 'bigint');
|
||||
pgSql = pgSql.replaceAll(/last_insert_rowid\(\)/g, 'LASTVAL()');
|
||||
fs.writeFileSync(`./migration-pg/${notFile}`, pgSql);
|
||||
}
|
||||
|
||||
|
@ -51,4 +51,37 @@ function transform() {
|
|||
console.log('sql无需更新');
|
||||
}
|
||||
}
|
||||
transform();
|
||||
|
||||
function transformMysql() {
|
||||
// 读取文件列表
|
||||
const sqliteFiles = fs.readdirSync('./migration/');
|
||||
const pgFiles = fs.readdirSync('./migration-mysql/');
|
||||
//找出pg里面没有的文件
|
||||
const notFiles = sqliteFiles.filter(file => !pgFiles.includes(file));
|
||||
for (const notFile of notFiles) {
|
||||
//开始转换
|
||||
const sqliteSql = fs.readFileSync(`./migration/${notFile}`, 'utf-8');
|
||||
let pgSql = sqliteSql.replaceAll(/AUTOINCREMENT/g, 'AUTO_INCREMENT');
|
||||
pgSql = pgSql.replaceAll(/datetime/g, 'timestamp');
|
||||
//DEFAULT (xxx) 替换成 DEFAULT xxx
|
||||
pgSql = pgSql.replaceAll(/DEFAULT \(([^)]*)\)/g, 'DEFAULT $1');
|
||||
pgSql = pgSql.replaceAll(/integer/g, 'bigint');
|
||||
pgSql = pgSql.replaceAll(/last_insert_rowid\(\)/g, 'LAST_INSERT_ID()');
|
||||
|
||||
//双引号 替换成反引号
|
||||
pgSql = pgSql.replaceAll(/"/g, '`');
|
||||
|
||||
fs.writeFileSync(`./migration-mysql/${notFile}`, pgSql);
|
||||
}
|
||||
|
||||
if (notFiles.length > 0) {
|
||||
console.log('sqlite->mysql 转换完成');
|
||||
|
||||
throw new Error('sqlite->mysql 转换完成,有更新,需要测试mysql');
|
||||
} else {
|
||||
console.log('sql无需更新');
|
||||
}
|
||||
}
|
||||
|
||||
transformPG();
|
||||
transformMysql();
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"commdev": "cross-env NODE_ENV=commdev mwtsc --watch --run @midwayjs/mock/app",
|
||||
"commpro": "cross-env NODE_ENV=commpro mwtsc --watch --run @midwayjs/mock/app",
|
||||
"pgdev": "cross-env NODE_ENV=pgdev mwtsc --watch --run @midwayjs/mock/app",
|
||||
"mysqldev": "cross-env NODE_ENV=mysqldev mwtsc --watch --run @midwayjs/mock/app",
|
||||
"local-plus": "cross-env NODE_ENV=localplus mwtsc --watch --run @midwayjs/mock/app",
|
||||
"pgpl": "cross-env NODE_ENV=pgpl mwtsc --watch --run @midwayjs/mock/app",
|
||||
"dev-new": "cross-env NODE_ENV=devnew mwtsc --watch --run @midwayjs/mock/app",
|
||||
|
@ -79,6 +80,7 @@
|
|||
"lru-cache": "^11.0.1",
|
||||
"mwts": "^1.3.0",
|
||||
"mwtsc": "^1.4.0",
|
||||
"mysql": "^2.18.1",
|
||||
"nanoid": "^5.0.7",
|
||||
"node-forge": "^1.3.1",
|
||||
"nodemailer": "^6.9.3",
|
||||
|
|
|
@ -2,6 +2,7 @@ import { SqliteAdapter } from './sqlite.js';
|
|||
import { PostgresqlAdapter } from './postgresql.js';
|
||||
import { Config, Init, Provide, Scope, ScopeEnum } from '@midwayjs/core';
|
||||
import { SqlAdapter } from './d.js';
|
||||
import { MysqlAdapter } from './mysql.js';
|
||||
|
||||
@Provide()
|
||||
@Scope(ScopeEnum.Singleton)
|
||||
|
@ -16,8 +17,10 @@ export class DbAdapter implements SqlAdapter {
|
|||
this.adapter = new SqliteAdapter();
|
||||
} else if (this.isPostgresql()) {
|
||||
this.adapter = new PostgresqlAdapter();
|
||||
} else if (this.isMysql()) {
|
||||
this.adapter = new MysqlAdapter();
|
||||
} else {
|
||||
throw new Error(`dbType ${this.dbType} not support`);
|
||||
throw new Error(`dbType ${this.dbType} not support, 请实现Adapter`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +30,9 @@ export class DbAdapter implements SqlAdapter {
|
|||
isPostgresql() {
|
||||
return this.dbType === 'postgres';
|
||||
}
|
||||
isMysql() {
|
||||
return this.dbType === 'mysql' || this.dbType === 'mariadb';
|
||||
}
|
||||
|
||||
date(columnName: string) {
|
||||
return this.adapter.date(columnName);
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
import { SqlAdapter } from './d.js';
|
||||
|
||||
export class MysqlAdapter implements SqlAdapter {
|
||||
date(columnName: string) {
|
||||
return `DATE_FORMAT(${columnName}, '%Y-%m-%d')`;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue