-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-migration.js
More file actions
82 lines (69 loc) · 2.61 KB
/
test-migration.js
File metadata and controls
82 lines (69 loc) · 2.61 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
// Test script to check tables and run migration
// Run this in the browser console when logged in as an admin
const API_URL = 'https://scrivenly.com/api';
async function checkAndRunMigration() {
console.log('🔍 Checking database tables...');
try {
// Get session ID from localStorage
const sessionId = localStorage.getItem('sessionId');
if (!sessionId) {
console.error('❌ No session ID found. Please log in first.');
return;
}
// Check what tables exist
console.log('📋 Checking existing tables...');
const tablesResponse = await fetch(`${API_URL}/admin/tables`, {
headers: {
Authorization: `Bearer ${sessionId}`,
},
});
if (tablesResponse.ok) {
const tablesData = await tablesResponse.json();
console.log('📊 Current tables:', tablesData.tables);
const hasTrackedChanges = tablesData.tables.some((table) => table.name === 'tracked_changes');
const hasChangeComments = tablesData.tables.some((table) => table.name === 'change_comments');
if (hasTrackedChanges && hasChangeComments) {
console.log('✅ Tracked changes tables already exist!');
return;
} else {
console.log('❌ Tracked changes tables missing:', {
tracked_changes: hasTrackedChanges,
change_comments: hasChangeComments
});
}
} else {
console.error('❌ Failed to get tables:', tablesResponse.status);
return;
}
// Run migration
console.log('🚀 Running tracked changes migration...');
const migrationResponse = await fetch(`${API_URL}/admin/migrate/tracked-changes`, {
method: 'POST',
headers: {
Authorization: `Bearer ${sessionId}`,
},
});
if (migrationResponse.ok) {
const migrationResult = await migrationResponse.json();
console.log('✅ Migration completed:', migrationResult);
// Check tables again
console.log('📋 Checking tables after migration...');
const tablesResponse2 = await fetch(`${API_URL}/admin/tables`, {
headers: {
Authorization: `Bearer ${sessionId}`,
},
});
if (tablesResponse2.ok) {
const tablesData2 = await tablesResponse2.json();
console.log('📊 Tables after migration:', tablesData2.tables);
}
} else {
const errorText = await migrationResponse.text();
console.error('❌ Migration failed:', migrationResponse.status, errorText);
}
} catch (error) {
console.error('❌ Error during migration check:', error);
}
}
// Run the check
checkAndRunMigration();