Rip out inline JS from start.sh and use existing code

This commit is contained in:
antanst 2025-07-31 10:13:13 +03:00 committed by Chris
parent 49e7ee250b
commit 044fc1db1a

View file

@ -28,11 +28,11 @@ backup_db() {
# Check if database exists and create/authenticate
if [ ! -f "$DB_FILE" ]; then
echo "Creating new database..."
node -e "require(\"./models\").sequelize.sync({force:true}).then(()=>{console.log(\"DB ready\");process.exit(0)}).catch(e=>{console.error(\"❌\",e.message);process.exit(1)})"
node scripts/db-init.js
else
backup_db
echo "Checking database connection..."
node -e "require(\"./models\").sequelize.authenticate().then(()=>{console.log(\"DB OK\");process.exit(0)}).catch(e=>{console.error(\"❌\",e.message);process.exit(1)})"
node scripts/db-status.js
fi
# Run database migrations automatically
@ -44,7 +44,7 @@ else
fi
if [ -n "${TUDUDI_USER_EMAIL:-}" ] && [ -n "${TUDUDI_USER_PASSWORD:-}" ]; then
node -e "const{User}=require(\"./models\");const bcrypt=require(\"bcrypt\");(async()=>{try{const[u,c]=await User.findOrCreate({where:{email:process.env.TUDUDI_USER_EMAIL},defaults:{email:process.env.TUDUDI_USER_EMAIL,password_digest:await bcrypt.hash(process.env.TUDUDI_USER_PASSWORD,10)}});console.log(c?\"✅ User created\":\" User exists\");process.exit(0)}catch(e){console.error(\"❌\",e.message);process.exit(1)}})();" || exit 1
node scripts/user-create.js "$TUDUDI_USER_EMAIL" "$TUDUDI_USER_PASSWORD" || exit 1
fi
exec node app.js