changes
This commit is contained in:
1 parent
a99af426db
commit
8886aa8640
91 files changed
+2823
-773
No files matched your search
@@ -1,15 +1,38 @@
|
||||
// Usage: node scripts/test-db-connection.mjs
|
||||
// Reads DATABASE_URL from the environment or .env.local (never hardcode hosts/passwords).
|
||||
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import pg from "pg";
|
||||
|
||||
const { Client } = pg;
|
||||
|
||||
const client = new Client({
|
||||
host: "185.36.145.12",
|
||||
port: 5432,
|
||||
database: "ManagmentWebSite_Db",
|
||||
user: "managment_web",
|
||||
password: process.env.DB_PASSWORD,
|
||||
if (!process.env.DATABASE_URL) {
|
||||
const envPath = path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
"..",
|
||||
".env.local",
|
||||
);
|
||||
if (existsSync(envPath)) {
|
||||
for (const line of readFileSync(envPath, "utf8").split(/\r?\n/)) {
|
||||
const match = line.match(/^\s*([A-Z0-9_]+)\s*=\s*(.*)\s*$/);
|
||||
if (match && !(match[1] in process.env)) {
|
||||
process.env[match[1]] = match[2];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
connectionTimeoutMillis: 20000,
|
||||
if (!process.env.DATABASE_URL) {
|
||||
console.error("CONNECTION_FAIL");
|
||||
console.error("DATABASE_URL is not set. Copy .env.example → .env.local and fill it in.");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const client = new Client({
|
||||
connectionString: process.env.DATABASE_URL,
|
||||
connectionTimeoutMillis: 10000,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -26,6 +49,14 @@ try {
|
||||
console.log("CONNECTION_OK");
|
||||
console.log(JSON.stringify(info.rows[0], null, 2));
|
||||
|
||||
const migrations = await client.query(
|
||||
"SELECT version, applied_at FROM schema_migrations ORDER BY version",
|
||||
).catch(() => ({ rows: [] }));
|
||||
console.log("migrations_applied:", migrations.rows.length);
|
||||
if (migrations.rows.length) {
|
||||
console.log(JSON.stringify(migrations.rows.map((r) => r.version), null, 2));
|
||||
}
|
||||
|
||||
const tables = await client.query(`
|
||||
SELECT table_schema, table_name
|
||||
FROM information_schema.tables
|
||||
|
||||
Reference in new issue
Block a user