Skip to content

Commit

Permalink
feat: migrate from prisma to drizzle ORM (#180)
Browse files Browse the repository at this point in the history
* build(deps): add Drizzle ORM and planetscale connector

* build(deps): remove prisma as dependencies

* feat(drizzle): add drizzle based schemas and middleware

* build(deps-dev): add lodash-es and mysql2 and update nuxt

* fix(schema): fix schema and relationships

* feat(server): add db migrate, seed and crud ops

* style(schema): apply biomejs

* feat(crud): add crud operations

It is complex, however drizzle gives us no other choice

* fix(middleware): use nuxt runtime config for setting database URL

* feat(prisma): remove unrequired files

* style(db): apply biomejs

* refactor(seed): apply biomejs and simplify code

* feat(api/sections): change caching params and use crud ops

* feat(api/question): validate router params and use crud ops

* style(pages): add a space

* refactor(components): use updated types for Answer

* refactor(composables): do not use proxy url

* feat(useSectionNav): remove not `undefined` assert

* build(deps-dev): update deps and add type helper package

* build(nuxt): do not generate shim

* refactor: update type import path

* fix(crud/question): fetch the correct related data

* refactor(crud/answer): remove unused code
  • Loading branch information
arunanshub authored Feb 9, 2024
1 parent 4951929 commit 6f3e5ad
Show file tree
Hide file tree
Showing 35 changed files with 2,143 additions and 420 deletions.
12 changes: 12 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'dotenv/config'
import { type Config } from 'drizzle-kit'

export default {
out: 'src/server/database/migrations',
schema: 'src/server/database/schema/*',
driver: 'mysql2',
dbCredentials: {
uri: process.env.DATABASE_URL!,
database: process.env.DATABASE_NAME!,
},
} satisfies Config
8 changes: 8 additions & 0 deletions migrate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'dotenv/config'
import { migrate } from 'drizzle-orm/planetscale-serverless/migrator'
import { getDb } from '~/server/database/db'

// This will run migrations on the database, skipping the ones already applied
await migrate(getDb(process.env.DATABASE_URL!), {
migrationsFolder: './src/server/database/migrations',
})
2 changes: 1 addition & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default defineNuxtConfig({
databaseUrl: process.env.DATABASE_URL,
},

// Development
// Development
devtools: { enabled: true },
typescript: {
strict: true,
Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "prisma generate --no-engine && nuxt prepare"
},
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\",\"verbatimModuleSyntax\":false} ./prisma/seed.ts"
"postinstall": "nuxt prepare"
},
"browserslist": [
"last 4 versions, >0.2%, not dead"
],
"devDependencies": {
"@biomejs/biome": "1.5.3",
"@nuxt/devtools": "latest",
"@tailwindcss/typography": "^0.5.10",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.8",
"nuxt": "^3.9.3",
"drizzle-kit": "^0.20.13",
"lodash-es": "^4.17.21",
"mysql2": "^3.9.1",
"nuxt": "^3.10.0",
"prettier": "^3.2.4",
"prettier-plugin-tailwindcss": "^0.5.11",
"ts-node": "^10.9.2",
"type-fest": "^4.10.2",
"vue": "^3.4.15",
"vue-router": "^4.2.5"
"vue-router": "^4.2.5",
"vue-tsc": "^1.8.27"
},
"dependencies": {
"@nuxt/content": "2.12.0",
Expand All @@ -33,15 +37,14 @@
"@nuxtjs/google-fonts": "^3.1.3",
"@nuxtjs/robots": "^3.0.0",
"@nuxtjs/tailwindcss": "^6.11.1",
"@prisma/client": "^5.8.1",
"@prisma/extension-accelerate": "^0.6.2",
"@planetscale/database": "^1.14.0",
"@vueuse/core": "^10.7.2",
"@vueuse/nuxt": "^10.7.2",
"browserslist-to-esbuild": "^2.1.1",
"drizzle-orm": "^0.29.3",
"nuxt-delay-hydration": "^1.3.3",
"nuxt-icon": "^0.6.8",
"postcss-preset-env": "^9.3.0",
"prisma": "^5.8.1",
"valibot": "^0.28.0"
}
}
Loading

0 comments on commit 6f3e5ad

Please sign in to comment.