feat: initialize Discord clone application with core backend services and Electron frontend.
This commit is contained in:
32
Backend/scripts/migrate_dms.js
Normal file
32
Backend/scripts/migrate_dms.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const path = require('path');
|
||||
require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
||||
const db = require('../db');
|
||||
|
||||
async function migrate() {
|
||||
try {
|
||||
console.log('Running DM migration...');
|
||||
|
||||
// 1. Update the check constraint to allow 'dm' type
|
||||
await db.query("ALTER TABLE channels DROP CONSTRAINT IF EXISTS channels_type_check");
|
||||
await db.query("ALTER TABLE channels ADD CONSTRAINT channels_type_check CHECK (type IN ('text', 'voice', 'dm'))");
|
||||
console.log(' Updated channels type constraint to allow dm.');
|
||||
|
||||
// 2. Create dm_participants table
|
||||
await db.query(`
|
||||
CREATE TABLE IF NOT EXISTS dm_participants (
|
||||
channel_id UUID REFERENCES channels(id) ON DELETE CASCADE,
|
||||
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
|
||||
PRIMARY KEY (channel_id, user_id)
|
||||
)
|
||||
`);
|
||||
console.log(' Created dm_participants table.');
|
||||
|
||||
console.log('DM migration complete.');
|
||||
process.exit(0);
|
||||
} catch (err) {
|
||||
console.error('DM migration failed:', err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
migrate();
|
||||
Reference in New Issue
Block a user