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
|
| Line | |
|---|
| 1 | #!/bin/sh
|
|---|
| 2 | set -e
|
|---|
| 3 |
|
|---|
| 4 | echo "Waiting for PostgreSQL to be ready..."
|
|---|
| 5 |
|
|---|
| 6 | until pg_isready -h db -U app -d postgres > /dev/null 2>&1; do
|
|---|
| 7 | sleep 2
|
|---|
| 8 | done
|
|---|
| 9 |
|
|---|
| 10 | echo "Checking if database needs migration..."
|
|---|
| 11 | TABLE_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")
|
|---|
| 12 |
|
|---|
| 13 | if [ "$TABLE_COUNT" -eq "0" ]; then
|
|---|
| 14 | echo "Database is empty, running migrations..."
|
|---|
| 15 | npm run drizzle:generate
|
|---|
| 16 | npm run drizzle:migrate
|
|---|
| 17 |
|
|---|
| 18 | echo "Seeding database..."
|
|---|
| 19 | npm run drizzle:seed
|
|---|
| 20 | else
|
|---|
| 21 | echo "Database already initialized (found $TABLE_COUNT tables), skipping migrations and seed"
|
|---|
| 22 | fi
|
|---|
| 23 |
|
|---|
| 24 | echo "Starting application..."
|
|---|
| 25 | exec node dist/server/index.mjs |
|---|
Note:
See
TracBrowser
for help on using the repository browser.