source: docker-entrypoint.sh@ cc841a5

main
Last change on this file since cc841a5 was cc841a5, checked in by Tome <gjorgievtome@…>, 7 months ago

Add migration check

  • Property mode set to 100644
File size: 703 bytes
RevLine 
[05361b8]1#!/bin/sh
2set -e
3
4echo "Waiting for PostgreSQL to be ready..."
5
6until pg_isready -h db -U app -d postgres > /dev/null 2>&1; do
7 sleep 2
8done
9
[cc841a5]10echo "Checking if database needs migration..."
11TABLE_COUNT=$(psql -h db -U app -d postgres -t -c "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema='public';" 2>/dev/null || echo "0")
[05361b8]12
[cc841a5]13if [ "$TABLE_COUNT" -eq "0" ]; then
14 echo "Database is empty, running migrations..."
15 npm run drizzle:generate
16 npm run drizzle:migrate
[05361b8]17
[cc841a5]18 echo "Seeding database..."
19 npm run drizzle:seed
20else
21 echo "Database already initialized (found $TABLE_COUNT tables), skipping migrations and seed"
22fi
[05361b8]23
24echo "Starting application..."
[cc841a5]25exec node dist/server/index.mjs
Note: See TracBrowser for help on using the repository browser.