File size: 3,254 Bytes
83f4356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ac2662d
83f4356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a4d7990
83f4356
 
 
 
 
 
 
 
 
a4d7990
83f4356
 
 
 
 
 
 
 
 
a4d7990
83f4356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**
 * Seed Test Data Script
 * 
 * Adds 3 "Available Plants" and 1 "Community Post" for testing the Adopter's dashboard.
 * Associated with the Admin user.
 */

require('dotenv').config();
const { createClient } = require('@supabase/supabase-js');

const supabaseAdmin = createClient(
  process.env.SUPABASE_URL,
  process.env.SUPABASE_SERVICE_ROLE_KEY
);

async function seedTestData() {
  console.log('๐ŸŒฑ Seeding test data for User Dashboard...\n');

  // 1. Get Admin User
  const adminEmail = process.env.ADMIN_EMAIL || 'admin@greenguard.in';
  const { data: admin, error: adminError } = await supabaseAdmin
    .from('profiles')
    .select('id')
    .eq('email', adminEmail)
    .single();

  if (adminError || !admin) {
    console.error('โŒ Admin user not found. Run seed-admin.js first.');
    process.exit(1);
  }

  const adminId = admin.id;

  // 2. Add Plants (Pune Coordinates)
  console.log('๐ŸŒต Adding 3 test plants...');
  const testPlants = [
    {
      ngo_id: adminId,
      plant_name: 'Urban Ficus',
      species: 'Ficus Benjamina',
      description: 'A beautiful indoor plant, great for air purification.',
      image_urls: ['https://images.unsplash.com/photo-1598512752271-33f913a5af13?auto=format&fit=crop&q=80&w=400'],
      location: 'SRID=4326;POINT(73.8567 18.5204)', // Longitude Latitude
      address: 'Near Shaniwar Wada, Pune',
      adoption_status: 'available'
    },
    {
      ngo_id: adminId,
      plant_name: 'Desert Aloe',
      species: 'Aloe Vera',
      description: 'Hardy and medicinal. Perfect for a sunny balcony.',
      image_urls: ['https://images.unsplash.com/photo-1596547609652-9cf5d8d76921?auto=format&fit=crop&q=80&w=400'],
      location: 'SRID=4326;POINT(73.9272 18.5089)', // Hadapsar area
      address: 'Magarpatta City, Pune',
      adoption_status: 'available'
    },
    {
      ngo_id: adminId,
      plant_name: 'Garden Hibiscus',
      species: 'Hibiscus Rosa-sinensis',
      description: 'Produces vibrant red flowers. Needs daily watering.',
      image_urls: ['https://images.unsplash.com/photo-1591880911855-40899478f771?auto=format&fit=crop&q=80&w=400'],
      location: 'SRID=4326;POINT(73.8340 18.5283)', // Shivaji Nagar
      address: 'Shivajinagar, Pune',
      adoption_status: 'available'
    }
  ];

  const { error: plantError } = await supabaseAdmin.from('plants').insert(testPlants);

  if (plantError) {
    console.error('โŒ Failed to seed plants:', plantError.message);
  } else {
    console.log('โœ… 3 Plants seeded.');
  }

  // 3. Add a Post
  console.log('๐Ÿ“œ Adding a community post...');
  const { error: postError } = await supabaseAdmin.from('posts').insert({
    author_id: adminId,
    content: 'Welcome to GreenGuard! ๐ŸŒฟ We just added 3 new plants available for adoption in the Pune area. Check the map to see their locations!',
    image_urls: ['https://images.unsplash.com/photo-1524486361537-8ad15938e1a3?auto=format&fit=crop&q=80&w=600']
  });

  if (postError) {
    console.error('โŒ Failed to seed post:', postError.message);
  } else {
    console.log('โœ… Community post seeded.');
  }

  console.log('\nโœจ Seeding completed!');
}

seedTestData().catch(err => {
  console.error('\nโŒ Fatal error:', err);
  process.exit(1);
});