diff --git a/README.md b/README.md index 655d523..e944430 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,14 @@ npx create-next-app nextjs-typescript-starter --example "https://github.com/verc ## Getting Started -First, run the development server: +Copy .env.example to .env and add your postgresql settings, along with a randomly created AUTH_SECRET value. +Then, apply the drizzle schema to your database: + +``` +drizzle-kit push +``` + +Finally, run the development server: ```bash pnpm dev diff --git a/app/db.ts b/app/db.ts index 1c94cb6..f425bd8 100644 --- a/app/db.ts +++ b/app/db.ts @@ -1,20 +1,15 @@ import { drizzle } from 'drizzle-orm/postgres-js'; -import { pgTable, serial, varchar } from 'drizzle-orm/pg-core'; import { eq } from 'drizzle-orm'; import postgres from 'postgres'; import { genSaltSync, hashSync } from 'bcrypt-ts'; +import { users } from './schema'; // Optionally, if not using email/pass login, you can // use the Drizzle adapter for Auth.js / NextAuth // https://authjs.dev/reference/adapter/drizzle -let client = postgres(`${process.env.POSTGRES_URL!}?sslmode=require`); +let client = postgres(`${process.env.POSTGRES_URL!}`); let db = drizzle(client); -let users = pgTable('User', { - id: serial('id').primaryKey(), - email: varchar('email', { length: 64 }), - password: varchar('password', { length: 64 }), -}); export async function getUser(email: string) { return await db.select().from(users).where(eq(users.email, email)); diff --git a/app/schema.ts b/app/schema.ts new file mode 100644 index 0000000..2fffe84 --- /dev/null +++ b/app/schema.ts @@ -0,0 +1,7 @@ +import { pgTable, serial, varchar } from 'drizzle-orm/pg-core'; + +export const users = pgTable('User', { + id: serial('id').primaryKey(), + email: varchar('email', { length: 64 }), + password: varchar('password', { length: 64 }), +}); diff --git a/drizzle.config.ts b/drizzle.config.ts new file mode 100644 index 0000000..907abb8 --- /dev/null +++ b/drizzle.config.ts @@ -0,0 +1,10 @@ +import { defineConfig } from 'drizzle-kit'; + +export default defineConfig({ + schema: './app/schema.ts', + out: './drizzle', + dialect: 'postgresql', + dbCredentials: { + url: process.env.POSTGRES_URL! + } + }); \ No newline at end of file diff --git a/package.json b/package.json index eb7351c..ceb5c95 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "scripts": { "dev": "next dev --turbo", "build": "next build", + "generate": "drizzle-kit generate:pg --out drizzle --schema app/db/schema.ts", "start": "next start", "lint": "next lint" }, @@ -21,6 +22,7 @@ }, "devDependencies": { "autoprefixer": "^10.4.16", + "drizzle-kit": "^0.21.4", "eslint": "8.56.0", "eslint-config-next": "^14.0.4", "postcss": "^8.4.32", diff --git a/tsconfig.json b/tsconfig.json index b2ac004..3116350 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,5 @@ { "compilerOptions": { - "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true,