mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 16:26:00 +00:00
backend bundle refactor
This commit is contained in:
@@ -1,16 +1,9 @@
|
||||
const fp = require("lodash/fp");
|
||||
const _ = require("lodash");
|
||||
const sql = require('./sql')
|
||||
|
||||
const DatabaseAnalayser = require("../default/DatabaseAnalyser");
|
||||
|
||||
/** @returns {Promise<string>} */
|
||||
async function loadQuery(pool, name) {
|
||||
return await pool._nativeModules.fs.readFile(
|
||||
pool._nativeModules.path.join(__dirname, name),
|
||||
"utf-8"
|
||||
);
|
||||
}
|
||||
|
||||
class MySqlAnalyser extends DatabaseAnalayser {
|
||||
constructor(pool, driver) {
|
||||
super(pool, driver);
|
||||
@@ -24,18 +17,18 @@ class MySqlAnalyser extends DatabaseAnalayser {
|
||||
functions = false,
|
||||
triggers = false
|
||||
) {
|
||||
let res = await loadQuery(this.pool, resFileName);
|
||||
let res = sql[resFileName];
|
||||
res = res.replace("=[OBJECT_ID_CONDITION]", " is not null");
|
||||
return res;
|
||||
}
|
||||
async runAnalysis() {
|
||||
const tables = await this.driver.query(
|
||||
this.pool,
|
||||
await this.createQuery("table_modifications.psql")
|
||||
await this.createQuery("tableModifications")
|
||||
);
|
||||
const columns = await this.driver.query(
|
||||
this.pool,
|
||||
await this.createQuery("columns.psql")
|
||||
await this.createQuery("columns")
|
||||
);
|
||||
// const pkColumns = await this.driver.query(this.pool, await this.createQuery('primary_keys.sql'));
|
||||
// const fkColumns = await this.driver.query(this.pool, await this.createQuery('foreign_keys.sql'));
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
module.exports = `
|
||||
select
|
||||
table_schema as "schemaName",
|
||||
table_name as "pureName",
|
||||
@@ -15,3 +16,4 @@ where
|
||||
and table_schema !~ '^pg_toast'
|
||||
and 'table:' || table_schema || '.' || table_name =[OBJECT_ID_CONDITION]
|
||||
order by ordinal_position
|
||||
`;
|
||||
7
packages/engines/postgres/sql/index.js
Normal file
7
packages/engines/postgres/sql/index.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const columns = require('./columns');
|
||||
const tableModifications = require('./tableModifications');
|
||||
|
||||
module.exports = {
|
||||
columns,
|
||||
tableModifications,
|
||||
};
|
||||
@@ -1,6 +1,7 @@
|
||||
module.exports = `
|
||||
with pkey as
|
||||
(
|
||||
select cc.conrelid, format(E'create constraint %I primary key(%s);\n', cc.conname,
|
||||
select cc.conrelid, format(E'create constraint %I primary key(%s);\\n', cc.conname,
|
||||
string_agg(a.attname, ', '
|
||||
order by array_position(cc.conkey, a.attnum))) pkey
|
||||
from pg_catalog.pg_constraint cc
|
||||
@@ -13,13 +14,13 @@ with pkey as
|
||||
|
||||
|
||||
SELECT oid as "objectId", nspname as "schemaName", relname as "pureName",
|
||||
md5('CREATE TABLE ' || nspname || '.' || relname || E'\n(\n' ||
|
||||
md5('CREATE TABLE ' || nspname || '.' || relname || E'\\n(\\n' ||
|
||||
array_to_string(
|
||||
array_agg(
|
||||
' ' || column_name || ' ' || type || ' '|| not_null
|
||||
)
|
||||
, E',\n'
|
||||
) || E'\n);\n' || (select pkey from pkey where pkey.conrelid = oid)) as "hash"
|
||||
, E',\\n'
|
||||
) || E'\\n);\\n' || (select pkey from pkey where pkey.conrelid = oid)) as "hash"
|
||||
from
|
||||
(
|
||||
SELECT
|
||||
@@ -48,3 +49,4 @@ from
|
||||
) as tabledefinition
|
||||
where 'table:' || nspname || '.' || relname =[OBJECT_ID_CONDITION]
|
||||
group by relname, nspname, oid
|
||||
`;
|
||||
Reference in New Issue
Block a user