Skip to content

Commit b829e34

Browse files
authored
Merge pull request #41 from topcoder-platform/auto-migrations
Automate migrations
2 parents 016a1b3 + 6c0e4d8 commit b829e34

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

docker/Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ ENV PRISMA_LOG_LEVEL=info
1919

2020
RUN mkdir -p /challenge-api/reports
2121

22-
CMD ["node","/challenge-api/app.js"]
22+
# Copy entrypoint script and make it executable
23+
COPY docker/entrypoint.sh /entrypoint.sh
24+
RUN chmod +x /entrypoint.sh
25+
26+
# Use entrypoint to run migrations at startup (not build time)
27+
# Prisma uses PostgreSQL advisory locks to prevent concurrent migrations
28+
ENTRYPOINT ["/entrypoint.sh"]

docker/entrypoint.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/sh
2+
set -e
3+
4+
echo "Starting Challenge API v6..."
5+
6+
# Run database migrations
7+
# Prisma uses PostgreSQL advisory locks to prevent concurrent migrations
8+
# Only one instance will run migrations, others will wait
9+
echo "Running database migrations..."
10+
npx prisma migrate deploy
11+
12+
# Check migration status
13+
if [ $? -eq 0 ]; then
14+
echo "Migrations completed successfully"
15+
else
16+
echo "Migration failed with exit code $?"
17+
exit 1
18+
fi
19+
20+
# Start the application
21+
echo "Starting application server..."
22+
exec node /challenge-api/app.js

0 commit comments

Comments
 (0)