mirror of
https://github.com/certd/certd.git
synced 2026-04-24 04:17:25 +08:00
chore: pg sql自动转换脚本
This commit is contained in:
@@ -4,23 +4,11 @@
|
||||
# server:
|
||||
# baseUrl: 'http://127.0.0.1:11007'
|
||||
|
||||
#flyway:
|
||||
# scriptDir: './db/migration-pg'
|
||||
|
||||
#typeorm:
|
||||
# dataSource:
|
||||
# default:
|
||||
# type: postgres
|
||||
# host: localhost
|
||||
# port: 5433
|
||||
# username: postgres
|
||||
# password: root
|
||||
# database: postgres
|
||||
|
||||
typeorm:
|
||||
dataSource:
|
||||
default:
|
||||
database: './data/db.sqlite'
|
||||
# database: './data/db.sqlite'
|
||||
plus:
|
||||
server:
|
||||
baseUrls: ['https://api.ai.handsfree.work', 'https://api.ai.docmirror.cn']
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
flyway:
|
||||
scriptDir: './db/migration-pg'
|
||||
|
||||
|
||||
typeorm:
|
||||
dataSource:
|
||||
default:
|
||||
type: postgres
|
||||
host: 192.168.42.245
|
||||
port: 5432
|
||||
username: root
|
||||
password: Baode@1234567
|
||||
database: certd
|
||||
|
||||
#plus:
|
||||
# server:
|
||||
# baseUrl: 'https://api.ai.handsfree.work'
|
||||
|
||||
plus:
|
||||
server:
|
||||
baseUrl: 'http://127.0.0.1:11007'
|
||||
@@ -17,3 +17,5 @@ run/
|
||||
/test/setup.ts
|
||||
/data/
|
||||
.clinic
|
||||
|
||||
.env.pgpl.yaml
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE TABLE "pi_plugin"
|
||||
(
|
||||
"id" bigint NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
|
||||
"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,53 @@
|
||||
import fs from 'fs';
|
||||
/**
|
||||
* ## sqlite与postgres不同点
|
||||
* 1.
|
||||
* sqlite: AUTOINCREAMENT
|
||||
* postgresql: GENERATED BY DEFAULT AS IDENTITY
|
||||
*
|
||||
* 2.
|
||||
* sqlite: datetime
|
||||
* postgresql: timestamp
|
||||
*
|
||||
* 3.
|
||||
* sqlite: update sqlite_sequence set seq = 1000 where name = 'sys_role' ;
|
||||
* postgresql: select setval('sys_role_id_seq', 1000);
|
||||
*
|
||||
* 4.
|
||||
* sqlite: "disabled" boolean DEFAULT (0)
|
||||
* postgresql: "disabled" boolean DEFAULT (false)
|
||||
*
|
||||
* 5.
|
||||
* sqlite: last_insert_rowid()
|
||||
* postgresql: LASTVAL()
|
||||
*
|
||||
* 6.
|
||||
* sqlite: integer
|
||||
* postgresql: bigint
|
||||
*/
|
||||
function transform() {
|
||||
// 读取文件列表
|
||||
const sqliteFiles = fs.readdirSync('./migration/');
|
||||
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(/integer/g, 'bigint');
|
||||
pgSql = pgSql.replace(/last_insert_rowid\(\)/g, 'LASTVAL()');
|
||||
fs.writeFileSync(`./migration-pg/${notFile}`, pgSql);
|
||||
}
|
||||
|
||||
if (notFiles.length > 0) {
|
||||
console.log('sqlite->pg 转换完成');
|
||||
|
||||
throw new Error('sqlite->pg 转换完成,有更新,需要测试pg');
|
||||
} else {
|
||||
console.log('sql无需更新');
|
||||
}
|
||||
}
|
||||
transform();
|
||||
@@ -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",
|
||||
"pgpl": "cross-env NODE_ENV=pgpl mwtsc --watch --run @midwayjs/mock/app",
|
||||
"dev-new": "npm run rm-db-new && cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app",
|
||||
"rm-db-new": "rimraf ./data/db-new.sqlite",
|
||||
"test": "cross-env NODE_ENV=unittest mocha",
|
||||
@@ -21,7 +22,7 @@
|
||||
"dev-build": "echo 1",
|
||||
"build-on-docker": "node ./before-build.js && npm run build",
|
||||
"up-mw-deps": "npx midway-version -u -w",
|
||||
"heap": "clinic heapprofiler -- node ./bootstrap.js",
|
||||
"heap": "cross-env NODE_ENV=pgpl clinic heapprofiler -- node ./bootstrap.js",
|
||||
"flame": "clinic flame -- node ./bootstrap.js"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
Reference in New Issue
Block a user