- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.js
More file actions
Latest commit
53 lines (42 loc) · 2.37 KB
/
Copy pathseed.js
File metadata and controls
53 lines (42 loc) · 2.37 KB
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
import{initializeApp}from"firebase/app";
import{getFirestore,collection,addDoc,Timestamp}from"firebase/firestore";
importfsfrom"fs";
importpathfrom"path";
constconfigPath=path.join(process.cwd(),"firebase-applet-config.json");
constfirebaseConfig=JSON.parse(fs.readFileSync(configPath,"utf-8"));
constapp=initializeApp(firebaseConfig);
constdb=firebaseConfig.firestoreDatabaseId
? getFirestore(app,firebaseConfig.firestoreDatabaseId)
: getFirestore(app);
asyncfunctionseed(){
console.log("Seeding data...");
// 1. Stores
conststore1=awaitaddDoc(collection(db,"stores"),{name: "Downtown NYC",address: "123 Broadway, NY"});
conststore2=awaitaddDoc(collection(db,"stores"),{name: "SF Hub",address: "456 Market St, SF"});
console.log("Stores seeded");
// 2. Products
constp1=awaitaddDoc(collection(db,"products"),{name: "MacBook Pro",category: "Electronics",price: 1999.99,sku: "MBP-2024"});
constp2=awaitaddDoc(collection(db,"products"),{name: "iPhone 15",category: "Mobile",price: 999.99,sku: "IP15-64"});
constp3=awaitaddDoc(collection(db,"products"),{name: "Ergonomic Chair",category: "Furniture",price: 299.50,sku: "CH-ERG-01"});
console.log("Products seeded");
// 3. Inventory
awaitaddDoc(collection(db,"inventory"),{productId: p1.id,storeId: store1.id,stockLevel: 25});
awaitaddDoc(collection(db,"inventory"),{productId: p2.id,storeId: store1.id,stockLevel: 50});
awaitaddDoc(collection(db,"inventory"),{productId: p3.id,storeId: store1.id,stockLevel: 10});
awaitaddDoc(collection(db,"inventory"),{productId: p1.id,storeId: store2.id,stockLevel: 15});
console.log("Inventory seeded");
// 4. Sample Orders for analytics
constc1=awaitaddDoc(collection(db,"customers"),{name: "John Doe",email: "john@example.com",phone: "555-0101"});
consto1=awaitaddDoc(collection(db,"orders"),{
customerId: c1.id,
storeId: store1.id,
totalPrice: 2299.49,
date: Timestamp.fromDate(newDate(2025,2,15)),// March 15, 2025
status: "completed"
});
awaitaddDoc(collection(db,"orderItems"),{orderId: o1.id,productId: p1.id,quantity: 1,price: 1999.99});
awaitaddDoc(collection(db,"orderItems"),{orderId: o1.id,productId: p3.id,quantity: 1,price: 299.50});
console.log("Seeding complete!");
process.exit(0);
}
seed();