Fix jwt-token

This commit is contained in:
2025-09-21 09:03:09 +02:00
parent a1cf28f76a
commit e52d6a8384
3 changed files with 633 additions and 28 deletions

View File

@@ -17,28 +17,9 @@ echo "Database is ready!"
# Check if this is a fresh database by looking for the devices table
echo "Checking database state..."
if su-exec nodejs node -e "
const { Sequelize } = require('sequelize');
require('dotenv').config();
const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASSWORD, {
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
echo "Existing database detected. Running migrations..."
su-exec nodejs npm run db:migrate
fi
# Always run database setup (includes migrations + seeding if needed)
echo "Running database setup and migrations..."
su-exec nodejs npm run db:setup
# Check if setup/migrations were successful
if [ $? -eq 0 ]; then