-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.ts
58 lines (46 loc) · 1.35 KB
/
seed.ts
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
import { PrismaClient } from "@prisma/client";
import bcrypt from "bcryptjs";
import { importSource } from "~/lib/importer.server";
import { saveSource } from "~/models/source.server";
const prisma = new PrismaClient();
async function seed() {
const email = "testuser@foobar.com";
// cleanup the existing database
await prisma.user.delete({ where: { email } }).catch(() => {
// no worries if it doesn't exist yet
});
const hashedPassword = await bcrypt.hash("testuser", 10);
await prisma.user.create({
data: {
email,
password: {
create: {
hash: hashedPassword
}
}
}
});
const source = {
name: "Take Home Challenge",
connectionUrl: "https://s3-us-west-1.amazonaws.com/cdn-web.tunein.com/stations.json",
type: "json"
};
await prisma.contentSource
.delete({
where: { connectionUrl: source.connectionUrl }
})
.catch(() => {
// no worries if it doesn't exist yet
});
const s = await saveSource(source);
await importSource(s);
console.log(`Database has been seeded. 🌱`);
}
seed()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});