snowva-backend / src /seed.ts
zerito's picture
Deploy backend update Tue Jan 20 16:29:46 CET 2026
4a51c37
Raw
History Blame Contribute Delete
18.9 kB
import sql from './db';
const routes = [
{
name: 'Vallée Blanche',
description: 'The legendary off-piste run from Aiguille du Midi.',
// Approximate path: Aiguille du Midi -> Mer de Glace -> Montenvers
coordinates: [
[6.886, 45.879, 3842], // Aiguille du Midi
[6.895, 45.885, 3500],
[6.905, 45.895, 3000],
[6.915, 45.905, 2500],
[6.925, 45.915, 2000],
[6.918, 45.925, 1913] // Montenvers
]
},
{
name: 'Le Brévent',
description: 'Sunny slopes with great views of Mont Blanc.',
// Approximate path: Brévent top -> Planpraz
coordinates: [
[6.837, 45.934, 2525], // Le Brévent
[6.845, 45.938, 2300],
[6.850, 45.940, 2100],
[6.855, 45.942, 2000] // Planpraz area
]
},
{
name: 'La Flégère',
description: 'Classic run in the Aiguilles Rouges.',
// Approximate path: Index -> Flégère
coordinates: [
[6.885, 45.960, 2385], // L'Index
[6.890, 45.955, 2200],
[6.895, 45.950, 2000],
[6.898, 45.945, 1877] // La Flégère
]
}
];
const adventures = [
{
name: 'Route Travail MBC',
description: 'Morning commute route to MBC',
user_id: 'demo_user',
difficulty: 'easy',
type: 'downhill',
coordinates: [
[6.8697427, 45.9272432, 1096.9000244140625],
[6.8698024, 45.9271583, 1096.9000244140625],
[6.8699343, 45.9271738, 1096.699951171875],
[6.8700793, 45.9271864, 1095.5999755859375],
[6.8701594, 45.9272616, 1095.5999755859375],
[6.8701511, 45.9273519, 1095.5999755859375],
[6.8701413, 45.9274425, 1095.5999755859375],
[6.8701461, 45.9275353, 1095.5999755859375],
[6.8701785, 45.9276224, 1095.5999755859375],
[6.8701915, 45.9277173, 1096.5999755859375],
[6.8702202, 45.9278074, 1096.5999755859375],
[6.8702697, 45.9278918, 1096.5999755859375],
[6.8703351, 45.9279698, 1096.5999755859375],
[6.8703026, 45.9280589, 1096.5999755859375],
[6.8703311, 45.9281596, 1098.300048828125],
[6.870453, 45.9281889, 1098.300048828125],
[6.870603, 45.9281428, 1098.300048828125],
[6.8707213, 45.9281017, 1098.300048828125],
[6.8708495, 45.9280713, 1098.300048828125],
[6.8709702, 45.9280302, 1098.300048828125],
[6.8710862, 45.9279821, 1098],
[6.8711965, 45.9279322, 1096.0960190128365],
[6.8713172, 45.927898, 1094],
[6.8714509, 45.9278981, 1094],
[6.8715628, 45.9278499, 1094],
[6.8716834, 45.9278169, 1094],
[6.8718103, 45.9277842, 1094],
[6.8719373, 45.9277579, 1094],
[6.8720694, 45.9277417, 1094],
[6.8722059, 45.9277352, 1094],
[6.8723404, 45.927748, 1093.300048828125],
[6.8724694, 45.9277737, 1093.300048828125],
[6.8725959, 45.9278143, 1093.300048828125],
[6.8727277, 45.9278438, 1093.300048828125],
[6.8728491, 45.9278807, 1093.300048828125],
[6.8729863, 45.92789, 1093.300048828125],
[6.8731123, 45.9278689, 1093.300048828125],
[6.8732376, 45.9278427, 1093.300048828125],
[6.8733375, 45.9277791, 1093.300048828125],
[6.8734157, 45.9277013, 1093.300048828125],
[6.8734976, 45.9276261, 1093.3355591062466],
[6.8735919, 45.9275631, 1092.9000244140625],
[6.8736965, 45.9275096, 1093.300048828125],
[6.8738264, 45.9274944, 1093.300048828125],
[6.8739655, 45.9274901, 1091.800048828125],
[6.8740987, 45.9274969, 1091.800048828125],
[6.8742208, 45.9274648, 1091.800048828125],
[6.874343, 45.9274361, 1091.800048828125],
[6.8744692, 45.9274062, 1091.800048828125],
[6.874587, 45.9273607, 1091.800048828125],
[6.8747058, 45.9273197, 1091.800048828125],
[6.8748116, 45.9272661, 1091.800048828125],
[6.8749095, 45.9272054, 1091.800048828125],
[6.8750177, 45.927156, 1091.800048828125],
[6.8751244, 45.9270982, 1091.800048828125],
[6.8752579, 45.9271073, 1091.800048828125],
[6.8753906, 45.9271014, 1091.800048828125],
[6.8754794, 45.9271773, 1091.800048828125],
[6.8755995, 45.9272159, 1091.800048828125],
[6.8757281, 45.9272475, 1091.800048828125],
[6.8757815, 45.9273313, 1091.800048828125],
[6.8758923, 45.9273866, 1091.800048828125],
[6.8759039, 45.92748, 1091.800048828125]
]
},
// "{\"type\":\"LineString\",\"coordinates\":[]}"
{
name: 'Randonnée de la Cascade du Dard',
description: 'Description de la Randonnée de la Cascade du Dard',
user_id: 'demo_user',
difficulty: 'easy',
type: 'hike',
coordinates: [
[6.8688945, 45.9157594, 1081.059146391384],
[6.8687993, 45.9156871, 1081.1997572270068],
[6.8686657, 45.9156825, 1081.4036592284929],
[6.8685408, 45.915629, 1082.397348537824],
[6.8684442, 45.9155681, 1082.9569458509607],
[6.8683146, 45.9155085, 1083.8154532303688],
[6.8682309, 45.9154362, 1084.3153061443656],
[6.8681209, 45.9153795, 1084.983486345155],
[6.8680333, 45.9153135, 1085.5151355257856],
[6.8679594, 45.9152368, 1086.0080363904394],
[6.8678467, 45.9151887, 1086.3440317833956],
[6.8677568, 45.9151204, 1087.154687009319],
[6.8676522, 45.9150627, 1088.5409838046298],
[6.867564, 45.9149893, 1087.9338532751465],
[6.8674663, 45.9149247, 1090.3846031523801],
[6.8673608, 45.9148593, 1090.0214557762363],
[6.8672689, 45.9147919, 1090.1862308992443],
[6.8671972, 45.9147122, 1090.7392181778926],
[6.8671259, 45.9146338, 1091.1668282557905],
[6.8670452, 45.914554, 1090.609045875886],
[6.8669413, 45.9144926, 1093.199951171875],
[6.86684, 45.9144293, 1093.5907640714677],
[6.8667362, 45.9143721, 1092.9802924763503],
[6.8666481, 45.9142939, 1092.121907866093],
[6.8665762, 45.9142181, 1092.5488095753228],
[6.8664866, 45.914145, 1092.8568225420609],
[6.8664007, 45.914077, 1093.1947403656488],
[6.8663124, 45.9140028, 1093.674653426672],
[6.8662081, 45.9139397, 1094.0948209539697],
[6.8661324, 45.913864, 1094.2890337348153],
[6.8660427, 45.913796, 1094.758338629102],
[6.8659641, 45.9137181, 1095.0348936996504],
[6.8658782, 45.9136447, 1095.4351044545836],
[6.8657867, 45.9135785, 1095.6289202683129],
[6.8657001, 45.9135039, 1096.0313616020155],
[6.8655878, 45.9134521, 1096.5490667514152],
[6.8654814, 45.9133896, 1096.8325498419586],
[6.865402, 45.9133117, 1097.3507996690475],
[6.8653074, 45.9132487, 1096.699951171875],
[6.8652045, 45.9131939, 1096.0999755859375],
[6.865116, 45.9131211, 1096.0999755859375],
[6.8650193, 45.9130553, 1096.0999755859375],
[6.8648857, 45.913052, 1096.699951171875],
[6.8647727, 45.9129978, 1096.699951171875],
[6.8646638, 45.9129417, 1097.0999755859375],
[6.8645559, 45.9128899, 1097.0999755859375],
[6.8644565, 45.9128277, 1097.0999755859375],
[6.8643389, 45.9127878, 1097.0999755859375],
[6.8642209, 45.9127485, 1097.0999755859375],
[6.864123, 45.9126859, 1097.0999755859375],
[6.8640082, 45.9126296, 1097.6987271229448],
[6.863883, 45.9125935, 1098.0380381656614],
[6.8638106, 45.912516, 1098.277248683673],
[6.8636812, 45.9125005, 1098.400975910045],
[6.8635572, 45.9124745, 1098.79533507723],
[6.8634366, 45.9124345, 1099.3355886400816],
[6.8633764, 45.9123533, 1098.94887663412],
[6.8634471, 45.9122519, 1099.334465347278],
[6.8634767, 45.9121629, 1099.9805819384444],
[6.8634276, 45.9120719, 1100.5168661046698],
[6.863442, 45.9119818, 1101.6319535351283],
[6.8634325, 45.9118896, 1102.2782625400798],
[6.8634589, 45.9117891, 1103.0334235043022],
[6.8634216, 45.9117027, 1103.9590501350813],
[6.8634198, 45.911608, 1104.8744936324656],
[6.8633532, 45.9115277, 1105.913546469489],
[6.8632231, 45.9114953, 1106.2592795372645],
[6.8631097, 45.9114485, 1106.7834400953755],
[6.862974, 45.9114356, 1107.448088712898],
[6.8629228, 45.9113475, 1108.7405101272748],
[6.8629741, 45.9112612, 1109.1600875213167],
[6.8630551, 45.9111893, 1109.8827013750902],
[6.863079, 45.9110941, 1111.2529379732653],
[6.8630283, 45.9110053, 1111.7883312056974],
[6.8629303, 45.9109357, 1112.7518912824064],
[6.8629026, 45.9108428, 1113.3934997681822],
[6.862939, 45.9107529, 1115.2904673708558],
[6.863008, 45.9106768, 1116.6572863838849],
[6.8630739, 45.9105929, 1117.779316663176],
[6.8630785, 45.9104989, 1118.367700587035],
[6.8632093, 45.9104501, 1122.7076367556194],
[6.8633322, 45.9104084, 1121.5885337942984],
[6.8634663, 45.9103844, 1121.6266247101298],
[6.8635911, 45.9103537, 1121.6198424705285],
[6.8637162, 45.9103179, 1121.795843789446],
[6.8638181, 45.9102568, 1121.9559551414527],
[6.8639298, 45.9102118, 1122.3771535576504],
[6.8640544, 45.910243, 1123.8156980438316],
[6.8641801, 45.9102711, 1125.304478912378],
[6.8642974, 45.9103199, 1127.2307005231908],
[6.864232, 45.9102389, 1131.0732677839962],
[6.8641727, 45.9101559, 1132.6865105632735],
[6.8641226, 45.9100723, 1134.0755281545366],
[6.8640815, 45.9099808, 1135.6915737477063],
[6.8640691, 45.9098891, 1138.1132282046071],
[6.8640031, 45.9098075, 1139.4874002759907],
[6.8638927, 45.9097522, 1141.2421705191425],
[6.863855, 45.9096625, 1143.1267834767593],
[6.8638765, 45.909572, 1144.0621933953391],
[6.8637847, 45.9094991, 1145.534466324627],
[6.8637039, 45.9094266, 1146.9916315229584],
[6.8636423, 45.9093448, 1147.9774530165907],
[6.8636167, 45.9092531, 1149.3156147425884],
[6.8636213, 45.9091554, 1151.4259209197805],
[6.8636006, 45.9090619, 1151.5267790048365],
[6.8635101, 45.9089932, 1151.74358575613],
[6.8634007, 45.9089375, 1152.2040609014698],
[6.8632593, 45.9089195, 1153.1528849220538],
[6.8631346, 45.9088902, 1153.0049541366707],
[6.863087, 45.9088032, 1152.7995268045836],
[6.8630824, 45.9087124, 1156.3446774600488],
[6.8630435, 45.9086252, 1158.922561695732],
[6.862957, 45.9085575, 1160.7090136078941],
[6.8628931, 45.9084714, 1163.0505113687307],
[6.8628848, 45.9083805, 1163.98397951416],
[6.8628238, 45.9083011, 1168.4292803700644],
[6.8627901, 45.9082069, 1169.900747794902],
[6.8627282, 45.9081252, 1174.2165031558236],
[6.862606, 45.9080938, 1176.0866616705248],
[6.8626716, 45.9080144, 1181.0728643104667],
[6.8626353, 45.9079268, 1182.1515601443607],
[6.8626268, 45.9078338, 1184.2375701159237],
[6.8625365, 45.9077625, 1186.4635136967004],
[6.862562, 45.9076679, 1189.9840597701184],
[6.8626656, 45.9076078, 1192.171128467262],
[6.8626633, 45.9075163, 1194.7407712262575],
[6.8627494, 45.9074424, 1196.356781211603],
[6.862771, 45.9073485, 1198.1916958320223],
[6.8626417, 45.9073265, 1198.2290803715518],
[6.8627017, 45.9074159, 1199.8748649578085],
[6.8626896, 45.9073251, 1199.511779286203],
[6.8626972, 45.9072322, 1201.9547563762574],
[6.862794, 45.907168, 1203.992082426708],
[6.8628181, 45.9070732, 1205.9514560626897],
[6.8627303, 45.9070002, 1209.3273718156995],
[6.8627545, 45.9069107, 1214.228093208831],
[6.8627555, 45.9068174, 1215.2585690683013],
[6.8627467, 45.9067199, 1214.8421159057605],
[6.8627419, 45.9066261, 1215.5552482700823],
[6.862723, 45.9065343, 1217.4668126854197],
[6.8626076, 45.9064859, 1219.4525534519125],
[6.8626105, 45.9063942, 1223.8877903384719],
[6.8626526, 45.9063049, 1226.4555866753378],
[6.8626347, 45.9062097, 1227.2012379532093],
[6.8626134, 45.9061202, 1227.1461595601897],
[6.8626837, 45.9060431, 1226.6809385798776],
[6.8627113, 45.9059514, 1220.5967582426733],
[6.86265, 45.9058654, 1221.779321839327],
[6.8625651, 45.9057914, 1226.8725652261244],
[6.8624669, 45.9057203, 1221.1619895603048],
[6.8623723, 45.9056485, 1222.0263371758126],
[6.8622728, 45.9055883, 1221.2221721751157],
[6.8621356, 45.9055845, 1220.1621979392714],
[6.8620212, 45.9055336, 1221.800269795361],
[6.8620631, 45.9054442, 1220.9568260154147],
[6.8619662, 45.9053766, 1225.19496822729],
[6.8618778, 45.9053105, 1225.7003474802566],
[6.861782, 45.9052426, 1226.1530111518266],
[6.8616612, 45.9052034, 1229.8937884787902],
[6.8615896, 45.905125, 1229.3889469829403],
[6.8615994, 45.9050318, 1231.618894736775],
[6.8615719, 45.9049426, 1235.0859446590077],
[6.8616801, 45.9048922, 1237.1585239376057],
[6.8617116, 45.9048014, 1238.2270198005094],
[6.861662, 45.9047132, 1239.81473378018],
[6.8616137, 45.9046244, 1243.4683243747838],
[6.861738, 45.9045886, 1247.4833257883215],
[6.861705, 45.9045015, 1250.6797443738924],
[6.8616792, 45.9044097, 1254.7991857101283],
[6.8618086, 45.9044022, 1259.7396283686414],
[6.8618767, 45.9043243, 1262.4694378570173],
[6.8619747, 45.9042654, 1261.5151116779657],
[6.8620653, 45.9041974, 1260.1425948382714],
[6.8619417, 45.904165, 1258.667735078068],
[6.8618501, 45.9040928, 1260.6551140242807],
[6.861811, 45.9040069, 1260.5299769306173],
[6.8617482, 45.9039249, 1261.059676443075],
[6.8618414, 45.9038609, 1262.4840879799542],
[6.8619723, 45.9038811, 1264.5966908674864],
[6.8619848, 45.9037911, 1266.1419472398497],
[6.8618724, 45.9037423, 1268.511885808514],
[6.8617832, 45.903672, 1271.5656901712935],
[6.8619164, 45.9036769, 1272.6906004317634],
[6.8620513, 45.9036957, 1274.755771966626],
[6.8621612, 45.9036392, 1277.0647415209692],
[6.8622299, 45.9037197, 1278.9232369875976],
[6.8623604, 45.9037063, 1275.9682320319018],
[6.8624479, 45.9036397, 1273.42321468037],
[6.8625808, 45.9036189, 1272.6875375696866],
[6.8625842, 45.903713, 1273.2155339369829]
]
}
];
async function seed() {
try {
console.log('Seeding database...');
// Ensure routes table exists
await sql`
CREATE TABLE IF NOT EXISTS routes (
id SERIAL PRIMARY KEY,
external_id VARCHAR(255),
name VARCHAR(255),
description TEXT,
path JSONB,
properties JSONB,
difficulty VARCHAR(50),
difficulty_convention VARCHAR(50),
type VARCHAR(50),
uses TEXT[],
ref VARCHAR(50),
oneway VARCHAR(50),
gladed VARCHAR(50),
patrolled VARCHAR(50),
lit VARCHAR(50),
grooming VARCHAR(50),
status VARCHAR(50),
websites TEXT[],
wikidata_id VARCHAR(255),
elevation_profile JSONB,
created_at TIMESTAMP DEFAULT NOW()
);
`;
// Ensure adventures table exists
await sql`
CREATE TABLE IF NOT EXISTS adventures (
id SERIAL PRIMARY KEY,
user_id VARCHAR(255),
name VARCHAR(255),
description TEXT,
path JSONB,
properties JSONB,
recorded_at TIMESTAMP,
created_at TIMESTAMP DEFAULT NOW()
);
`;
// Seed routes (public ski tracks)
// for (const route of routes) {
// const geojson = {
// type: 'LineString',
// coordinates: route.coordinates
// };
// await sql`
// INSERT INTO routes (name, description, path)
// VALUES (${route.name}, ${route.description}, ${JSON.stringify(geojson)})
// `;
// console.log(`Inserted route: ${route.name}`);
// }
// Seed adventures (user-saved activities)
for (const adventure of adventures) {
const geojson = {
type: 'LineString',
coordinates: adventure.coordinates
};
const properties = {
difficulty: adventure.difficulty,
type: adventure.type
};
await sql`
INSERT INTO adventures (user_id, name, description, path, properties, recorded_at)
VALUES (
${adventure.user_id},
${adventure.name},
${adventure.description || null},
${JSON.stringify(geojson)},
${JSON.stringify(properties)},
${new Date()}
)
`;
console.log(`Inserted adventure: ${adventure.name}`);
}
console.log('Seeding complete!');
await sql.end({ timeout: 5 });
process.exit(0);
} catch (err) {
console.error('Error seeding database:', err);
await sql.end({ timeout: 5 });
process.exit(1);
}
}
seed();