diff --git a/backend/cmd/start.sh b/backend/cmd/start.sh index 2379d85..990900c 100755 --- a/backend/cmd/start.sh +++ b/backend/cmd/start.sh @@ -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