Get schema function
This commit is contained in:
parent
aa9931b521
commit
e7026d4aed
|
@ -21,6 +21,7 @@ import { PostgresColumn } from "./base/types"
|
||||||
import { escapeDangerousCharacters } from "../utilities"
|
import { escapeDangerousCharacters } from "../utilities"
|
||||||
|
|
||||||
import { Client, ClientConfig, types } from "pg"
|
import { Client, ClientConfig, types } from "pg"
|
||||||
|
import { exec } from "child_process"
|
||||||
|
|
||||||
// Return "date" and "timestamp" types as plain strings.
|
// Return "date" and "timestamp" types as plain strings.
|
||||||
// This lets us reference the original stored timezone.
|
// This lets us reference the original stored timezone.
|
||||||
|
@ -381,6 +382,34 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
return response.rows.length ? response.rows : [{ [operation]: true }]
|
return response.rows.length ? response.rows : [{ [operation]: true }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getSchema() {
|
||||||
|
const dumpCommandParts = [
|
||||||
|
`PGPASSWORD="${this.config.password}"`,
|
||||||
|
`pg_dump -U ${this.config.user} -h ${this.config.host} -p ${this.config.port} -d ${this.config.database} --schema-only`,
|
||||||
|
]
|
||||||
|
|
||||||
|
const dumpCommand = dumpCommandParts.join(" ")
|
||||||
|
|
||||||
|
return new Promise<string>((res, rej) => {
|
||||||
|
exec(dumpCommand, (error, stdout, stderr) => {
|
||||||
|
if (error) {
|
||||||
|
console.error(`Error generating dump: ${error.message}`)
|
||||||
|
rej(error.message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stderr) {
|
||||||
|
console.error(`pg_dump error: ${stderr}`)
|
||||||
|
rej(stderr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res(stdout)
|
||||||
|
console.log("SQL dump generated successfully!")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
Loading…
Reference in New Issue