Skip to content

Commit

Permalink
Merge main into branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzysoror committed Nov 20, 2024
2 parents 49cdc1f + 650fe98 commit 95305c7
Show file tree
Hide file tree
Showing 20 changed files with 669 additions and 308 deletions.
1 change: 0 additions & 1 deletion .dockerignore

This file was deleted.

5 changes: 0 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,4 @@ EXPOSE 3000

# Run the application
CMD echo "Running Prisma commands..." && \
npx prisma generate && \
npx prisma db push && \
npx @snaplet/seed sync && \
npx prisma db seed && \
echo "Starting Next.js application..." && \
npm run dev
44 changes: 15 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,55 +136,41 @@ docker system prune -a --volumes

### Accessing PostgreSQL Database

Run in two lines (View Absences Table):

```bash
# Open a Postgres shell in the sistema-db -1 Docker container and connect to the sistema database
docker exec -it sistema-db-1 psql -U sistema -d sistema
# Retrieve all rows from the "Absence" table
SELECT * FROM public."Absence";
```

Running the commands line by line.

```bash
# run a bash shell in the container
docker exec -it sistema-db-1 /bin/bash

# in container now
psql -U sistema -d sistema

# in postgres shell, some common commands:
# display all table names
# Some other helpful commands:
# Display all table names
\dt
# quit
# Quit
\q
# you can run any SQL query, don't forget the semicolon!
# Retrieve rows from other tables (don't forget the semicolon)
SELECT * FROM public."<table-name>";
```

### Seeding the Production Database

\*\* Database seeds automatically locally when docker compose build --up is run. Only run the following commands to seed the production database.
The local database seeds automatically locally when `docker compose build --up` is run. Only run the commands below to seed the production database:

In the schema.prisma, set env variable to VERCEL_DATABASE_NON_POOLING. Then run the following command.
In the schema.prisma, set the db datasource as follows:

```bash
npx prisma generate; npx prisma db push; npx @snaplet/seed sync; npx prisma db seed
```prisma
datasource db {
provider = "postgresql"
url = env("VERCEL_POSTGRES_PRISMA_URL")
directUrl = env("VERCEL_POSTGRES_URL_NON_POOLING")
}
```

Run the following commands:
Then, run the following commands:

```bash
npx prisma generate
npx prisma db push
```

```bash
# In the root directory to sync seed.ts to the current data models of the database
npx @snaplet/seed sync

# Seeding the database according to seed.ts
npx prisma db seed

```

## Formatting and Linting
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
- db
volumes:
- .:/sistema
- /sistema/node_modules
environment:
- NODE_ENV=development
- WATCHPACK_POLLING=true
Expand All @@ -17,6 +18,12 @@ services:
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_PORT=${POSTGRES_PORT}
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DATABASE}
command: >
sh -c "npx prisma generate &&
npx prisma db push &&
npx @snaplet/seed sync &&
npx prisma db seed &&
npm run dev"
db:
image: postgres:16-alpine
ports:
Expand Down
Loading

0 comments on commit 95305c7

Please sign in to comment.