mirror of https://github.com/certd/certd
chore: pg sql自动转换脚本
parent
2bc0a4bd14
commit
762a2058d3
|
@ -14,11 +14,12 @@
|
||||||
"i-all": "lerna link && lerna exec npm install ",
|
"i-all": "lerna link && lerna exec npm install ",
|
||||||
"publish": "npm run prepublishOnly2 && lerna publish --force-publish=pro/plus-core --conventional-commits --create-release github && npm run afterpublishOnly && npm run commitAll",
|
"publish": "npm run prepublishOnly2 && lerna publish --force-publish=pro/plus-core --conventional-commits --create-release github && npm run afterpublishOnly && npm run commitAll",
|
||||||
"afterpublishOnly": "time /t >build.trigger && git add ./build.trigger && git commit -m \"build: trigger build image\" && TIMEOUT /T 10 && git push",
|
"afterpublishOnly": "time /t >build.trigger && git add ./build.trigger && git commit -m \"build: trigger build image\" && TIMEOUT /T 10 && git push",
|
||||||
|
"transform-sql":"cd ./packages/ui/certd-server/db/ && node --experimental-json-modules transform.js",
|
||||||
"commitAll": "git add . && git commit -m \"build: publish\" && git push && npm run commitPro",
|
"commitAll": "git add . && git commit -m \"build: publish\" && git push && npm run commitPro",
|
||||||
"commitPro": "cd ./packages/core/ && git add . && git commit -m \"build: publish\" && git push",
|
"commitPro": "cd ./packages/core/ && git add . && git commit -m \"build: publish\" && git push",
|
||||||
"prepublishOnly1": "npm run check && lerna run build ",
|
"prepublishOnly1": "npm run check && lerna run build ",
|
||||||
"prepublishOnly2": "npm run check && npm run before-build && lerna run build ",
|
"prepublishOnly2": "npm run check && npm run before-build && lerna run build ",
|
||||||
"before-build": "cd ./packages/core/basic && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\"",
|
"before-build": "npm run transform-sql && cd ./packages/core/basic && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\"",
|
||||||
"deploy1": "node --experimental-json-modules deploy.js ",
|
"deploy1": "node --experimental-json-modules deploy.js ",
|
||||||
"check": "node --experimental-json-modules publish-check.js",
|
"check": "node --experimental-json-modules publish-check.js",
|
||||||
"init": "lerna run build"
|
"init": "lerna run build"
|
||||||
|
|
|
@ -4,23 +4,11 @@
|
||||||
# server:
|
# server:
|
||||||
# baseUrl: 'http://127.0.0.1:11007'
|
# baseUrl: 'http://127.0.0.1:11007'
|
||||||
|
|
||||||
#flyway:
|
|
||||||
# scriptDir: './db/migration-pg'
|
|
||||||
|
|
||||||
#typeorm:
|
#typeorm:
|
||||||
# dataSource:
|
# dataSource:
|
||||||
# default:
|
# default:
|
||||||
# type: postgres
|
# database: './data/db.sqlite'
|
||||||
# host: localhost
|
|
||||||
# port: 5433
|
|
||||||
# username: postgres
|
|
||||||
# password: root
|
|
||||||
# database: postgres
|
|
||||||
|
|
||||||
typeorm:
|
|
||||||
dataSource:
|
|
||||||
default:
|
|
||||||
database: './data/db.sqlite'
|
|
||||||
plus:
|
plus:
|
||||||
server:
|
server:
|
||||||
baseUrls: ['https://api.ai.handsfree.work', 'https://api.ai.docmirror.cn']
|
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
|
/test/setup.ts
|
||||||
/data/
|
/data/
|
||||||
.clinic
|
.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",
|
"commdev": "cross-env NODE_ENV=commdev mwtsc --watch --run @midwayjs/mock/app",
|
||||||
"commpro": "cross-env NODE_ENV=commpro 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",
|
"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",
|
"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",
|
"rm-db-new": "rimraf ./data/db-new.sqlite",
|
||||||
"test": "cross-env NODE_ENV=unittest mocha",
|
"test": "cross-env NODE_ENV=unittest mocha",
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
"dev-build": "echo 1",
|
"dev-build": "echo 1",
|
||||||
"build-on-docker": "node ./before-build.js && npm run build",
|
"build-on-docker": "node ./before-build.js && npm run build",
|
||||||
"up-mw-deps": "npx midway-version -u -w",
|
"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"
|
"flame": "clinic flame -- node ./bootstrap.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
Loading…
Reference in New Issue