94 lines
3.7 KiB
JavaScript
94 lines
3.7 KiB
JavaScript
const sdk = require('node-appwrite');
|
|
|
|
const client = new sdk.Client();
|
|
const databases = new sdk.Databases(client);
|
|
|
|
// Use explicit credentials for Almeira Web Cloud (Coolify)
|
|
const ENDPOINT = process.env.NEXT_PUBLIC_APPWRITE_ENDPOINT || 'https://appwrite.almeira.com.co/v1';
|
|
const PROJECT_ID = process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID || '69b84df5003bd8957c5c';
|
|
const API_KEY = process.env.APPWRITE_API_KEY || 'standard_ee81a4ca6784c0fa6a23abab0a983dbba9cd0c2d8e211a00c759d9801f5d8e27b43a605bfa373e13106da87acfc7673608f0ffb0eb04e10cae3dae93d2404bfda8676f96e3fcfd6bd642f6e12d69367916b796c54e98e2e4c4bc0b7a27aa42ba5048582fcbd45b1365b51c5014cb939c1853923c418048ff0e39c2237065da3c';
|
|
|
|
client
|
|
.setEndpoint(ENDPOINT)
|
|
.setProject(PROJECT_ID)
|
|
.setKey(API_KEY);
|
|
|
|
const delay = ms => new Promise(res => setTimeout(res, ms));
|
|
const dbId = 'almeira';
|
|
|
|
async function setupPhase4() {
|
|
try {
|
|
console.log('========================================');
|
|
console.log('Almeira Web — Appwrite Phase 4 (Live Schedule)');
|
|
console.log('========================================\n');
|
|
|
|
console.log('[1/2] Creando colección maestra: programming_matrices...');
|
|
try {
|
|
await databases.createCollection(dbId, 'programming_matrices', 'Matrices de Programación', [
|
|
sdk.Permission.read(sdk.Role.any()) // Publicly readable for the Frontend Schedules
|
|
], false);
|
|
console.log(' ✓ Colección creada.');
|
|
} catch(e){
|
|
console.log(' > Colección ya existe.');
|
|
}
|
|
await delay(500);
|
|
|
|
// String gigantesca (hasta 65,000 chars o mediumtext)
|
|
try {
|
|
await databases.createStringAttribute(dbId, 'programming_matrices', 'media_type', 50, true);
|
|
console.log(' ✓ Atributo media_type');
|
|
} catch(e){}
|
|
await delay(300);
|
|
try {
|
|
// 1,000,000 length string for robust JSON storage
|
|
await databases.createStringAttribute(dbId, 'programming_matrices', 'matrix_data', 1000000, true);
|
|
console.log(' ✓ Atributo matrix_data JSON (1MB)');
|
|
} catch(e){}
|
|
await delay(1000);
|
|
|
|
console.log('\n[2/2] Sembrando matrices en blanco...');
|
|
let emptyMatrix = {};
|
|
// 24 hours (0 to 23), 7 days (0:Mon to 6:Sun)
|
|
const days = ['mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun'];
|
|
|
|
// Matrix structure: record containing "hour_day" key => "Program Title"
|
|
// e.g. "06_mon": "Noticias del Amanecer"
|
|
for(let hour = 0; hour < 24; hour++) {
|
|
const h = hour.toString().padStart(2, '0');
|
|
days.forEach(day => {
|
|
emptyMatrix[`${h}_${day}`] = '';
|
|
});
|
|
}
|
|
const initialJson = JSON.stringify(emptyMatrix);
|
|
|
|
try {
|
|
await databases.createDocument(dbId, 'programming_matrices', 'matrix_tv', {
|
|
media_type: 'tv',
|
|
matrix_data: initialJson
|
|
});
|
|
console.log(' ✓ Matriz TV inicializada.');
|
|
} catch(e) {
|
|
console.log(' > Matriz TV ya existía.');
|
|
}
|
|
|
|
try {
|
|
await databases.createDocument(dbId, 'programming_matrices', 'matrix_radio', {
|
|
media_type: 'radio',
|
|
matrix_data: initialJson
|
|
});
|
|
console.log(' ✓ Matriz Radio inicializada.');
|
|
} catch(e) {
|
|
console.log(' > Matriz Radio ya existía.');
|
|
}
|
|
|
|
console.log('\n========================================');
|
|
console.log('✅ Base de Datos Phase 4 Lista!');
|
|
console.log('========================================');
|
|
|
|
} catch(e) {
|
|
console.error('\n❌ Error DB:', e.message);
|
|
}
|
|
}
|
|
|
|
setupPhase4();
|