-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmanual-production-fix.js
More file actions
108 lines (89 loc) · 3.65 KB
/
manual-production-fix.js
File metadata and controls
108 lines (89 loc) · 3.65 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
99
100
101
102
103
104
105
106
107
108
#!/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('🚀 MANUALLY RUNNING RCL PROPER FIX ON PRODUCTION...');
console.log('🔧 Environment check:');
console.log('DB_HOST:', process.env.DB_HOST || 'localhost');
console.log('DB_NAME:', process.env.DB_NAME || 'lectionary_api');
console.log('DB_PORT:', process.env.DB_PORT || '5432');
// Production database connection
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: false,
entities: [path.join(__dirname, 'dist/models/*.entity.js')],
ssl: process.env.DB_SSL === 'true' ? { rejectUnauthorized: false } : false,
});
async function runProductionFix() {
try {
console.log('\n📡 Connecting to production database...');
await AppDataSource.initialize();
console.log('✅ Production database connected successfully!');
// Get RCL tradition ID
const rclTraditions = await AppDataSource.query(
'SELECT id FROM traditions WHERE abbreviation = $1',
['RCL']
);
if (rclTraditions.length === 0) {
console.log('❌ RCL tradition not found in production database');
return;
}
const rclTraditionId = rclTraditions[0].id;
console.log('✅ Found RCL tradition ID:', rclTraditionId);
// Check current state of September 7, 2025
const sep7Current = await AppDataSource.query(
`SELECT COUNT(*) as count FROM readings
WHERE tradition_id = $1 AND date = '2025-09-07'`,
[rclTraditionId]
);
console.log(`📊 Current September 7, 2025 readings count: ${sep7Current[0].count}`);
// Delete all wrong RCL readings for 2025 summer/fall
console.log('\n🗑️ Deleting wrong 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(`✅ Successfully deleted readings for 2025 summer/fall period`);
// Verify September 7 is gone
const sep7After = await AppDataSource.query(
`SELECT COUNT(*) as count FROM readings
WHERE tradition_id = $1 AND date = '2025-09-07'`,
[rclTraditionId]
);
console.log(`📊 September 7, 2025 readings after deletion: ${sep7After[0].count}`);
if (parseInt(sep7After[0].count) === 0) {
console.log('✅ September 7, 2025 readings successfully removed');
console.log('🔄 Production database is now ready for correct readings import');
console.log('\n🚨 CRITICAL: You must now run the readings import script to add correct data');
console.log(' This can be done by triggering a new deployment or running import manually');
} else {
console.log('❌ Failed to remove September 7, 2025 readings');
}
await AppDataSource.destroy();
console.log('\n✅ Production fix preparation completed successfully');
} catch (error) {
console.error('\n❌ Production fix failed:', error.message);
if (AppDataSource.isInitialized) {
await AppDataSource.destroy();
}
process.exit(1);
}
}
// Run the fix
runProductionFix();