Skip to content

Commit

Permalink
feat: add drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
risv1 committed Apr 22, 2024
1 parent 35c3d90 commit e029893
Show file tree
Hide file tree
Showing 10 changed files with 4,684 additions and 4,353 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DB_URL="YOUR_DB_URL"
8 changes: 8 additions & 0 deletions database/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { drizzle } from "drizzle-orm/postgres-js"
import postgres from "postgres"
import { config } from "dotenv"

config()

const client = postgres(process.env.DB_URL!)
export const db = drizzle(client)
11 changes: 11 additions & 0 deletions database/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { pgTable, text } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
id: text("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull(),
password: text("password").notNull(),
role: text("role").notNull(),
created_at: text("created_at").notNull(),
updated_at: text("updated_at").notNull(),
})
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3.5'

services:

postgres:
container_name: postgres_nuxt
image: postgres
environment:
POSTGRES_DB: "postgres"
POSTGRES_USER: "root"
POSTGRES_PASSWORD: "password"
PGDATA: /data/postgres
ports:
- "5432:5432"
restart: unless-stopped
13 changes: 13 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from "drizzle-kit";
import { config } from "dotenv";

config();

export default {
schema: "./database/schema.ts",
out: "./drizzle",
driver: "pg",
dbCredentials: {
connectionString: process.env.DB_URL!,
},
} satisfies Config;
9 changes: 9 additions & 0 deletions drizzle/0000_spotty_wind_dancer.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS "users" (
"id" text PRIMARY KEY NOT NULL,
"name" text NOT NULL,
"email" text NOT NULL,
"password" text NOT NULL,
"role" text NOT NULL,
"created_at" text NOT NULL,
"updated_at" text NOT NULL
);
67 changes: 67 additions & 0 deletions drizzle/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"id": "b3239a7b-ea95-4710-8b88-c3e4dd579310",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"tables": {
"users": {
"name": "users",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true
},
"password": {
"name": "password",
"type": "text",
"primaryKey": false,
"notNull": true
},
"role": {
"name": "role",
"type": "text",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}
13 changes: 13 additions & 0 deletions drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "pg",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1713807382697,
"tag": "0000_spotty_wind_dancer",
"breakpoints": true
}
]
}
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@
"dev": "nuxt dev",
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare"
"postinstall": "nuxt prepare",
"db:generate": "drizzle-kit generate:pg",
"db:push": "drizzle-kit push:pg"
},
"dependencies": {
"@types/bcrypt": "^5.0.2",
"@types/jsonwebtoken": "^9.0.6",
"bcrypt": "^5.1.1",
"drizzle-kit": "^0.20.17",
"drizzle-orm": "^0.30.9",
"jsonwebtoken": "^9.0.2",
"nuxt": "^3.11.2",
"postgres": "^3.4.4",
"vue": "^3.4.21",
"vue-router": "^4.3.0"
"vue-router": "^4.3.0",
"zod": "^3.23.0"
}
}
Loading

0 comments on commit e029893

Please sign in to comment.