fix(dron): Ejecutor funcional + tabla events
Cambios: - ejecutor.rb: Corregir lectura de output con Open3 - bitacora_db.rb: Agregar métodos crear_evento/actualizar_evento (public) - dron_db.rb: Corregir conversión de PG::Result a Hash (.first.to_h) - vigilante.rb: Corregir formato de fecha en dashboard - migrations/004: Crear tabla bitacoras.events para Bitácora Web Pruebas: - dron lanzar --evento AUTO --nota "Test" -- echo "hola" ✅ - dron flota ✅ - dron salud ✅ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
3d2a988951
commit
be3a78c50a
@@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Migración 004: Crear tabla events para Bitácora Web
|
||||
# ====================================================
|
||||
# Esta tabla almacena eventos visibles en la Bitácora Web
|
||||
# Es el medio de comunicación donde los drones dejan registro de su actividad
|
||||
|
||||
require_relative '../core/bitacora_db'
|
||||
|
||||
module BitacorasDB
|
||||
module Migrations
|
||||
class CreateEventsTable
|
||||
def self.up
|
||||
BitacorasDB::BitacoraDB.with_connection do |db|
|
||||
# Crear tabla
|
||||
db.instance_variable_get(:@connection).exec(<<~SQL)
|
||||
CREATE TABLE IF NOT EXISTS bitacoras.events (
|
||||
id SERIAL PRIMARY KEY,
|
||||
nodo_id INTEGER NOT NULL REFERENCES bitacoras.nodos(id),
|
||||
descripcion TEXT NOT NULL,
|
||||
estado VARCHAR(10) NOT NULL DEFAULT '⏳',
|
||||
inicio VARCHAR(10) NOT NULL,
|
||||
fin VARCHAR(10),
|
||||
modo VARCHAR(10) DEFAULT 'A',
|
||||
metadata JSONB DEFAULT '{}'::jsonb,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW()
|
||||
)
|
||||
SQL
|
||||
|
||||
# Crear índices
|
||||
db.instance_variable_get(:@connection).exec("CREATE INDEX IF NOT EXISTS idx_events_nodo ON bitacoras.events(nodo_id)")
|
||||
db.instance_variable_get(:@connection).exec("CREATE INDEX IF NOT EXISTS idx_events_estado ON bitacoras.events(estado)")
|
||||
db.instance_variable_get(:@connection).exec("CREATE INDEX IF NOT EXISTS idx_events_inicio ON bitacoras.events(inicio)")
|
||||
db.instance_variable_get(:@connection).exec("CREATE INDEX IF NOT EXISTS idx_events_metadata ON bitacoras.events USING GIN(metadata)")
|
||||
|
||||
# Enable RLS
|
||||
db.instance_variable_get(:@connection).exec("ALTER TABLE bitacoras.events ENABLE ROW LEVEL SECURITY")
|
||||
|
||||
# Policies
|
||||
db.instance_variable_get(:@connection).exec("DROP POLICY IF EXISTS events_insert ON bitacoras.events")
|
||||
db.instance_variable_get(:@connection).exec("CREATE POLICY events_insert ON bitacoras.events FOR INSERT WITH CHECK (true)")
|
||||
|
||||
db.instance_variable_get(:@connection).exec("DROP POLICY IF EXISTS events_select ON bitacoras.events")
|
||||
db.instance_variable_get(:@connection).exec("CREATE POLICY events_select ON bitacoras.events FOR SELECT USING (true)")
|
||||
|
||||
db.instance_variable_get(:@connection).exec("DROP POLICY IF EXISTS events_update ON bitacoras.events")
|
||||
db.instance_variable_get(:@connection).exec("CREATE POLICY events_update ON bitacoras.events FOR UPDATE USING (true)")
|
||||
end
|
||||
puts "✅ Tabla bitacoras.events creada"
|
||||
end
|
||||
|
||||
def self.down
|
||||
BitacorasDB::BitacoraDB.with_connection do |db|
|
||||
db.instance_variable_get(:@connection).exec("DROP TABLE IF EXISTS bitacoras.events CASCADE")
|
||||
end
|
||||
puts "✅ Tabla bitacoras.events eliminada"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if __FILE__ == $PROGRAM_NAME
|
||||
BitacorasDB::Migrations::CreateEventsTable.up
|
||||
end
|
||||
Reference in New Issue
Block a user