-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun-basic-migrations.js
More file actions
78 lines (68 loc) · 2.14 KB
/
run-basic-migrations.js
File metadata and controls
78 lines (68 loc) · 2.14 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const { Sequelize, DataTypes } = require('sequelize');
const path = require('path');
const fs = require('fs');
// Load environment variables
require('dotenv').config();
// Database configuration
const databaseUrl = process.env.DATABASE_URL;
const useSsl = String(process.env.DB_SSL || '').toLowerCase() === 'true';
let sequelize;
if (databaseUrl) {
const shouldForceSsl = useSsl || /render\.com/i.test(databaseUrl) || /sslmode=require/i.test(databaseUrl);
sequelize = new Sequelize(databaseUrl, {
dialect: 'postgres',
protocol: 'postgres',
logging: console.log,
dialectOptions: shouldForceSsl
? {
ssl: {
require: true,
rejectUnauthorized: false
}
}
: {}
});
} else {
const database = process.env.DB_NAME || 'alphacollect_db';
const username = process.env.DB_USER || 'postgres';
const password = process.env.DB_PASSWORD || '';
const host = process.env.DB_HOST || 'localhost';
const port = Number(process.env.DB_PORT) || 5432;
sequelize = new Sequelize(database, username, password, {
host,
port,
dialect: 'postgres',
logging: console.log,
dialectOptions: useSsl
? {
ssl: {
require: true,
rejectUnauthorized: false
}
}
: {}
});
}
async function runBasicMigrations() {
try {
console.log('🚀 Starting basic database migration...');
// Test connection
await sequelize.authenticate();
console.log('✅ Database connection established.');
// Run the basic tables migration
console.log('📦 Running basic tables migration...');
const basicMigration = require('./backend/migrations/016_create_basic_tables.js');
if (basicMigration.up) {
await basicMigration.up(sequelize.getQueryInterface(), Sequelize);
console.log('✅ Basic tables migration completed successfully');
}
console.log('\n🎉 Basic migrations completed successfully!');
process.exit(0);
} catch (error) {
console.error('\n❌ Migration failed:', error);
console.error('\nError details:', error.message);
process.exit(1);
}
}
// Run migrations
runBasicMigrations();