Skip to content

Commit 6750964

Browse files
authored
chore: implements dev database and updates prisma config (#786)
Signed-off-by: Anthony D. Mays <anthony@morganlatimer.com>
1 parent 546b685 commit 6750964

File tree

10 files changed

+57
-12
lines changed

10 files changed

+57
-12
lines changed

lib/javascript/fullstack_demo/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ db.json
4949
# Cypress
5050
/cypress/snapshots/actual
5151
/cypress/snapshots/diff
52-
cypress.env.json
52+
cypress.env.json
53+
54+
# Prisma
55+
/src/generated
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
FROM postgres:16-alpine
3+
4+
# Create a directory for initialization scripts
5+
RUN mkdir -p /docker-entrypoint-initdb.d
6+
7+
# Add any initialization scripts if needed
8+
# COPY ./init-scripts/ /docker-entrypoint-initdb.d/
9+
10+
# Set environment defaults (these can be overridden in docker-compose.yml)
11+
ENV POSTGRES_USER=postgres
12+
ENV POSTGRES_PASSWORD=password
13+
ENV POSTGRES_DB=fullstack_db
14+
15+
# Expose the PostgreSQL port
16+
EXPOSE 5432
17+
18+
# Set the data directory
19+
VOLUME ["/var/lib/postgresql/data"]
20+
21+
# Set health check command
22+
HEALTHCHECK --interval=5s --timeout=5s --retries=5 \
23+
CMD pg_isready -U postgres || exit 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '3.8'
2+
3+
name: fullstack-app
4+
services:
5+
database:
6+
container_name: fullstack-db
7+
build:
8+
context: .
9+
dockerfile: Dockerfile
10+
ports:
11+
- '5432:5432'
12+
environment:
13+
- POSTGRES_DB=fullstack_db
14+
- POSTGRES_USER=postgres
15+
- POSTGRES_PASSWORD=password
16+
volumes:
17+
- fullstack_postgres_data:/var/lib/postgresql/data
18+
restart: unless-stopped
19+
20+
volumes:
21+
fullstack_postgres_data:

lib/javascript/fullstack_demo/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"cy:open": "cypress open",
1616
"cy:open:e2e": "cypress open --e2e",
1717
"cy:run:e2e": "cypress run --e2e",
18+
"db:start": "docker-compose -f ./db/docker-compose.yml up -d",
19+
"db:stop": "docker-compose -f ./db/docker-compose.yml down",
1820
"db:seed": "tsx prisma/seed.ts"
1921
},
2022
"dependencies": {

lib/javascript/fullstack_demo/prisma/schema.prisma

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
generator client {
22
provider = "prisma-client-js"
3-
}
4-
5-
// Define seed script
6-
generator seeder {
7-
provider = "ts-node"
8-
output = "../prisma/seed.ts"
3+
binaryTargets = ["native", "linux-musl", "rhel-openssl-3.0.x"]
4+
output = "../src/generated/client"
95
}
106

117
datasource db {

lib/javascript/fullstack_demo/prisma/seed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient } from '@prisma/client';
1+
import { PrismaClient } from '../src/generated/client';
22

33
const prisma = new PrismaClient();
44

lib/javascript/fullstack_demo/src/repositories/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export type { TodoRepository } from './todo-repository';
22

3-
import { PrismaClient } from '@prisma/client';
3+
import { PrismaClient } from '@/generated/client';
44
import { Redis } from '@upstash/redis';
55
import { JSONFilePreset } from 'lowdb/node';
66
import { dirname } from 'path';

lib/javascript/fullstack_demo/src/repositories/postgres-todo-repository.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient } from '@prisma/client';
1+
import { PrismaClient } from '@/generated/client';
22
import { beforeEach, describe, expect, it } from 'vitest';
33
import { DbTodo, FakePrismaClient } from './fakes/fake-prima-client';
44
import { PostgresTodoRepository } from './postgres-todo-repository';

lib/javascript/fullstack_demo/src/repositories/postgres-todo-repository.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { PrismaClient } from '@/generated/client';
12
import { Todo } from '@/models';
2-
import { PrismaClient } from '@prisma/client';
33
import { TodoRepository } from './todo-repository';
44

55
export class PostgresTodoRepository implements TodoRepository {

lib/javascript/fullstack_demo/src/util/prisma-transport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient } from '@prisma/client';
1+
import { PrismaClient } from '@/generated/client';
22
import Transport from 'winston-transport';
33

44
export class PrismaTransport extends Transport {

0 commit comments

Comments
 (0)