forked from asachs01/lectio-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdirect-production-fix.js
More file actions
98 lines (81 loc) · 3.19 KB
/
Copy pathdirect-production-fix.js
File metadata and controls
98 lines (81 loc) · 3.19 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
require('reflect-metadata');
const { DataSource } = require('typeorm');
const { config } = require('dotenv');
const path = require('path');
// Load environment variables
config();
// This script is intended for production - require credentials
if (!process.env.DB_PASSWORD) {
console.error('ERROR: DB_PASSWORD environment variable is required');
process.exit(1);
}
console.log('🚀 DIRECT PRODUCTION RCL FIX - FINAL ATTEMPT');
console.log('📡 Connecting to production database...');
// Production database connection with all necessary environment variables
const AppDataSource = new DataSource({
type: 'postgres',
host: process.env.DB_HOST || 'localhost',
port: parseInt(process.env.DB_PORT || '5432'),
username: process.env.DB_USERNAME || 'postgres',
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME || 'lectionary_api',
synchronize: false,
logging: true,
entities: [path.join(__dirname, 'dist/models/*.entity.js')],
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false,
});
async function directProductionFix() {
try {
await AppDataSource.initialize();
console.log('✅ Connected to production database');
// Get RCL tradition ID
const rclResult = await AppDataSource.query(
'SELECT id FROM traditions WHERE abbreviation = $1',
['RCL']
);
if (rclResult.length === 0) {
throw new Error('RCL tradition not found');
}
const rclTraditionId = rclResult[0].id;
console.log('✅ RCL tradition ID:', rclTraditionId);
// Check current state
const currentSep7 = await AppDataSource.query(
'SELECT COUNT(*) as count FROM readings WHERE tradition_id = $1 AND date = $2',
[rclTraditionId, '2025-09-07']
);
console.log(`📊 Current Sep 7, 2025 readings: ${currentSep7[0].count}`);
// Delete all wrong RCL readings for June-November 2025
console.log('🗑️ Deleting incorrect RCL readings for June-November 2025...');
const deleteResult = await AppDataSource.query(`
DELETE FROM readings
WHERE tradition_id = $1
AND date >= '2025-06-01'
AND date <= '2025-11-30'
`, [rclTraditionId]);
console.log(`✅ Deleted ${deleteResult.rowCount || 0} incorrect readings`);
// Verify September 7 is cleared
const afterDelete = await AppDataSource.query(
'SELECT COUNT(*) as count FROM readings WHERE tradition_id = $1 AND date = $2',
[rclTraditionId, '2025-09-07']
);
console.log(`📊 After deletion Sep 7, 2025 readings: ${afterDelete[0].count}`);
if (parseInt(afterDelete[0].count) === 0) {
console.log('✅ September 7, 2025 successfully cleared');
console.log('🎉 PRODUCTION RCL FIX COMPLETED SUCCESSFULLY!');
console.log('🔄 Next deployment will import correct Proper 18 readings');
} else {
console.log('❌ September 7, 2025 readings still exist');
}
await AppDataSource.destroy();
console.log('📡 Database connection closed');
} catch (error) {
console.error('❌ Direct production fix failed:', error.message);
if (AppDataSource.isInitialized) {
await AppDataSource.destroy();
}
process.exit(1);
}
}
// Execute the fix
directProductionFix();