const { Client } = require('pg'); const client = new Client({ host: '121.37.183.152', port: 5432, database: 'lp-card-test', user: 'postgres', password: '123456', }); async function main() { await client.connect(); console.log('连接成功'); await client.query(` CREATE TABLE IF NOT EXISTS sys_operation_log ( id BIGSERIAL PRIMARY KEY, username VARCHAR(100) NOT NULL, role VARCHAR(50) NOT NULL DEFAULT 'user', action VARCHAR(200) NOT NULL, detail TEXT, ip VARCHAR(50), create_time TIMESTAMP DEFAULT NOW() ); CREATE INDEX IF NOT EXISTS idx_log_username ON sys_operation_log(username); CREATE INDEX IF NOT EXISTS idx_log_create_time ON sys_operation_log(create_time); `); console.log('日志表创建成功'); await client.end(); } main().catch(e => { console.error(e); process.exit(1); });