Skip to content

Commit af7ec67

Browse files
authored
feat(): update for prisma 7 (#232)
1 parent 3676bb0 commit af7ec67

File tree

8 files changed

+105
-56
lines changed

8 files changed

+105
-56
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig, env } from 'prisma/config'
2+
3+
export default defineConfig({
4+
schema: './prisma/schema.prisma',
5+
migrations: {
6+
path: './prisma/migrations',
7+
seed: 'tsx prisma/seed.ts',
8+
},
9+
datasource: {
10+
url: env('DATABASE_URL'),
11+
},
12+
});
13+

frameworks/react-cra/add-ons/prisma/assets/schema.prisma.ejs renamed to frameworks/react-cra/add-ons/prisma/assets/prisma/schema.prisma.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
generator client {
2-
provider = "prisma-client-js"
2+
provider = "prisma-client"
3+
output = "../src/generated/prisma"
34
}
45

56
datasource db {
67
provider = "<%= addOnOption.prisma.database === "postgres" ? "postgresql" : addOnOption.prisma.database %>"
7-
url = env("DATABASE_URL")
88
}
99

1010
model Todo {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { PrismaClient } from "../src/generated/prisma/client.js";
2+
3+
<% if (addOnOption.prisma.database === 'postgres') { %>
4+
import { PrismaPg } from '@prisma/adapter-pg';
5+
6+
const adapter = new PrismaPg({
7+
connectionString: process.env.DATABASE_URL!,
8+
});<% } %>
9+
10+
<% if (addOnOption.prisma.database === 'mysql') { %>
11+
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
12+
const adapter = new PrismaMariaDb({
13+
host: "localhost",
14+
port: 3306,
15+
connectionLimit: 5
16+
});<% } %>
17+
18+
<% if (addOnOption.prisma.database === 'sqlite') { %>
19+
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
20+
const adapter = new PrismaBetterSQLite3({
21+
url: process.env.DATABASE_URL || 'file:./dev.db'
22+
});<% } %>
23+
24+
const prisma = new PrismaClient({adapter})
25+
26+
async function main() {
27+
console.log('🌱 Seeding database...')
28+
29+
// Clear existing todos
30+
await prisma.todo.deleteMany()
31+
32+
// Create example todos
33+
const todos = await prisma.todo.createMany({
34+
data: [
35+
{ title: 'Buy groceries' },
36+
{ title: 'Read a book' },
37+
{ title: 'Workout' },
38+
],
39+
})
40+
41+
console.log(`✅ Created ${todos.count} todos`)
42+
}
43+
44+
main()
45+
.catch((e) => {
46+
console.error('❌ Error seeding database:', e)
47+
process.exit(1)
48+
})
49+
.finally(async () => {
50+
await prisma.$disconnect()
51+
})

frameworks/react-cra/add-ons/prisma/assets/seed.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

frameworks/react-cra/add-ons/prisma/assets/src/db.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { PrismaClient } from './generated/prisma/client.js'
2+
3+
<% if (addOnOption.prisma.database === 'postgres') { %>
4+
import { PrismaPg } from '@prisma/adapter-pg';
5+
6+
const adapter = new PrismaPg({
7+
connectionString: process.env.DATABASE_URL!,
8+
});<% } %>
9+
10+
<% if (addOnOption.prisma.database === 'mysql') { %>
11+
import { PrismaMariaDb } from '@prisma/adapter-mariadb';
12+
const adapter = new PrismaMariaDb({
13+
host: "localhost",
14+
port: 3306,
15+
connectionLimit: 5
16+
});<% } %>
17+
18+
<% if (addOnOption.prisma.database === 'sqlite') { %>
19+
import { PrismaBetterSQLite3 } from '@prisma/adapter-better-sqlite3';
20+
const adapter = new PrismaBetterSQLite3({
21+
url: process.env.DATABASE_URL || 'file:./dev.db'
22+
});<% } %>
23+
24+
declare global {
25+
var __prisma: PrismaClient | undefined
26+
}
27+
28+
export const prisma = globalThis.__prisma || new PrismaClient({ adapter })
29+
30+
if (process.env.NODE_ENV !== 'production') {
31+
globalThis.__prisma = prisma
32+
}
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
{
22
"dependencies": {
33
"prisma": "^6.16.3",
4-
"@prisma/client": "^6.16.3"<% if (addOnOption.prisma.database === 'postgres') { %>,
5-
"pg": "^8.11.0"<% } %><% if (addOnOption.prisma.database === 'mysql') { %>,
6-
"mysql2": "^3.6.0"<% } %>
4+
"@prisma/client": "^7.0.0"<% if (addOnOption.prisma.database === 'postgres') { %>,
5+
"@prisma/adapter-pg": "^7.0.0"<% } %><% if (addOnOption.prisma.database === 'mysql') { %>,
6+
"@prisma/adapter-mariadb": "^7.0.0"<% } %><% if (addOnOption.prisma.database === 'sqlite') { %>,
7+
"@prisma/adapter-better-sqlite3": "^7.0.0"<% } %>
78
},
89
"devDependencies": {
910
"dotenv-cli": "^10.0.0",
10-
"ts-node": "^10.9.2",
11-
<% if (addOnOption.prisma.database === 'postgres') { %>
12-
"@types/pg": "^8.10.0"<% } %><% if (addOnOption.prisma.database === 'mysql') { %>
13-
"@types/mysql2": "^3.6.0"<% } %><% if (addOnOption.prisma.database === 'sqlite') { %>
14-
"@types/better-sqlite3": "^7.6.0"<% } %>
11+
"tsx": "^4.20.6"
1512
},
1613
"scripts": {<% if (addOnOption.prisma.database === 'postgres') { %>
1714
"post-cta-init": "npx create-db@latest",<% } %>
@@ -20,8 +17,5 @@
2017
"db:migrate": "dotenv -e .env.local -- prisma migrate dev",
2118
"db:studio": "dotenv -e .env.local -- prisma studio",
2219
"db:seed": "dotenv -e .env.local -- prisma db seed"
23-
},
24-
"prisma": {
25-
"seed": "ts-node seed.ts"
2620
}
27-
}
21+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is auto-generated. Do not edit manually.
22
// Generated from add-ons, examples, hosts, project, and toolchains directories
3-
export const contentChecksum = '22415a1abc64758541fdba06e79f1b24860e8100379e3a08c2cd0084f5ec26f9'
3+
export const contentChecksum = '2124eaa547a2067f472354b25eb9ad5472526504fb8a80226ee6996a412e2b49'

0 commit comments

Comments
 (0)