Skip to content

Commit

Permalink
feat: add prisma.
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyyuan committed Apr 14, 2023
1 parent eafc3bf commit 193cb5b
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DATABASE_URL="postgresql://admin:eipsfun@localhost:5335/eipsfun?schema=public"
PORT=3100
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
$ yarn install
```

## Start services

```
cd service && docker-compose up -d
```

## Running the app

```bash
Expand Down
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build",
"prebuild": "rimraf dist",
"build": "npm run generate && nest build",
"generate": "prisma generate",
"migrate:dev": "prisma migrate dev",
"migrate:prod": "prisma migrate deploy",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start:dev": "nest start --watch",
Expand All @@ -23,6 +27,7 @@
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"@prisma/client": "4.12.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
},
Expand All @@ -41,14 +46,14 @@
"eslint-plugin-prettier": "^4.0.0",
"jest": "29.5.0",
"prettier": "^2.3.2",
"prisma": "^4.12.0",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "29.0.5",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.2.0",
"typescript": "^4.7.4",
"prisma": "^4.12.0"
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
Expand Down
58 changes: 58 additions & 0 deletions prisma/migrations/20230414061305_init/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
-- CreateEnum
CREATE TYPE "EIPType" AS ENUM ('Standards Track', 'Meta', 'Informational');

-- CreateEnum
CREATE TYPE "EIPCategory" AS ENUM ('Core', 'Networking', 'Interface', 'ERC');

-- CreateEnum
CREATE TYPE "EIPStatus" AS ENUM ('Idea', 'Draft', 'Review', 'Last Call', 'Final', 'Stagnant', 'Withdrawn', 'Living');

-- CreateTable
CREATE TABLE "EmailSubscribe" (
"id" SERIAL NOT NULL,
"address" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "EmailSubscribe_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "EIPs" (
"id" SERIAL NOT NULL,
"eip" INTEGER NOT NULL,
"title" TEXT NOT NULL,
"description" TEXT NOT NULL,
"author" TEXT NOT NULL,
"discussions_to" TEXT NOT NULL,
"status" "EIPStatus" NOT NULL,
"type" "EIPType" NOT NULL,
"category" "EIPCategory",
"created" TIMESTAMP(3) NOT NULL,
"requires" INTEGER[],
"last_call_deadline" TIMESTAMP(3),
"withdrawal_reason" TEXT,
"content" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "EIPs_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "EIPsSearch" (
"id" SERIAL NOT NULL,
"eip" INTEGER NOT NULL,
"subTitle" TEXT NOT NULL,
"shortRead" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "EIPsSearch_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "EmailSubscribe_address_key" ON "EmailSubscribe"("address");

-- CreateIndex
CREATE UNIQUE INDEX "EIPs_eip_key" ON "EIPs"("eip");

-- CreateIndex
CREATE UNIQUE INDEX "EIPsSearch_eip_key" ON "EIPsSearch"("eip");
3 changes: 3 additions & 0 deletions prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
67 changes: 67 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

enum EIPType {
Standards_Track @map("Standards Track")
Meta
Informational
}

enum EIPCategory {
Core
Networking
Interface
ERC
}

enum EIPStatus {
Idea
Draft
Review
Last_Call @map("Last Call")
Final
Stagnant
Withdrawn
Living
}

model EmailSubscribe {
id Int @id @default(autoincrement())
address String @unique
createdAt DateTime @default(now())
}

model EIPs {
id Int @id @default(autoincrement())
eip Int @unique
title String
description String
author String
discussions_to String
status EIPStatus
type EIPType
category EIPCategory?
created DateTime
requires Int[]
last_call_deadline DateTime?
withdrawal_reason String?
content String
createdAt DateTime @default(now())
}

model EIPsSearch {
id Int @id @default(autoincrement())
eip Int @unique
subTitle String
shortRead String
createdAt DateTime @default(now())
}
17 changes: 17 additions & 0 deletions service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.1'

services:
postgres-eipsfun:
image: postgres:15
restart: always
environment:
- POSTGRES_USER=admin
- POSTGRES_PASSWORD=eipsfun
- POSTGRES_DB=eipsfun
ports:
- 5335:5432
volumes:
- eipsfun-postgresql:/var/lib/postgresql/data

volumes:
eipsfun-postgresql:
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,18 @@
consola "^2.15.0"
node-fetch "^2.6.1"

"@prisma/[email protected]":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@prisma/client/-/client-4.12.0.tgz#119b692888b1fe0fd3305c7d0e0ac48520aa6839"
integrity sha512-j9/ighfWwux97J2dS15nqhl60tYoH8V0IuSsgZDb6bCFcQD3fXbXmxjYC8GHhIgOk3lB7Pq+8CwElz2MiDpsSg==
dependencies:
"@prisma/engines-version" "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7"

"@prisma/engines-version@4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7":
version "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7"
resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7.tgz#51a1cc5c886564b542acde64a873645d0dee2566"
integrity sha512-JIHNj5jlXb9mcaJwakM0vpgRYJIAurxTUqM0iX0tfEQA5XLZ9ONkIckkhuAKdAzocZ+80GYg7QSsfpjg7OxbOA==

"@prisma/[email protected]":
version "4.12.0"
resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-4.12.0.tgz#68d99078b70b2d9c339d0e8cbf2e99f00b72aa8c"
Expand Down

0 comments on commit 193cb5b

Please sign in to comment.