initial commit
This commit is contained in:
89
backend/seed.js
Normal file
89
backend/seed.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.join(__dirname, 'awards.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
const awardTemplates = [
|
||||
"Most Dog Friendly", "Biggest Cactus", "Most Likely to be a Jungle", "Best Tacos", "Most Colorful House",
|
||||
"Best Surf Spot", "Most Palm Trees", "Best Sunset View", "Most Beach Vibes", "Best Coffee Shop",
|
||||
"Most Instagrammable", "Best Pizza", "Most Relaxing", "Best Ice Cream", "Most Artistic",
|
||||
"Best Seafood", "Most Tropical", "Best Breakfast", "Most Peaceful", "Best Mexican Food",
|
||||
"Most Oceanfront", "Best Smoothies", "Most Lively", "Best Burgers", "Most Zen",
|
||||
"Best Sushi", "Most Vibrant", "Best Acai Bowl", "Most Welcoming", "Best Thai Food",
|
||||
"Most Scenic", "Best Juice Bar", "Most Energetic", "Best Italian", "Most Serene",
|
||||
"Best Fish Tacos", "Most Dynamic", "Best Smoothie Bowl", "Most Friendly", "Best Indian Food",
|
||||
"Most Picturesque", "Best Tea House", "Most Exciting", "Best Greek Food", "Most Tranquil",
|
||||
"Best Burritos", "Most Active", "Best Poke Bowl", "Most Hospitable", "Best Mediterranean"
|
||||
];
|
||||
|
||||
const realPBAddresses = [
|
||||
"4500 Ocean Blvd, San Diego, CA 92109",
|
||||
"710 Garnet Ave, San Diego, CA 92109",
|
||||
"976 Felspar St, San Diego, CA 92109",
|
||||
"4325 Mission Blvd, San Diego, CA 92109",
|
||||
"5010 Cass St, San Diego, CA 92109",
|
||||
"744 Ventura Pl, San Diego, CA 92109",
|
||||
"4150 Mission Blvd, San Diego, CA 92109",
|
||||
"909 Garnet Ave, San Diego, CA 92109",
|
||||
"3704 Mission Blvd, San Diego, CA 92109",
|
||||
"1860 Grand Ave, San Diego, CA 92109"
|
||||
];
|
||||
|
||||
const realPBCoords = [
|
||||
{ lat: 32.7977, lng: -117.2551 }, // 4500 Ocean Blvd
|
||||
{ lat: 32.7979, lng: -117.2542 }, // 710 Garnet Ave
|
||||
{ lat: 32.7975, lng: -117.2520 }, // 976 Felspar St
|
||||
{ lat: 32.7972, lng: -117.2525 }, // 4325 Mission Blvd
|
||||
{ lat: 32.8002, lng: -117.2527 }, // 5010 Cass St
|
||||
{ lat: 32.7701, lng: -117.2523 }, // 744 Ventura Pl
|
||||
{ lat: 32.7970, lng: -117.2540 }, // 4150 Mission Blvd
|
||||
{ lat: 32.7978, lng: -117.2530 }, // 909 Garnet Ave
|
||||
{ lat: 32.7973, lng: -117.2522 }, // 3704 Mission Blvd
|
||||
{ lat: 32.8010, lng: -117.2420 } // 1860 Grand Ave
|
||||
];
|
||||
|
||||
function seedAwards() {
|
||||
db.serialize(() => {
|
||||
db.run(`CREATE TABLE IF NOT EXISTS awards (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
category TEXT NOT NULL,
|
||||
address TEXT NOT NULL,
|
||||
emoji_tally TEXT DEFAULT '{}',
|
||||
submitted_by VARCHAR(255),
|
||||
submitted_date DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
approved_date DATETIME,
|
||||
lat REAL,
|
||||
lng REAL
|
||||
)`);
|
||||
|
||||
let remaining = awardTemplates.length;
|
||||
awardTemplates.forEach((title, index) => {
|
||||
const address = realPBAddresses[index % realPBAddresses.length];
|
||||
const coords = realPBCoords[index % realPBCoords.length];
|
||||
db.get('SELECT * FROM awards WHERE category = ? AND address = ?', [title, address], (err, row) => {
|
||||
if (err) console.error(err);
|
||||
if (!row) {
|
||||
const approvedDate = title.startsWith('Best') ? null : 'CURRENT_TIMESTAMP';
|
||||
const sql = approvedDate
|
||||
? 'INSERT INTO awards (category, address, submitted_by, emoji_tally, submitted_date, approved_date, lat, lng) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP, ?, ?)'
|
||||
: 'INSERT INTO awards (category, address, submitted_by, emoji_tally, submitted_date, approved_date, lat, lng) VALUES (?, ?, ?, ?, CURRENT_TIMESTAMP, NULL, ?, ?)';
|
||||
db.run(
|
||||
sql,
|
||||
[title, address, null, '{}', coords.lat, coords.lng],
|
||||
(err) => {
|
||||
if (err) console.error(err);
|
||||
else console.log(`Inserted: ${title}`);
|
||||
if (--remaining === 0) db.close();
|
||||
}
|
||||
);
|
||||
} else {
|
||||
if (--remaining === 0) db.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
if (awardTemplates.length === 0) db.close();
|
||||
});
|
||||
}
|
||||
|
||||
seedAwards();
|
||||
Reference in New Issue
Block a user