add docker and prisma

This commit is contained in:
Cesar
2026-05-22 15:27:58 -06:00
parent 0ea46e1f76
commit 397c2ef3df
10 changed files with 1467 additions and 7 deletions

0
backend/.env.template Normal file
View File

2
backend/.gitignore vendored
View File

@@ -2,6 +2,6 @@ node_modules/
key/
.env
dist/
/postgres
/src/generated/prisma

View File

@@ -0,0 +1,16 @@
version: '3.8'
services:
postgres-db:
image: postgres:15.3
restart: always
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
volumes:
- ./postgres:/var/lib/postgresql/data
ports:
- 5433:5432

1332
backend/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,13 +15,18 @@
"devDependencies": {
"@types/express": "^5.0.6",
"@types/node": "^25.9.1",
"@types/pg": "^8.20.0",
"prisma": "^7.8.0",
"rimraf": "^6.1.3",
"tsx": "^4.22.3",
"typescript": "^5.9.3"
},
"dependencies": {
"@prisma/adapter-pg": "^7.8.0",
"@prisma/client": "^7.8.0",
"dotenv": "^17.4.2",
"env-var": "^7.5.0",
"express": "^5.2.1"
"express": "^5.2.1",
"pg": "^8.21.0"
}
}

15
backend/prisma.config.ts Normal file
View File

@@ -0,0 +1,15 @@
// This file was generated by Prisma, and assumes you have installed the following:
// npm install --save-dev prisma dotenv
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
},
datasource: {
url: env("POSTGRES_URL"),
},
});

View File

@@ -0,0 +1,43 @@
-- CreateEnum
CREATE TYPE "UserRole" AS ENUM ('USER', 'ADMIN');
-- CreateTable
CREATE TABLE "users" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"email" TEXT NOT NULL,
"password" TEXT NOT NULL,
"phone" TEXT,
"role" "UserRole" NOT NULL DEFAULT 'USER',
"isActive" BOOLEAN NOT NULL DEFAULT true,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
);
-- CreateTable
CREATE TABLE "addresses" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"label" TEXT NOT NULL,
"street" TEXT NOT NULL,
"neighborhood" TEXT,
"postalCode" TEXT,
"latitude" DOUBLE PRECISION,
"longitude" DOUBLE PRECISION,
"isDefault" BOOLEAN NOT NULL DEFAULT false,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,
CONSTRAINT "addresses_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
-- CreateIndex
CREATE UNIQUE INDEX "users_phone_key" ON "users"("phone");
-- AddForeignKey
ALTER TABLE "addresses" ADD CONSTRAINT "addresses_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

View File

@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (e.g., Git)
provider = "postgresql"

View File

@@ -0,0 +1,54 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
// Get a free hosted Postgres database in seconds: `npx create-db`
generator client {
provider = "prisma-client"
output = "../src/generated/prisma"
}
datasource db {
provider = "postgresql"
}
enum UserRole {
USER
ADMIN
}
model User {
id Int @id @default(autoincrement())
name String
email String @unique
password String
phone String? @unique
role UserRole @default(USER)
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
addresses Address[]
@@map("users")
}
model Address {
id Int @id @default(autoincrement())
userId Int
label String
street String
neighborhood String?
postalCode String?
latitude Float?
longitude Float?
isDefault Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@map("addresses")
}

View File