chore: initial import

This commit is contained in:
2026-04-19 14:05:40 +08:00
commit 89e9eae36e
81 changed files with 37363 additions and 0 deletions
@@ -0,0 +1,48 @@
const db = require('../db');
async function createTables() {
const client = await db.pool.connect();
try {
console.log('开始创建通知相关表...');
await client.query('BEGIN');
// 创建 notifications 表
await client.query(`
CREATE TABLE IF NOT EXISTS notifications (
id SERIAL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
publisher_id INTEGER REFERENCES users(id),
publisher_name VARCHAR(100),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
is_top BOOLEAN DEFAULT FALSE,
status VARCHAR(20) DEFAULT 'published' -- published, draft, archived
);
`);
console.log('notifications 表创建成功');
// 创建 notification_attachments 表
await client.query(`
CREATE TABLE IF NOT EXISTS notification_attachments (
id SERIAL PRIMARY KEY,
notification_id INTEGER REFERENCES notifications(id) ON DELETE CASCADE,
file_name VARCHAR(255) NOT NULL,
file_path VARCHAR(255) NOT NULL,
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
`);
console.log('notification_attachments 表创建成功');
await client.query('COMMIT');
console.log('所有表创建完成');
} catch (err) {
await client.query('ROLLBACK');
console.error('创建表失败:', err);
} finally {
client.release();
process.exit();
}
}
createTables();