mirror of
https://github.com/certd/certd.git
synced 2026-04-03 14:10:54 +08:00
perf: 修改sql升级语句,兼容mysql5.7
This commit is contained in:
@@ -62,7 +62,7 @@ services:
|
||||
# - certd_typeorm_dataSource_default_password=yourpasswd # 密码
|
||||
# - certd_typeorm_dataSource_default_database=certd # 数据库名
|
||||
|
||||
# #↓↓↓↓ ----------------------------- 使用mysql数据库,需要提前创建数据库 charset=utf8mb4, collation=utf8mb4_bin
|
||||
# #↓↓↓↓ ----------------------------- 使用mysql8数据库,需要提前创建数据库 charset=utf8mb4, collation=utf8mb4_bin
|
||||
# - certd_flyway_scriptDir=./db/migration-mysql # 升级脚本目录
|
||||
# - certd_typeorm_dataSource_default_type=mysql # 数据库类型, 或者 mariadb
|
||||
# - certd_typeorm_dataSource_default_host=localhost # 数据库地址
|
||||
|
||||
@@ -31,6 +31,12 @@ const DefaultLogger = {
|
||||
console.error(args);
|
||||
},
|
||||
};
|
||||
|
||||
let customLogger:any = null;
|
||||
export function setFlywayLogger (logger: any) {
|
||||
customLogger = logger;
|
||||
};
|
||||
|
||||
export class Flyway {
|
||||
scriptDir;
|
||||
flywayTableName;
|
||||
@@ -43,7 +49,7 @@ export class Flyway {
|
||||
this.flywayTableName = opts.flywayTableName ?? 'flyway_history';
|
||||
this.baseline = opts.baseline ?? false;
|
||||
this.allowHashNotMatch = opts.allowHashNotMatch ?? false;
|
||||
this.logger = opts.logger || DefaultLogger;
|
||||
this.logger = customLogger || opts.logger || DefaultLogger;
|
||||
this.connection = opts.connection;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// src/index.ts
|
||||
export { FlywayConfiguration as Configuration } from './configuration.js';
|
||||
// eslint-disable-next-line node/no-unpublished-import
|
||||
export { Flyway } from './flyway.js';
|
||||
// eslint-disable-next-line node/no-unpublished-import
|
||||
export { Flyway, setFlywayLogger } from './flyway.js';
|
||||
export { FlywayHistory } from './entity.js';
|
||||
|
||||
@@ -11,6 +11,8 @@ typeorm:
|
||||
default:
|
||||
logging: false
|
||||
|
||||
flyway:
|
||||
allowHashNotMatch: true
|
||||
|
||||
account:
|
||||
server:
|
||||
|
||||
@@ -97,7 +97,7 @@ CREATE TABLE `cd_cert_info`
|
||||
|
||||
CREATE INDEX `index_cert_info_user_id` ON `cd_cert_info` (`user_id`);
|
||||
CREATE INDEX `index_cert_info_domain` ON `cd_cert_info` (`domain`);
|
||||
CREATE INDEX `index_cert_info_domains` ON `cd_cert_info` (`domains`(200));
|
||||
CREATE INDEX `index_cert_info_domains` ON `cd_cert_info` (`domains`(190));
|
||||
CREATE INDEX `index_cert_info_pipeline` ON `cd_cert_info` (`pipeline_id`);
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ CREATE TABLE `cd_site_info`
|
||||
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
CREATE INDEX `index_site_info_user_id` ON `cd_site_info` (`user_id`);
|
||||
CREATE INDEX `index_site_info_domain` ON `cd_site_info` (`domain`);
|
||||
|
||||
@@ -16,5 +16,5 @@ CREATE TABLE `cd_domain`
|
||||
);
|
||||
|
||||
CREATE INDEX `index_domain_user_id` ON `cd_domain` (`user_id`);
|
||||
CREATE INDEX `index_domain_domain` ON `cd_domain` (`domain`);
|
||||
CREATE INDEX `index_domain_domain` ON `cd_domain` (`domain`(100));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
CREATE TABLE `cd_oauth_bound`
|
||||
CREATE TABLE IF NOT EXISTS `cd_oauth_bound`
|
||||
(
|
||||
`id` bigint PRIMARY KEY AUTO_INCREMENT NOT NULL,
|
||||
`user_id` bigint NOT NULL,
|
||||
@@ -7,8 +7,8 @@ CREATE TABLE `cd_oauth_bound`
|
||||
`open_id` varchar(512) NOT NULL,
|
||||
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
) ENGINE=InnoDB;
|
||||
|
||||
|
||||
CREATE INDEX `index_oauth_bound_user_id` ON `cd_oauth_bound` (`user_id`);
|
||||
CREATE INDEX `index_oauth_bound_open_id` ON `cd_oauth_bound` (`open_id`);
|
||||
CREATE INDEX `index_oauth_bound_open_id` ON `cd_oauth_bound` (`open_id`(190));
|
||||
|
||||
@@ -75,6 +75,8 @@ function transformMysql() {
|
||||
pgSql = pgSql.replaceAll(/text/g, 'longtext');
|
||||
//双引号 替换成反引号
|
||||
pgSql = pgSql.replaceAll(/"/g, '`');
|
||||
//create table if not exists
|
||||
pgSql = pgSql.replaceAll(/CREATE TABLE ([ ]+)`/g, 'CREATE TABLE IF NOT EXISTS `');
|
||||
|
||||
fs.writeFileSync(`./migration-mysql/${notFile}`, pgSql);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { MidwayConfig } from '@midwayjs/core';
|
||||
// import { fileURLToPath } from 'node:url';
|
||||
// // const __filename = fileURLToPath(import.meta.url);
|
||||
// const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
import { FlywayHistory } from '@certd/midway-flyway-js';
|
||||
import { FlywayHistory, setFlywayLogger } from '@certd/midway-flyway-js';
|
||||
import { UserEntity } from '../modules/sys/authority/entity/user.js';
|
||||
import { PipelineEntity } from '../modules/pipeline/entity/pipeline.js';
|
||||
//import { logger } from '../utils/logger';
|
||||
@@ -15,6 +15,7 @@ import { commercialEntities } from '@certd/commercial-core';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { DefaultUploadFileMimeType, uploadWhiteList } from '@midwayjs/upload';
|
||||
import path from 'path';
|
||||
import { logger } from '@certd/basic';
|
||||
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
@@ -137,4 +138,6 @@ mergeConfig(development, 'development');
|
||||
|
||||
mergeConfig(development, env);
|
||||
|
||||
setFlywayLogger(logger);
|
||||
|
||||
export default development;
|
||||
|
||||
@@ -78,7 +78,7 @@ export class MainConfiguration {
|
||||
app: koa.Application;
|
||||
|
||||
async onReady() {
|
||||
|
||||
// 设置flyway logger
|
||||
|
||||
|
||||
// add middleware
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import { AliyunAccess } from "./aliyun-access.js";
|
||||
|
||||
@IsAccess({
|
||||
name: "alioss",
|
||||
@@ -36,6 +37,15 @@ export class AliossAccess extends BaseAccess {
|
||||
title: "Bucket",
|
||||
helper: "存储桶名称",
|
||||
required: true,
|
||||
component: {
|
||||
name: "remote-auto-complete",
|
||||
vModel: "value",
|
||||
type: "access",
|
||||
action: AliossAccess.prototype.onGetBucketList.name,
|
||||
search: false,
|
||||
pager: false,
|
||||
watches: ["accessId", "region"],
|
||||
},
|
||||
})
|
||||
bucket!: string;
|
||||
|
||||
@@ -76,6 +86,32 @@ export class AliossAccess extends BaseAccess {
|
||||
}
|
||||
}
|
||||
|
||||
async onGetBucketList() {
|
||||
const access = (await this.ctx.accessService.getById(this.accessId)) as AliyunAccess;
|
||||
const client = await this.getClient(access);
|
||||
|
||||
let res;
|
||||
const buckets = [];
|
||||
do {
|
||||
const requestData = { marker: res?.nextMarker || null, "max-keys": 1000 };
|
||||
res = await client.listBuckets(requestData);
|
||||
buckets.push(...(res?.buckets || []));
|
||||
} while (!!res?.nextMarker);
|
||||
return buckets.filter(bucket => bucket?.region === this.region).map(bucket => ({ label: `${bucket.name}<${bucket.region}>`, value: bucket.name }));
|
||||
}
|
||||
|
||||
async getClient(access: AliyunAccess) {
|
||||
// @ts-ignore
|
||||
const OSS = await import("ali-oss");
|
||||
return new OSS.default({
|
||||
accessKeyId: access.accessKeyId,
|
||||
accessKeySecret: access.accessKeySecret,
|
||||
// yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
|
||||
region: this.region,
|
||||
//@ts-ignore
|
||||
authorizationV4: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
new AliossAccess();
|
||||
|
||||
Reference in New Issue
Block a user