first MVP
This commit is contained in:
138
prisma/seed.ts
Normal file
138
prisma/seed.ts
Normal file
@@ -0,0 +1,138 @@
|
||||
// prisma/seed.ts
|
||||
import "dotenv/config";
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
type SeedPerson = {
|
||||
name: string;
|
||||
company?: string;
|
||||
role?: string;
|
||||
email?: string;
|
||||
location?: string;
|
||||
sectors?: string[];
|
||||
interests?: string[];
|
||||
};
|
||||
|
||||
const people: SeedPerson[] = [
|
||||
{ name: "Alex Carter", company: "GreenFields", role: "Founder", email: "alex@greenfields.io", location: "Brussels", sectors: ["agriculture", "sustainability"], interests: ["funding", "network"] },
|
||||
{ name: "John Miller", company: "BuildRight", role: "PM", email: "john@buildright.eu", location: "Amsterdam", sectors: ["construction"], interests: ["knowledge", "network"] },
|
||||
{ name: "Mark Li", company: "BioPharmX", role: "Analyst", email: "mark@biopharmx.com", location: "Zurich", sectors: ["pharma"], interests: ["team", "network"] },
|
||||
{ name: "Sara Gomez", company: "AeroNext", role: "VP BizDev", email: "sara@aeronext.ai", location: "Madrid", sectors: ["aerospace", "ai"], interests: ["funding"] },
|
||||
{ name: "Priya Nair", company: "AgriSense", role: "CTO", email: "priya@agrisense.io", location: "Bangalore", sectors: ["agriculture", "iot"], interests: ["network", "knowledge"] },
|
||||
{ name: "Luca Moretti", company: "Constructa", role: "Engineer", email: "luca@constructa.it", location: "Milan", sectors: ["construction"], interests: ["team"] },
|
||||
{ name: "Emily Chen", company: "FinScope", role: "Investor", email: "emily@finscope.vc", location: "London", sectors: ["finance"], interests: ["where to invest"] },
|
||||
{ name: "David Kim", company: "HealthBridge", role: "Founder", email: "david@healthbridge.io", location: "Seoul", sectors: ["healthcare", "pharma"], interests: ["funding", "network"] },
|
||||
{ name: "Nina Petrov", company: "EcoLogix", role: "Consultant", email: "nina@ecologix.de", location: "Berlin", sectors: ["sustainability"], interests: ["knowledge"] },
|
||||
{ name: "Omar Hassan", company: "BuildHub", role: "Architect", email: "omar@buildhub.me", location: "Dubai", sectors: ["construction"], interests: ["network"] },
|
||||
{ name: "Isabella Rossi", company: "AgriCo", role: "Ops Lead", email: "isabella@agrico.it", location: "Rome", sectors: ["agriculture"], interests: ["team"] },
|
||||
{ name: "Tom Williams", company: "MedNova", role: "Scientist", email: "tom@mednova.uk", location: "Oxford", sectors: ["pharma", "biotech"], interests: ["knowledge", "team"] },
|
||||
{ name: "Chen Wei", company: "SkyLink", role: "Systems Eng", email: "chen@skylink.cn", location: "Shanghai", sectors: ["aerospace"], interests: ["network"] },
|
||||
{ name: "Ana Silva", company: "GreenWave", role: "Analyst", email: "ana@greenwave.pt", location: "Lisbon", sectors: ["sustainability", "energy"], interests: ["where to invest"] },
|
||||
{ name: "Michael Brown", company: "FinBridge", role: "Partner", email: "michael@finbridge.vc", location: "New York", sectors: ["finance"], interests: ["where to invest", "network"] },
|
||||
{ name: "Yuki Tanaka", company: "BioCore", role: "Researcher", email: "yuki@biocore.jp", location: "Tokyo", sectors: ["biotech"], interests: ["knowledge", "team"] },
|
||||
{ name: "Fatima Zahra", company: "AgriRoot", role: "Founder", email: "fatima@agriroot.ma", location: "Casablanca", sectors: ["agriculture"], interests: ["funding", "network"] },
|
||||
{ name: "Peter Novak", company: "BuildSmart", role: "Engineer", email: "peter@buildsmart.cz", location: "Prague", sectors: ["construction", "iot"], interests: ["knowledge"] },
|
||||
{ name: "Sofia Anders", company: "NordPharm", role: "PM", email: "sofia@nordpharm.se", location: "Stockholm", sectors: ["pharma"], interests: ["network"] },
|
||||
{ name: "Rafael Diaz", company: "AeroLab", role: "Founder", email: "rafael@aerolab.mx", location: "Mexico City", sectors: ["aerospace"], interests: ["funding", "team"] },
|
||||
];
|
||||
|
||||
function pairKey(a: string, b: string) {
|
||||
return a < b ? `${a}|${b}` : `${b}|${a}`;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log("Seeding database…");
|
||||
|
||||
// Reset (dev only)
|
||||
await prisma.connection.deleteMany({});
|
||||
await prisma.person.deleteMany({});
|
||||
|
||||
// Create people
|
||||
const created = await Promise.all(
|
||||
people.map((p) =>
|
||||
prisma.person.create({
|
||||
data: {
|
||||
name: p.name,
|
||||
company: p.company ?? null,
|
||||
role: p.role ?? null,
|
||||
email: p.email ?? null,
|
||||
location: p.location ?? null,
|
||||
sectors: p.sectors ?? [],
|
||||
interests: p.interests ?? [],
|
||||
},
|
||||
select: { id: true, name: true },
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
const ids = created.map((c) => c.id);
|
||||
const idByName = new Map(created.map((c) => [c.name, c.id]));
|
||||
|
||||
// Create a set of sample undirected connections (about 28-32)
|
||||
const targetEdges = Math.min(32, Math.floor((ids.length * (ids.length - 1)) / 6));
|
||||
const used = new Set<string>();
|
||||
const rnd = (n: number) => Math.floor(Math.random() * n);
|
||||
|
||||
const edges: {
|
||||
a: string;
|
||||
b: string;
|
||||
introducedByChain: string[];
|
||||
eventLabels: string[];
|
||||
notes?: string | null;
|
||||
}[] = [];
|
||||
|
||||
let guard = 0;
|
||||
while (edges.length < targetEdges && guard < 5000) {
|
||||
guard++;
|
||||
const i = rnd(ids.length);
|
||||
let j = rnd(ids.length);
|
||||
if (j === i) continue;
|
||||
const a = ids[i];
|
||||
const b = ids[j];
|
||||
const key = pairKey(a, b);
|
||||
if (used.has(key)) continue;
|
||||
used.add(key);
|
||||
|
||||
// 50% add a single introducer different from a and b
|
||||
let introducedByChain: string[] = [];
|
||||
if (Math.random() < 0.5 && ids.length > 2) {
|
||||
let k = rnd(ids.length);
|
||||
let guard2 = 0;
|
||||
while ((k === i || k === j) && guard2 < 100) {
|
||||
k = rnd(ids.length);
|
||||
guard2++;
|
||||
}
|
||||
if (k !== i && k !== j) {
|
||||
introducedByChain = [ids[k]];
|
||||
}
|
||||
}
|
||||
|
||||
const eventLabels = Math.random() < 0.4 ? ["event:demo"] : [];
|
||||
edges.push({ a, b, introducedByChain, eventLabels, notes: null });
|
||||
}
|
||||
|
||||
for (const e of edges) {
|
||||
await prisma.connection.create({
|
||||
data: {
|
||||
personAId: e.a,
|
||||
personBId: e.b,
|
||||
introducedByChain: e.introducedByChain,
|
||||
eventLabels: e.eventLabels,
|
||||
notes: e.notes ?? null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
console.log(`Inserted ${created.length} people and ${edges.length} connections.`);
|
||||
}
|
||||
|
||||
main()
|
||||
.then(async () => {
|
||||
await prisma.$disconnect();
|
||||
})
|
||||
.catch(async (e) => {
|
||||
console.error(e);
|
||||
await prisma.$disconnect();
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user