-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-schema.js
More file actions
66 lines (51 loc) · 1.55 KB
/
run-schema.js
File metadata and controls
66 lines (51 loc) · 1.55 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
/**
* Script para ejecutar schema.sql en Supabase
* Run with: node run-schema.js
*/
import postgres from 'postgres';
import fs from 'fs';
// Connection string directo
const connectionString = 'postgresql://postgres:S_michigaN_7799@db.eyuuujpwgpmajrjhnah.supabase.co:5432/postgres';
const sql = postgres(connectionString, {
max: 1,
connect_timeout: 10,
});
async function runSchema() {
try {
console.log('🔄 Conectando a Supabase...\n');
// Leer el schema
const schema = fs.readFileSync('./api/scores/schema.sql', 'utf8');
console.log('📄 Ejecutando schema.sql...\n');
// Ejecutar el schema completo
await sql.unsafe(schema);
console.log('✅ Schema ejecutado exitosamente!\n');
// Verificar que la tabla existe
const tables = await sql`
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public' AND table_name = 'scores'
`;
if (tables.length > 0) {
console.log('✅ Tabla "scores" creada correctamente\n');
// Verificar índices
const indexes = await sql`
SELECT indexname
FROM pg_indexes
WHERE tablename = 'scores'
`;
console.log(`✅ ${indexes.length} índices creados:`);
indexes.forEach(idx => {
console.log(` - ${idx.indexname}`);
});
console.log();
}
console.log('🎉 Setup de base de datos completado!\n');
await sql.end();
process.exit(0);
} catch (error) {
console.error('❌ Error:', error.message);
await sql.end();
process.exit(1);
}
}
runSchema();