123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Casts\Attribute;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Storage;
  6. use Spatie\Translatable\HasTranslations;
  7. class Badge extends Model
  8. {
  9. use HasTranslations;
  10. protected $guarded = ["id"];
  11. public $translatable = ["title"];
  12. protected $appends = ["img_url_link"];
  13. protected function imgUrlLink(): Attribute
  14. {
  15. return Attribute::make(
  16. get: fn ($value) => is_null($this->img_url) ? null :Storage::url($this->img_url),
  17. );
  18. }
  19. public function projects()
  20. {
  21. return $this->morphedByMany(Project::class, 'badgeable');
  22. }
  23. }
  24. #!/bin/bash
  25. # =============================================================================
  26. # Fresh Export + Ready-to-use SCP command for operators
  27. # Run this on your backend server when someone requests today's data
  28. # =============================================================================
  29. set -e # Stop on any error
  30. # Config
  31. DB_PATH="$HOME/backend/surveys.db"
  32. EXPORT_DIR="$HOME/backend/exports"
  33. DATE=$(date +%Y%m%d) # e.g. 20251121
  34. TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
  35. mkdir -p "$EXPORT_DIR"
  36. MAIN_CSV="$EXPORT_DIR/surveys_${DATE}.csv"
  37. GB_CSV="$EXPORT_DIR/gb_surveys_${DATE}.csv"
  38. echo "=================================================="
  39. echo "Exporting fresh data for $DATE"
  40. echo "Started at: $TIMESTAMP"
  41. echo "=================================================="
  42. # Export main surveys
  43. sqlite3 "$DB_PATH" <<SQL
  44. .headers on
  45. .mode csv
  46. .output "$MAIN_CSV"
  47. SELECT
  48. id, name, email, phone, company, department, title,
  49. utm_source, utm_medium, utm_campaign,
  50. answer1, answer2, answer3, answer4, answer5,
  51. created_at, completed_at
  52. FROM surveys
  53. ORDER BY created_at DESC;
  54. SQL
  55. # Export GB surveys
  56. sqlite3 "$DB_PATH" <<SQL
  57. .headers on
  58. .mode csv
  59. .output "$GB_CSV"
  60. SELECT
  61. id, name, email, phone, company, department, note,
  62. utm_source, utm_medium, utm_campaign,
  63. created_at
  64. FROM gb_surveys
  65. ORDER BY created_at DESC;
  66. SQL
  67. # Count records
  68. MAIN_COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM surveys;")
  69. GB_COUNT=$(sqlite3 "$DB_PATH" "SELECT COUNT(*) FROM gb_surveys;")
  70. echo ""
  71. echo "SUCCESS! Files created:"
  72. echo " → $MAIN_CSV ($MAIN_COUNT records)"
  73. echo " → $GB_CSV ($GB_COUNT records)"
  74. echo ""
  75. echo "=================================================="
  76. echo "COPY-PASTE THIS TO DOWNLOAD:"
  77. echo ""
  78. echo "scp -i dell.pem ubuntu@43.207.13.55:~backend/exports/surveys_${DATE}.csv ~/Downloads/"
  79. echo "scp -i dell.pem ubuntu@43.207.13.55:~backend/exports/gb_surveys_${DATE}.csv ~/Downloads/"
  80. echo ""
  81. echo "Or download both at once:"
  82. echo "scp -i dell.pem ubuntu@43.207.13.55:~backend/exports/*_${DATE}.csv ~/Downloads/"
  83. echo ""
  84. echo "Finished at: $(date '+%Y-%m-%d %H:%M:%S')"
  85. echo "=================================================="