feat: support product information PostgreSQL config

This commit is contained in:
lunanting 2026-09-12 21:34:07 +08:00
parent d726dfd4cb
commit 4b1e004b3c
4 changed files with 37 additions and 1 deletions

View File

@ -28,6 +28,7 @@
"multer": "^2.1.1", "multer": "^2.1.1",
"mysql2": "^3.6.5", "mysql2": "^3.6.5",
"node-cron": "^3.0.3", "node-cron": "^3.0.3",
"pg": "8.17.2",
"playwright": "^1.60.0", "playwright": "^1.60.0",
"sharp": "^0.33.5", "sharp": "^0.33.5",
"uuid": "^9.0.1", "uuid": "^9.0.1",

View File

@ -31,6 +31,7 @@
"multer": "^2.1.1", "multer": "^2.1.1",
"mysql2": "^3.6.5", "mysql2": "^3.6.5",
"node-cron": "^3.0.3", "node-cron": "^3.0.3",
"pg": "8.17.2",
"playwright": "^1.60.0", "playwright": "^1.60.0",
"sharp": "^0.33.5", "sharp": "^0.33.5",
"uuid": "^9.0.1", "uuid": "^9.0.1",

View File

@ -1479,6 +1479,13 @@ function getDefaultPortByDriver(driver) {
return 3306; return 3306;
} }
function normalizeDatabaseDriver(driver) {
const normalized = String(driver || '').trim().toLowerCase();
if (normalized === 'postgresql' || normalized === 'postgres') return 'postgres';
if (normalized === 'mssql') return 'mssql';
return 'mysql';
}
async function getStoredDatabaseConfig(configName) { async function getStoredDatabaseConfig(configName) {
const normalizedName = normalizeDatabaseConfigName(configName); const normalizedName = normalizeDatabaseConfigName(configName);
let configs = await database.local.query( let configs = await database.local.query(
@ -1617,7 +1624,9 @@ router.put('/database', async (req, res) => {
} }
// 根据数据库类型设置默认端口 // 根据数据库类型设置默认端口
const resolvedDriver = driver || existingConfig?.driver || (useEnvConfig ? envSummary.driver : 'mysql'); const resolvedDriver = normalizeDatabaseDriver(
driver || existingConfig?.driver || (useEnvConfig ? envSummary.driver : 'mysql')
);
const defaultPort = getDefaultPortByDriver(resolvedDriver); const defaultPort = getDefaultPortByDriver(resolvedDriver);
const configData = { const configData = {
@ -1711,6 +1720,8 @@ router.post('/database/test', async (req, res) => {
return res.status(400).json({ success: false, error: '请完整填写数据库连接信息' }); return res.status(400).json({ success: false, error: '请完整填写数据库连接信息' });
} }
driver = normalizeDatabaseDriver(driver);
if (driver === 'mssql') { if (driver === 'mssql') {
// SQL Server 连接测试 // SQL Server 连接测试
const sql = require('mssql'); const sql = require('mssql');
@ -1730,6 +1741,26 @@ router.post('/database/test', async (req, res) => {
const pool = await sql.connect(config); const pool = await sql.connect(config);
await pool.request().query('SELECT 1 as test'); await pool.request().query('SELECT 1 as test');
await pool.close(); await pool.close();
} else if (driver === 'postgres') {
const { Client } = require('pg');
const client = new Client({
host,
port: port || 5432,
database: dbName,
user: username,
password,
ssl: ssl ? { rejectUnauthorized: false } : false,
connectionTimeoutMillis: 10000,
query_timeout: 10000,
statement_timeout: 10000,
});
try {
await client.connect();
await client.query('SELECT 1 AS test');
} finally {
await client.end().catch(() => {});
}
} else { } else {
// MySQL 连接测试 // MySQL 连接测试
const mysql = require('mysql2/promise'); const mysql = require('mysql2/promise');

View File

@ -41,11 +41,13 @@ const { Text } = Typography;
const DRIVER_OPTIONS = [ const DRIVER_OPTIONS = [
{ value: 'mysql', label: 'MySQL / MariaDB' }, { value: 'mysql', label: 'MySQL / MariaDB' },
{ value: 'mssql', label: 'SQL Server (MSSQL)' }, { value: 'mssql', label: 'SQL Server (MSSQL)' },
{ value: 'postgres', label: 'PostgreSQL' },
]; ];
const DEFAULT_PORTS = { const DEFAULT_PORTS = {
mysql: 3306, mysql: 3306,
mssql: 1433, mssql: 1433,
postgres: 5432,
}; };
const CORE_CONFIG_NAMES = new Set([ const CORE_CONFIG_NAMES = new Set([
@ -59,6 +61,7 @@ const CONFIG_LABELS = {
cloud_database_public: '公网业务数据库', cloud_database_public: '公网业务数据库',
planning_database: '企划数据库', planning_database: '企划数据库',
jiansun_database: '简尚业务数据库', jiansun_database: '简尚业务数据库',
product_information_database: '产品资料系统数据库',
}; };
const DatabaseSettings = () => { const DatabaseSettings = () => {