CoolFace
Apppublic

fmatituy/selectospromanager

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
migrate_epp.py64 linesDownload Raw Back to database
1import sqlite32import os3 4db_path = 'pro_manager.db'5if not os.path.exists(db_path):6    db_path = '../pro_manager.db'7 8conn = sqlite3.connect(db_path)9c = conn.cursor()10 11# 1. Catalogo de EPP e Inventario12c.execute('''13    CREATE TABLE IF NOT EXISTS sst_epp_catalogo (14        id INTEGER PRIMARY KEY AUTOINCREMENT,15        nombre TEXT NOT NULL,16        categoria TEXT, -- Cabeza, Manos, Alturas, etc.17        vida_util_meses INTEGER DEFAULT 12,18        descripcion TEXT,19        stock_minimo INTEGER DEFAULT 0,20        stock_actual INTEGER DEFAULT 0,21        ubicacion TEXT,22        fecha_ingreso TEXT23    )24''')25 26# 2. Registro de Entregas27c.execute('''28    CREATE TABLE IF NOT EXISTS sst_epp_entregas (29        id INTEGER PRIMARY KEY AUTOINCREMENT,30        trabajador_id INTEGER NOT NULL,31        epp_id INTEGER NOT NULL,32        fecha_entrega TEXT NOT NULL,33        cantidad INTEGER DEFAULT 1,34        estado_epp TEXT DEFAULT 'Nuevo', -- Nuevo, Usado35        fecha_vencimiento TEXT,36        firma_digital TEXT, -- Base64 o URL37        foto_url TEXT,38        observacion TEXT,39        responsable_id INTEGER,40        FOREIGN KEY (trabajador_id) REFERENCES usuarios (id),41        FOREIGN KEY (epp_id) REFERENCES sst_epp_catalogo (id),42        FOREIGN KEY (responsable_id) REFERENCES usuarios (id)43    )44''')45 46# 3. Reposiciones47c.execute('''48    CREATE TABLE IF NOT EXISTS sst_epp_reposiciones (49        id INTEGER PRIMARY KEY AUTOINCREMENT,50        trabajador_id INTEGER NOT NULL,51        epp_id INTEGER NOT NULL,52        motivo TEXT, -- Daño, Pérdida, Vencimiento53        fecha_solicitud TEXT,54        estado TEXT DEFAULT 'Pendiente', -- Pendiente, Aprobado, Entregado55        entrega_id_original INTEGER,56        FOREIGN KEY (trabajador_id) REFERENCES usuarios (id),57        FOREIGN KEY (epp_id) REFERENCES sst_epp_catalogo (id)58    )59''')60 61conn.commit()62conn.close()63print("Tablas de Gestión de EPP creadas exitosamente.")64