Skip to content

Commit

Permalink
Update prisma init
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaUrsa committed Nov 4, 2023
1 parent c04a242 commit 0d37188
Show file tree
Hide file tree
Showing 14 changed files with 4,875 additions and 1,028 deletions.
1 change: 0 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ steps:
- apk update
- apk upgrade
- apk add --no-cache git
- docker compose -f docker-compose.host.yml --project-name tripbot up tripbot_database -d --force-recreate --build
- docker compose -f docker-compose.host.yml --project-name tripbot up tripbot_prisma -d --force-recreate --build
# - tail -f /dev/null
environment:
Expand Down
12 changes: 11 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ If you wanted to do this in telegram, you would figure out how to take input val

## Database Development ##

TripBot's database runs on Postgres, which is a relational database.

You make changes to the schema.prisma, and then run the ```npm run prisma:migrate``` to create the migration file

When this file is pushed to production, the database will be updated automatically.

One of the goals is to convert the knex queries in tripbot into Prisma Client queries.

### Postgres ###
```npm run postgres```
We use postgres for our database.
Expand All @@ -140,14 +148,16 @@ By itself, it does nothing, you need another utility, like Prisma, to interact w
Prisma runs the necessary setup to fill in the database tables and columns.
You just need to run this container once and you can forget about it.
Previously we used Knex so you'll still see some knex code, but we're moving away from that.
There is a webserver (prisma studio)that starts as part of this container.
There is a webserver (prisma studio) that starts as part of this container.
You can access it via http://localhost:5555
If you're worried about this, exit the prisma container after it finishes running.
It only needs to run once to setup the DB.

### PG Admin ###
```npm run pgadmin```
This is a webserver that allows you to view the database.
It's not necessary, but it's nice to have.
You can access it via http://localhost:80 (maybe idk)

### API ###
```npm run api```
Expand Down
36 changes: 15 additions & 21 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,44 @@ services:

tripbot_database:
<<: *common-keys-apps
build:
context: ./
dockerfile: ./src/docker/Dockerfile.postgres
# image: docker.io/bitnami/postgresql:15.4.0
image: postgres:15.4
container_name: tripbot_database
# Uncomment this if you want the DB to persist between rebuilds
# volumes:
# - ${DOCKERDIR}/appdata/database/data:/var/lib/postgresql/data
# ports:
# - 5432:5432
networks:
- tripbot_database-net
environment:
POSTGRES_USER: tripsit
POSTGRES_DB: tripsit
POSTGRES_PASSWORD: ${POSTGRESS_ROOT}
# POSTGRES_HOST_AUTH_METHOD: trust
<<: *default-tz-puid-pgid
POSTGRESQL_DATABASE: tripsit
POSTGRESQL_PASSWORD: ${POSTGRESQL_PASSWORD}
labels:
- com.centurylinklabs.watchtower.enable=false
- traefik.docker.network=tripbot_database-net
- traefik.enable=false

tripbot_prisma:
# <<: *common-keys-apps
<<: *common-keys-apps
build:
# context: https://github.com/tripsit/tripbot.git#main
context: ./
dockerfile: ./src/docker/Dockerfile.prisma
target: development
container_name: tripbot_prisma
working_dir: /usr/src/app
depends_on:
- tripbot_database
networks:
- tripbot_database-net
- tripbot_prisma-net
volumes:
- ./src/prisma/:/usr/src/app/src/prisma/
- ./src/knex/:/usr/src/app/src/knex/
- ./src/global/:/usr/src/app/src/global/
- ./src/global/@types/database.d.ts:/usr/src/app/src/types/database.d.ts
environment:
<<: *default-tz-puid-pgid
PORT: 5000
TZ: America/Chicago
POSTGRES_DB_URL: postgres://tripsit:${POSTGRESS_ROOT}@tripbot_database:5432/tripsit
POSTGRES_DB_URL: postgres://tripsit:${POSTGRESQL_PASSWORD}@tripbot_database:5432/tripsit
labels:
- com.centurylinklabs.watchtower.enable=false
- traefik.enable=true
Expand All @@ -118,23 +114,21 @@ services:
- traefik.http.routers.tripbot_prisma.middlewares=googleAuth@file

tripbot_pgadmin:
build:
context: ./
dockerfile: ./src/docker/Dockerfile.pgadmin
image: dpage/pgadmin4:latest
restart: unless-stopped
container_name: tripbot_pgadmin
depends_on:
- tripbot_database
# ports:
# - 8081:80
volumes:
- ./src/pgadmin4/servers.json:/pgadmin4/servers.json
networks:
- tripbot_pgadmin-net
- tripbot_database-net
environment:
<<: *default-tz-puid-pgid
TZ: America/Chicago
PGADMIN_DEFAULT_EMAIL: [email protected]
PGADMIN_DEFAULT_PASSWORD: ${POSTGRESS_ADMIN_PASS}
PGADMIN_DEFAULT_PASSWORD: ${PGADMIN_PASSWORD}
labels:
- com.centurylinklabs.watchtower.enable=false
- traefik.enable=true
Expand Down Expand Up @@ -191,7 +185,7 @@ services:
<<: *default-tz-puid-pgid
PORT: 5000
TZ: America/Chicago
DATABASE_URL: postgres://tripsit:${POSTGRESS_ROOT}@tripbot_database:5432/tripsit
DATABASE_URL: postgres://tripsit:${POSTGRESQL_PASSWORD}@tripbot_database:5432/tripsit
labels:
- com.centurylinklabs.watchtower.enable=false
- traefik.enable=true
Expand Down
Loading

0 comments on commit 0d37188

Please sign in to comment.