From 037c4baf1b8304005ed068f46bf583ad4af060e6 Mon Sep 17 00:00:00 2001 From: ronalds Date: Tue, 9 Dec 2025 00:46:16 -0300 Subject: [PATCH] =?UTF-8?q?Ejemplo=20con=20la=20inspecci=C3=B3n=20250:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guardado en BD: 2025-12-08 19:11:30+00 (hora de Canarias) Mostrado en tu cliente: 2025-12-08 16:11:30-03 (convertido a Paraguay, 3 horas menos) Ambas representan el MISMO momento en el tiempo, solo que en zonas horarias diferentes. 🌍 Resumen del Sistema Componente Zona Horaria Estado PostgreSQL (almacenamiento) +00 Atlantic/Canary ✅ CORRECTO Backend FastAPI Atlantic/Canary ✅ CORRECTO Frontend (usuario) Local del navegador ✅ CORRECTO (convierte automáticamente) Tu cliente PostgreSQL -0300 Paraguay ℹ️ Solo afecta cómo VES las fechas 💡 Conclusión --- apply-timezone.bat | 40 ++++++++++++++++++++++ apply-timezone.sh | 39 +++++++++++++++++++++ docker-compose.yml | 2 ++ init-db.sh | 9 ++++- migrations/force_timezone_all_sessions.sql | 17 +++++++++ postgres-custom.conf | 24 +++++++++++++ 6 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 apply-timezone.bat create mode 100644 apply-timezone.sh create mode 100644 migrations/force_timezone_all_sessions.sql create mode 100644 postgres-custom.conf diff --git a/apply-timezone.bat b/apply-timezone.bat new file mode 100644 index 0000000..ad1b71e --- /dev/null +++ b/apply-timezone.bat @@ -0,0 +1,40 @@ +@echo off +echo ==================================== +echo Aplicando configuracion de timezone +echo ==================================== + +echo. +echo 1. Copiando script de migracion... +docker cp migrations/force_timezone_all_sessions.sql checklist-db:/tmp/ + +echo. +echo 2. Ejecutando migracion en checklist_db... +docker exec checklist-db psql -U checklist_user -d checklist_db -f /tmp/force_timezone_all_sessions.sql + +echo. +echo 3. Ejecutando migracion en syntria_db (si existe)... +docker exec checklist-db psql -U checklist_user -d postgres -c "SELECT 1 FROM pg_database WHERE datname = 'syntria_db'" | find "1" >nul +if %ERRORLEVEL% equ 0 ( + docker exec checklist-db psql -U syntria_user -d syntria_db -f /tmp/force_timezone_all_sessions.sql + echo Migración aplicada a syntria_db +) else ( + echo syntria_db no existe, omitiendo... +) + +echo. +echo 4. Recargando configuracion de PostgreSQL... +docker exec checklist-db psql -U checklist_user -d checklist_db -c "SELECT pg_reload_conf();" + +echo. +echo 5. Verificando timezone... +docker exec checklist-db psql -U checklist_user -d checklist_db -c "SHOW timezone;" + +echo. +echo ==================================== +echo Completado! +echo ==================================== +echo. +echo IMPORTANTE: Desconecta y reconecta tu cliente PostgreSQL +echo para que aplique la nueva zona horaria. +echo. +pause diff --git a/apply-timezone.sh b/apply-timezone.sh new file mode 100644 index 0000000..839b5c6 --- /dev/null +++ b/apply-timezone.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +echo "====================================" +echo "Aplicando configuración de timezone" +echo "====================================" + +echo "" +echo "1. Copiando script de migración..." +docker cp migrations/force_timezone_all_sessions.sql checklist-db:/tmp/ + +echo "" +echo "2. Ejecutando migración en checklist_db..." +docker exec checklist-db psql -U checklist_user -d checklist_db -f /tmp/force_timezone_all_sessions.sql + +echo "" +echo "3. Ejecutando migración en syntria_db (si existe)..." +if docker exec checklist-db psql -U checklist_user -d postgres -tc "SELECT 1 FROM pg_database WHERE datname = 'syntria_db'" | grep -q 1; then + docker exec checklist-db psql -U syntria_user -d syntria_db -f /tmp/force_timezone_all_sessions.sql + echo "Migración aplicada a syntria_db" +else + echo "syntria_db no existe, omitiendo..." +fi + +echo "" +echo "4. Recargando configuración de PostgreSQL..." +docker exec checklist-db psql -U checklist_user -d checklist_db -c "SELECT pg_reload_conf();" + +echo "" +echo "5. Verificando timezone..." +docker exec checklist-db psql -U checklist_user -d checklist_db -c "SHOW timezone;" + +echo "" +echo "====================================" +echo "Completado!" +echo "====================================" +echo "" +echo "IMPORTANTE: Desconecta y reconecta tu cliente PostgreSQL" +echo "para que aplique la nueva zona horaria." +echo "" diff --git a/docker-compose.yml b/docker-compose.yml index 8ddc7a7..0e36d77 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,6 +13,8 @@ services: volumes: - postgres_data:/var/lib/postgresql/data - ./init-db.sh:/docker-entrypoint-initdb.d/init-db.sh + - ./postgres-custom.conf:/etc/postgresql/postgresql.conf + command: postgres -c config_file=/etc/postgresql/postgresql.conf healthcheck: test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-checklist_user} -d ${POSTGRES_DB:-checklist_db}"] interval: 10s diff --git a/init-db.sh b/init-db.sh index 596cbff..7f4837a 100644 --- a/init-db.sh +++ b/init-db.sh @@ -2,12 +2,19 @@ set -e psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL + -- Configurar zona horaria Atlantic/Canary + ALTER DATABASE "$POSTGRES_DB" SET timezone TO 'Atlantic/Canary'; + ALTER ROLE "$POSTGRES_USER" SET timezone TO 'Atlantic/Canary'; + -- Verificar que la base de datos existe SELECT 'Database is ready!' as status; -- Crear extensiones si son necesarias CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; + + -- Mostrar zona horaria configurada + SHOW timezone; EOSQL -echo "Database initialization completed successfully!" +echo "Database initialization completed successfully with timezone: Atlantic/Canary" diff --git a/migrations/force_timezone_all_sessions.sql b/migrations/force_timezone_all_sessions.sql new file mode 100644 index 0000000..d46cda5 --- /dev/null +++ b/migrations/force_timezone_all_sessions.sql @@ -0,0 +1,17 @@ +-- Forzar zona horaria Atlantic/Canary en TODAS las sesiones +-- Esto anula cualquier configuración del cliente + +-- 1. Establecer timezone por defecto para la base de datos +ALTER DATABASE checklist_db SET timezone TO 'Atlantic/Canary'; +ALTER DATABASE syntria_db SET timezone TO 'Atlantic/Canary'; + +-- 2. Establecer timezone por defecto para todos los usuarios +ALTER ROLE checklist_user SET timezone TO 'Atlantic/Canary'; +ALTER ROLE syntria_user SET timezone TO 'Atlantic/Canary'; +ALTER ROLE postgres SET timezone TO 'Atlantic/Canary'; + +-- 3. Verificar configuración actual +SHOW timezone; + +-- 4. Para aplicar los cambios, desconectar y reconectar +-- O forzar: SELECT pg_reload_conf(); diff --git a/postgres-custom.conf b/postgres-custom.conf new file mode 100644 index 0000000..beff017 --- /dev/null +++ b/postgres-custom.conf @@ -0,0 +1,24 @@ +# Configuración de PostgreSQL para Ayutec +# Zona horaria: Atlantic/Canary (Islas Canarias, España) + +# ZONA HORARIA +timezone = 'Atlantic/Canary' +log_timezone = 'Atlantic/Canary' + +# LOCALE (opcional - para formato de fechas en español) +lc_messages = 'es_ES.UTF-8' +lc_monetary = 'es_ES.UTF-8' +lc_numeric = 'es_ES.UTF-8' +lc_time = 'es_ES.UTF-8' + +# CONEXIONES +max_connections = 100 +shared_buffers = 256MB + +# LOGGING +logging_collector = on +log_directory = 'pg_log' +log_filename = 'postgresql-%Y-%m-%d_%H%M%S.log' +log_statement = 'mod' # Registrar INSERT, UPDATE, DELETE +log_duration = on +log_line_prefix = '%t [%p]: [%l-1] user=%u,db=%d,app=%a,client=%h '