Files
Warracker/backend/migrations/010_configure_admin_roles.sql
sassanix 60239bd637 Fix Apprise notification system, scheduler stability, and email configuration
Fixes & Enhancements

* Resolved five critical Apprise notification issues:
  • Ensured configuration reload during scheduled jobs
  • Fixed warranty data fetching for Apprise-only users
  • Refactored notification dispatch logic with dedicated helpers
  • Corrected handler scoping via Flask app context
  • Wrapped scheduler jobs with Flask app context to prevent context errors
  → Verified: Scheduled Apprise notifications now work reliably for "Apprise only" and "Both" channels.

* Added support for SMTP\_FROM\_ADDRESS environment variable, allowing sender address customization independent of SMTP username. (PR #115)

* Fixed duplicate scheduled notifications in multi-worker environments:
  • Strengthened should\_run\_scheduler() logic
  • Now guarantees exactly one scheduler instance across all Gunicorn modes.

* Fixed stale database connection handling in scheduled jobs:
  • Fresh connection acquired each run, properly released via try/finally
  • Eliminates "server closed the connection" errors.

* Definitive scheduler logic fix for all memory modes (ultra-light, optimized, performance):
  • Single-worker runs scheduler if GUNICORN\_WORKER\_ID is unset
  • Multi-worker: only worker 0 runs scheduler.

Impact

* Apprise and Email notifications are now stable, reliable, and production-ready
* No more duplicate or missed notifications across all memory modes
* Improved system efficiency and robustness
2025-08-24 12:34:40 -03:00

46 lines
2.3 KiB
SQL

-- Migration: Configure PostgreSQL Admin Role
-- This is optional role management - will be skipped if permissions are insufficient
DO $$
BEGIN
-- Try to create admin role, but continue if it fails
BEGIN
-- Check if the db_admin_user exists, if not create it
IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '%(db_admin_user)s') THEN
CREATE ROLE %(db_admin_user)s WITH LOGIN PASSWORD '%(db_admin_password)s';
RAISE NOTICE 'Successfully created admin role %(db_admin_user)s';
END IF;
-- Grant privileges to the admin role
GRANT ALL PRIVILEGES ON DATABASE %(db_name)s TO %(db_admin_user)s;
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO %(db_admin_user)s;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO %(db_admin_user)s;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO %(db_admin_user)s;
-- Try to grant CREATEROLE, but continue if it fails
BEGIN
ALTER ROLE %(db_admin_user)s WITH CREATEROLE;
RAISE NOTICE 'Successfully granted CREATEROLE to %(db_admin_user)s';
EXCEPTION WHEN insufficient_privilege THEN
RAISE NOTICE 'Insufficient privileges to grant CREATEROLE to %(db_admin_user)s - role management features may be limited';
WHEN OTHERS THEN
RAISE NOTICE 'Could not grant CREATEROLE to %(db_admin_user)s - role management features may be limited';
END;
EXCEPTION WHEN insufficient_privilege THEN
RAISE NOTICE 'Insufficient privileges to create admin role %(db_admin_user)s - this is optional and the application will work without it';
WHEN OTHERS THEN
RAISE NOTICE 'Could not create admin role %(db_admin_user)s - this is optional and the application will work without it';
END;
END
$$;
-- Ensure the db_user can still access all application tables
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO %(db_user)s;
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO %(db_user)s;
GRANT ALL PRIVILEGES ON ALL FUNCTIONS IN SCHEMA public TO %(db_user)s;
-- Make db_admin_user the owner of all existing users
-- Note: This would require superuser privileges to execute
-- ALTER ROLE %(db_user)s OWNER TO %(db_admin_user)s;