Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>
Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.githu b.com> correcion de errores en llenado de tablas, primeras vistas frontend
This commit is contained in:
@@ -1,40 +1,28 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
from supabase import create_client, Client
|
||||
|
||||
# Configuración de directorios base
|
||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
DATA_DIR = os.path.join(BASE_DIR, "data")
|
||||
ENV_PATH = os.path.join(os.path.dirname(BASE_DIR), ".env")
|
||||
BASE_DIR = Path(__file__).parent.parent # backend/app/
|
||||
DATA_DIR = BASE_DIR / "data"
|
||||
ENV_PATH = BASE_DIR.parent / ".env" # backend/.env
|
||||
|
||||
def load_env(path: str):
|
||||
"""Carga variables de entorno de forma manual sin depender de python-dotenv"""
|
||||
if not os.path.exists(path):
|
||||
print(f"Advertencia: No se encontró el archivo {path}")
|
||||
return
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#'):
|
||||
# Separa por el primer '=' y limpia espacios y comillas
|
||||
key, val = line.split('=', 1)
|
||||
os.environ[key.strip()] = val.strip().strip("'").strip('"')
|
||||
|
||||
def load_json(filename: str):
|
||||
path = os.path.join(DATA_DIR, filename)
|
||||
with open(path, "r", encoding="utf-8") as f:
|
||||
with open(DATA_DIR / filename, encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
|
||||
|
||||
def main():
|
||||
print("Iniciando proceso de seeding...")
|
||||
load_env(ENV_PATH)
|
||||
load_dotenv(ENV_PATH)
|
||||
|
||||
# Es crucial usar SUPABASE_SERVICE_ROLE_KEY para saltar el RLS durante el Seed
|
||||
URL = os.environ.get("SUPABASE_URL")
|
||||
KEY = os.environ.get("SUPABASE_SERVICE_ROLE_KEY")
|
||||
|
||||
if not URL or not KEY:
|
||||
raise ValueError("Error: Asegúrate de tener SUPABASE_URL y SUPABASE_SERVICE_ROLE_KEY en el .env")
|
||||
raise ValueError("Falta SUPABASE_URL o SUPABASE_SERVICE_ROLE_KEY en el .env")
|
||||
|
||||
supabase: Client = create_client(URL, KEY)
|
||||
|
||||
@@ -99,7 +87,7 @@ def main():
|
||||
"turno": c["turno"],
|
||||
"horario_estimado": c["horario_estimado"]
|
||||
})
|
||||
supabase.table("colonias").upsert(colonias_to_insert).execute()
|
||||
supabase.table("colonias").upsert(colonias_to_insert, on_conflict="nombre").execute()
|
||||
|
||||
print("✅ Seed completado con éxito. Base de datos operativa para la app.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user