Fix jwt-token

This commit is contained in:
2025-09-20 22:46:48 +02:00
parent 216b2b152f
commit 66831cd2f0

View File

@@ -15,15 +15,36 @@ while ! nc -z postgres 5432; do
done done
echo "Database is ready!" echo "Database is ready!"
# Run database migrations as nodejs user # Check if this is a fresh database by looking for the devices table
echo "Running database migrations..." echo "Checking database state..."
su-exec nodejs npm run db:migrate if su-exec nodejs node -e "
const { Sequelize } = require('sequelize');
# Check if migrations were successful require('dotenv').config();
if [ $? -eq 0 ]; then const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
echo "Database migrations completed successfully" host: process.env.DB_HOST, port: process.env.DB_PORT, dialect: 'postgres', logging: false
});
sequelize.authenticate().then(() => {
return sequelize.getQueryInterface().describeTable('devices');
}).then(() => {
console.log('TABLES_EXIST');
process.exit(0);
}).catch(() => {
console.log('FRESH_DATABASE');
process.exit(0);
});
" | grep -q "FRESH_DATABASE"; then
echo "Fresh database detected. Running initial setup..."
su-exec nodejs npm run db:setup
else else
echo "Database migrations failed" echo "Existing database detected. Running migrations..."
su-exec nodejs npm run db:migrate
fi
# Check if setup/migrations were successful
if [ $? -eq 0 ]; then
echo "Database initialization completed successfully"
else
echo "Database initialization failed"
exit 1 exit 1
fi fi