-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-database.js
More file actions
44 lines (35 loc) · 1.34 KB
/
setup-database.js
File metadata and controls
44 lines (35 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { Pool } = require('pg');
const fs = require('fs');
const path = require('path');
// Veritabanı bağlantısı
const pool = new Pool({
host: process.env.DB_HOST || 'localhost',
port: parseInt(process.env.DB_PORT || '5432'),
database: process.env.DB_NAME || 'infiwo',
user: process.env.DB_USER || 'dvt',
password: process.env.DB_PASSWORD || '123edc',
});
async function setupDatabase() {
try {
console.log('🚀 MüzikStream veritabanı kurulumu başlıyor...');
// Schema dosyasını oku ve çalıştır
const schemaPath = path.join(__dirname, '../database/schema.sql');
const schemaSQL = fs.readFileSync(schemaPath, 'utf8');
console.log('📋 Tablolar oluşturuluyor...');
await pool.query(schemaSQL);
console.log('✅ Tablolar başarıyla oluşturuldu');
// Örnek verileri ekle
const sampleDataPath = path.join(__dirname, '../database/sample_data.sql');
const sampleDataSQL = fs.readFileSync(sampleDataPath, 'utf8');
console.log('📊 Örnek veriler ekleniyor...');
await pool.query(sampleDataSQL);
console.log('✅ Örnek veriler başarıyla eklendi');
console.log('\n🎉 MüzikStream veritabanı başarıyla kuruldu!');
} catch (error) {
console.error('❌ Veritabanı kurulum hatası:', error);
process.exit(1);
} finally {
await pool.end();
}
}
setupDatabase();