Skip to content

Commit

Permalink
feat: define db schema (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
renansilva15 committed Oct 24, 2023
1 parent 7d0790d commit 99c0a04
Show file tree
Hide file tree
Showing 8 changed files with 1,059 additions and 8 deletions.
1 change: 1 addition & 0 deletions ERD.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
933 changes: 933 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"react-dom": "^18"
},
"devDependencies": {
"@mermaid-js/mermaid-cli": "^10.5.1",
"@rocketseat/eslint-config": "^1.2.0",
"@types/node": "^20",
"@types/react": "^18",
Expand All @@ -26,6 +27,8 @@
"eslint-config-next": "13.5.4",
"postcss": "^8",
"prisma": "^5.4.1",
"prisma-erd-generator": "^1.11.1",
"prisma-markdown": "^1.0.3",
"tailwindcss": "^3",
"typescript": "5.2"
}
Expand Down
57 changes: 57 additions & 0 deletions prisma/ERD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Doe Aqui
> Generated by [`prisma-markdown`](https://github.com/samchon/prisma-markdown)
- [default](#default)

## default
```mermaid
erDiagram
"User" {
String id PK
String name
String email UK
String password
}
"Image" {
String id PK
String campaign_id FK
String url
}
"Campaign" {
String id PK
String user_id FK
String title
String description
Decimal goal
Decimal total_raised
String pix_key
}
"Image" }|--|| "Campaign" : campaign
"Campaign" }|--|| "User" : user
```

### `User`

**Properties**
- `id`:
- `name`:
- `email`:
- `password`:

### `Image`

**Properties**
- `id`:
- `campaign_id`:
- `url`:

### `Campaign`

**Properties**
- `id`:
- `user_id`:
- `title`:
- `description`:
- `goal`:
- `total_raised`:
- `pix_key`:
Binary file modified prisma/dev.db
Binary file not shown.
Binary file added prisma/dev.db-journal
Binary file not shown.
30 changes: 30 additions & 0 deletions prisma/migrations/20231024214006_schema_defined/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Warnings:
- You are about to drop the `Campaigns` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropTable
PRAGMA foreign_keys=off;
DROP TABLE "Campaigns";
PRAGMA foreign_keys=on;

-- CreateTable
CREATE TABLE "Image" (
"id" TEXT NOT NULL PRIMARY KEY,
"campaign_id" TEXT NOT NULL,
"url" TEXT NOT NULL,
CONSTRAINT "Image_campaign_id_fkey" FOREIGN KEY ("campaign_id") REFERENCES "Campaign" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);

-- CreateTable
CREATE TABLE "Campaign" (
"id" TEXT NOT NULL PRIMARY KEY,
"user_id" TEXT NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"goal" DECIMAL NOT NULL DEFAULT 0,
"total_raised" DECIMAL NOT NULL DEFAULT 0,
"pix_key" TEXT NOT NULL,
CONSTRAINT "Campaign_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
);
43 changes: 35 additions & 8 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ generator client {
provider = "prisma-client-js"
}

// generator erd {
// provider = "prisma-erd-generator"
// theme = "dark"
// output = "../ERD.svg"
// }

generator markdown {
provider = "prisma-markdown"
output = "./ERD.md"
title = "Doe Aqui"
}

datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
Expand All @@ -13,18 +25,33 @@ datasource db {
model User {
id String @id @default(uuid())
name String
email String @unique
password String
Campaigns Campaigns[]
name String
email String @unique
password String
campaigns Campaign[]
}

model Campaigns {
model Image {
id String @id @default(uuid())
campaignId String @map("campaign_id")
url String
campaign Campaign @relation(fields: [campaignId], references: [id])
}

model Campaign {
id String @id @default(uuid())
userId String
userId String @map("user_id")
name String
title String
description String
goal Decimal @default(0)
totalRaised Decimal @default(0) @map("total_raised")
pixKey String @map("pix_key")
user User @relation(fields: [userId], references: [id])
user User @relation(fields: [userId], references: [id])
images Image[]
}

0 comments on commit 99c0a04

Please sign in to comment.