#!/bin/sh
# Fix: جداول farm_data وجود ندارند اما migrationهای legacy با label قدیمی ثبت شده‌اند.
# اجرا: docker compose run --rm web sh /app/scripts/fix_farm_data_tables.sh
set -e
cd /app
echo "Resetting legacy sensor_data migrations (fake unapply - tables may not exist)..."
python manage.py migrate sensor_data zero --noinput --fake
echo "Re-applying legacy sensor_data migrations (--fake-initial if tables already exist)..."
python manage.py migrate sensor_data --noinput --fake-initial
echo "Done. Running seed_sensor_parameters..."
python manage.py seed_sensor_parameters
echo "All done."
