Skip to content

Commit

Permalink
Merge pull request #9 from codingwithmanny/feat/drizzle-update-postgr…
Browse files Browse the repository at this point in the history
…es-docker

feat: 🎸 Updated drizzle, fixed studio, added docker
  • Loading branch information
noxify authored Sep 6, 2024
2 parents 568a2ce + 96550c3 commit e097b69
Show file tree
Hide file tree
Showing 5 changed files with 3,643 additions and 4,693 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The database URL is used to connect to your database.
DB_HOST='localhost'
DB_PORT=5432
DB_NAME='turbo_stack'
DB_NAME='turbo_stack_db'
DB_USERNAME='turbo_stack'
DB_PASSWORD='turbo_stack'

Expand Down
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: turbo_stack_db
POSTGRES_USER: turbo_stack
POSTGRES_PASSWORD: turbo_stack
ports:
- "5432:5432"
expose:
- "5432"
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"dev:next": "turbo watch dev -F @acme/nextjs...",
"clean": "git clean -xdf node_modules",
"clean:workspaces": "turbo run clean",
"db:up": "docker compose -p turbo up -d ",
"db:down": "docker compose -p turbo down --remove-orphans -v",
"db:generate": "pnpm -F db generate",
"db:migrate": "pnpm -F db migrate",
"db:push": "turbo -F @acme/db push",
Expand Down
44 changes: 15 additions & 29 deletions packages/db/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { relations, sql } from "drizzle-orm"
import {
index,
pgTable,
primaryKey,
text,
timestamp,
uuid,
varchar,
} from "drizzle-orm/pg-core"
import { pgTable, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core"
import { createInsertSchema } from "drizzle-zod"
import { z } from "zod"

Expand Down Expand Up @@ -60,24 +52,15 @@ export const Session = pgTable("session", {
userAgent: text("user_agent"),
})

export const Account = pgTable(
"account",
{
providerId: varchar("provider_id", { length: 255 }).notNull(),
providerUserId: varchar("provider_user_id", { length: 255 }).notNull(),
userId: varchar("user_id", {
length: 255,
})
.notNull()
.references(() => User.id),
},
(account) => ({
compoundKey: primaryKey({
columns: [account.providerId, account.providerUserId],
}),
userIdIdx: index("userId_idx").on(account.userId),
}),
)
export const Account = pgTable("account", {
providerId: varchar("provider_id", { length: 255 }).notNull(),
providerUserId: varchar("provider_user_id", { length: 255 }).notNull(),
userId: varchar("user_id", {
length: 255,
})
.notNull()
.references(() => User.id),
})

export const SessionRelations = relations(Session, ({ one }) => ({
user: one(User, {
Expand All @@ -86,6 +69,9 @@ export const SessionRelations = relations(Session, ({ one }) => ({
}),
}))

export const UserRelations = relations(User, ({ many }) => ({
accounts: many(Account),
export const AccountRelations = relations(Account, ({ one }) => ({
user: one(User, {
fields: [Account.userId],
references: [User.id],
}),
}))
Loading

0 comments on commit e097b69

Please sign in to comment.