const sdk = require('node-appwrite'); const client = new sdk.Client(); const databases = new sdk.Databases(client); client .setEndpoint('http://localhost/v1') // Appwrite local .setProject('69bedced002971103d13') .setKey('standard_2350cc147ace39b0e3fb2c42d1447bc00effb4d5e6115cd682b0d215297a3b35b2ce82e312bd35cff1b738d5eb3462c5b28887937acf217eca6c2143aa0bf4e85ab183350db830901edc0d80d17755d1de5524b945d0c4cb11871af8d33df7f7cdbdfea4237dfc8a47e3c71ac79b3e5172834cc09d451d687a3db74e839ec7a7'); const delay = ms => new Promise(res => setTimeout(res, ms)); async function setupAlmeira() { try { console.log("Creando BBDD Almeira Producciones..."); try { await databases.create('almeira', 'Almeira Producciones'); console.log("DB almeira creada."); } catch (e) { console.log("DB almeira ya existe o error:", e.message); } const dbId = 'almeira'; console.log("Creando Colecciones..."); try { await databases.createCollection(dbId, 'posts', 'Publicaciones', [], false); } catch(e){ console.log(e.message) } try { await databases.createCollection(dbId, 'clients', 'Clientes', [], false); } catch(e){ console.log(e.message) } try { await databases.createCollection(dbId, 'metrics', 'Métricas', [], false); } catch(e){ console.log(e.message) } try { await databases.createCollection(dbId, 'settings', 'Configuración del Medio', [], false); } catch(e){ console.log(e.message) } console.log("Creando Atributos en Publicaciones..."); try { await databases.createStringAttribute(dbId, 'posts', 'titulo', 255, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'contenido', 50000, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'resumen_redes', 1000, false); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'tipo', 50, true); } catch(e){ } // noticia, evento, clasificado try { await databases.createStringAttribute(dbId, 'posts', 'estado', 50, true); } catch(e){ } // borrador, pendiente, publicado try { await databases.createStringAttribute(dbId, 'posts', 'imagen_destacada_id', 255, false); } catch(e){ } try { await databases.createUrlAttribute(dbId, 'posts', 'video_url', false); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'cliente_id', 255, true); } catch(e){ } try { await databases.createDatetimeAttribute(dbId, 'posts', 'fecha_publicacion', true); } catch(e){ } // SEO attributes para posts try { await databases.createStringAttribute(dbId, 'posts', 'slug', 255, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'seo_titulo', 60, false); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'seo_descripcion', 160, false); } catch(e){ } try { await databases.createStringAttribute(dbId, 'posts', 'seo_keywords', 255, false); } catch(e){ } try { await databases.createUrlAttribute(dbId, 'posts', 'og_image_url', false); } catch(e){ } console.log("Creando Atributos en Clientes..."); try { await databases.createStringAttribute(dbId, 'clients', 'nombre_entidad', 255, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'clients', 'contacto_nombre', 255, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'clients', 'numero_whatsapp', 50, true); } catch(e){ } try { await databases.createBooleanAttribute(dbId, 'clients', 'estado', true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'clients', 'slug', 255, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'clients', 'seo_descripcion', 160, false); } catch(e){ } console.log("Creando Atributos en Métricas..."); try { await databases.createStringAttribute(dbId, 'metrics', 'publicacion_id', 255, true); } catch(e){ } try { await databases.createStringAttribute(dbId, 'metrics', 'plataforma', 50, true); } catch(e){ } try { await databases.createIntegerAttribute(dbId, 'metrics', 'vistas', false); } catch(e){ } try { await databases.createIntegerAttribute(dbId, 'metrics', 'interacciones', false); } catch(e){ } console.log("Creando Atributos en Configuración..."); try { await databases.createUrlAttribute(dbId, 'settings', 'radio_stream_url', false); } catch(e){ } try { await databases.createUrlAttribute(dbId, 'settings', 'tv_stream_url', false); } catch(e){ } try { await databases.createStringAttribute(dbId, 'settings', 'whatsapp_recepcion', 50, false); } catch(e){ } try { await databases.createStringAttribute(dbId, 'settings', 'seo_site_name', 255, false); } catch(e){ } try { await databases.createUrlAttribute(dbId, 'settings', 'seo_default_image', false); } catch(e){ } console.log("Almeira Producciones Cloud Database: Finalizado con Éxito!"); } catch (e) { console.error("Error Global:", e.message); } } setupAlmeira();