16 Commits
Author SHA1 Message Date
MichaelandClaude Fable 5 753b301066 perf: add missing indexes and remove N+1 queries
The app degraded progressively over a year of data growth. Four causes,
all cumulative:

1. No indexes. Apart from primary keys, unique constraints and
   session.expire, no table carried an index. PostgreSQL does not index
   foreign keys automatically, so every filter and join on group_id,
   supplier_id, order_id and the date columns did a sequential scan.
   Worst offender: user_groups.user_id, read by getUserWithGroups() on
   every authenticated request.

2. N+1 in the order and delivery listings. getOrders,
   getOrdersByDateRange, getDeliveries and getDeliveriesByDateRange
   issued one to two queries per row to load relations. Relations are now
   loaded in bulk and grouped in Node: three queries regardless of volume.

3. /api/sync-order-delivery-status reloaded the whole deliveries table on
   every iteration of its loop over orders. It now uses the deliveries
   getOrders() already attaches.

4. clearExpiredCache() was implemented but never called, so
   invoice_verification_cache grew without bound. Now scheduled every 6h.

Also replaces the full-history downloads on the Groups and Suppliers
pages, which fetched every order and delivery with nested relations only
to count rows, with aggregate endpoints that count in the database.

Indexes are created via scripts/auto-migrate-production.sh, the script
that actually runs at deploy time, using CREATE INDEX CONCURRENTLY so no
write lock is taken. Note that server/migrations.ts explicitly ignores
the migrations/ directory and runs only hardcoded migrations; the SQL
file added there is for reference and manual application.

Verified: typecheck baseline 440 errors, 430 after, none new in the
changed code; vite build passes; server boots; functional test confirms
the aggregate endpoints match the source data including the delivered
count.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-14 11:55:49 +02:00
michaelschal 2c36650edd Add SQL execution tool for administrators to manage database tables
Introduce a new admin-only utility tab allowing direct SQL query execution, file uploads (.sql), and logging of operations. Includes server-side endpoint and client-side UI for executing raw SQL commands against the database.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/ECRh2Iu
2025-09-03 14:11:12 +00:00
michaelschal 4ef702f44b Add SQL script to create missing webhook configuration table
Add SQL script `fix-webhook-bap-FINAL.sql` and shell script `scripts/manual-create-webhook-table.sh` to address the `relation "webhook_bap_config" does not exist` error by creating and populating the `webhook_bap_config` table.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/qkkp1hi
2025-09-03 14:04:25 +00:00
michaelschal ac9622233a Improve webhook configuration and database migration handling
Update docker-entrypoint.sh to ensure webhook_bap_config table creation and manage migration errors gracefully. Add default webhook configuration and handle potential database connection issues during script execution.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/qkkp1hi
2025-09-03 14:03:11 +00:00
michaelschal 3304d1c912 Add automatic creation of webhook configuration table during database migration
Modify the auto-migrate script to check for and create the `webhook_bap_config` table if it does not exist, including a default entry and description. Remove explicit migration calls from `server/index.ts` as they are now handled by the Docker entrypoint script.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/qkkp1hi
2025-09-03 13:58:55 +00:00
michaelschal bae218813b Automate database migration execution on production startup
Add logic to run database migrations automatically when the application starts in production. Includes a new migration script to create the webhook_bap_config table and a utility script for creating new migration files.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/baXszB8
2025-09-03 13:20:56 +00:00
michaelschal f938fdb95d Add configuration interface for enterprise task webhook
Implement a new UI component and backend routes for configuring and testing enterprise task webhooks, including database schema and migration scripts.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/vzUkIk6
2025-09-03 13:15:50 +00:00
michaelschal c851aacb28 Fix automatic database backup system for production
Resolves an issue where the automatic backup service was not initialized in the production environment, preventing daily backups. Updates `docker-compose.yml` to include a backup directory and volume, modifies `index.production.ts` to import and initialize the backup service, and enhances `replit.md` with details of the fix. A new verification script `scripts/verify-backup-system.sh` is added to confirm the system's functionality.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: cc2d271b-82f0-4d6a-9302-a0b067ffb429
Replit-Commit-Checkpoint-Type: full_checkpoint
2025-08-18 12:06:40 +00:00
michaelschal b383363e45 Ensure database tables are created automatically in production environments
Add a new script to synchronize missing database migrations and update the Docker entrypoint to execute it before starting the application.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm
2025-08-18 09:54:50 +00:00
michaelschal a2554c4962 Automate database migrations on Docker startup for production
Update Dockerfile and entrypoint script to automatically run database migrations and apply schema changes upon container initialization.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm
2025-08-18 09:39:20 +00:00
michaelschal 98d1e62200 Prepare system for database migrations and French localization improvements
Update Dockerfile to include migration scripts, configure PostgreSQL credentials in docker-compose.yml, and enhance the auto-migration script to support full database migration with French localization.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/JKfj3tT
2025-08-18 09:32:34 +00:00
michaelschal 785105814a Add stock depletion tracking for products
Introduce new columns to the products table to track stock depletion status, including who depleted it and when. This enhances product management by distinguishing between expired and out-of-stock items. This change includes database migrations, Docker updates, and deployment scripts to ensure a smooth rollout.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/JKfj3tT
2025-08-18 09:29:31 +00:00
michaelschal a4931ce1cd Add stock management for out-of-stock products and update deployment scripts
Implement new fields in the database and update deployment scripts to include a feature for managing out-of-stock products.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/JKfj3tT
2025-08-18 09:14:12 +00:00
michaelschal d45d3562ba Created a checkpoint
Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce/biGr9ER
2025-08-16 11:40:57 +00:00
michaelschal 0dc7ef49c0 Add a dedicated script for creating missing announcement tables
Introduce a new script `fix-announcements-only.sh` to specifically create the `announcements` table if it does not exist, streamlining the migration process for this critical component.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce/biGr9ER
2025-08-16 11:28:32 +00:00
michaelschal 74e7eb8118 Automate database table creation during Docker updates
Add scripts and Dockerfile modifications to ensure database tables are automatically created or updated when the Docker image is rebuilt and deployed.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce/biGr9ER
2025-08-16 11:25:04 +00:00