create_log_table.js 875 B

123456789101112131415161718192021222324252627282930313233
  1. const { Client } = require('pg');
  2. const client = new Client({
  3. host: '121.37.183.152',
  4. port: 5432,
  5. database: 'lp-card-test',
  6. user: 'postgres',
  7. password: '123456',
  8. });
  9. async function main() {
  10. await client.connect();
  11. console.log('连接成功');
  12. await client.query(`
  13. CREATE TABLE IF NOT EXISTS sys_operation_log (
  14. id BIGSERIAL PRIMARY KEY,
  15. username VARCHAR(100) NOT NULL,
  16. role VARCHAR(50) NOT NULL DEFAULT 'user',
  17. action VARCHAR(200) NOT NULL,
  18. detail TEXT,
  19. ip VARCHAR(50),
  20. create_time TIMESTAMP DEFAULT NOW()
  21. );
  22. CREATE INDEX IF NOT EXISTS idx_log_username ON sys_operation_log(username);
  23. CREATE INDEX IF NOT EXISTS idx_log_create_time ON sys_operation_log(create_time);
  24. `);
  25. console.log('日志表创建成功');
  26. await client.end();
  27. }
  28. main().catch(e => { console.error(e); process.exit(1); });