Skip to content

Commit

Permalink
feat: prisma migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
diced committed Dec 28, 2024
1 parent 6f044c6 commit 651efbc
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 125 deletions.
5 changes: 1 addition & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
.github
.next
.yarn/cache
.yarn/install-state.gz
build
node_modules
public
uploads
uploads*
.env
.eslintcache
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM node:20-alpine3.19 AS base

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable pnpm
RUN corepack prepare pnpm@latest --activate

Expand Down Expand Up @@ -38,6 +39,8 @@ COPY --from=builder /zipline/.next ./.next
COPY --from=builder /zipline/mimes.json ./mimes.json
COPY --from=builder /zipline/code.json ./code.json

RUN pnpm build:prisma

# clean
RUN rm -rf /tmp/* /root/*

Expand Down
135 changes: 26 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,78 +1,17 @@
# Zipline 4

! This is a work in progress, the database is not final and is subject to change without a migration. !
> [!WARNING]
> This is a work in progress, the database is not final and is subject to change without a migration.
Roadmap for v4: https://diced.notion.site/Zipline-v4-Roadmap-058aceb8a35140e7af4c726560aa3db1?pvs=4

## Running Zipline v4

Running Zipline v4 as of now is kind of complicated due to the database being subject to change. At this stage the database is most likely final, but I rather not create migrations while the project is still in development.
Running v4 as of the latest commit is as simple as spinning up a docker container with a few of the required environment variables.

### updating image
It is recommended to follow the guide available at [v4.zipline.diced.sh/docs/get-started/docker](https://v4.zipline.diced.sh/docs/get-started/docker).

If you are using the provided docker images, they will be updated on every commit to the `v4` branch. You can pull the latest image by running:

```bash
docker pull ghcr.io/diced/zipline:v4
```

### ⚠ first run ⚠

If you are running v4 for the first time, you must prototype the database using prisma. To do this through docker follow the instructions in the `docker-compose.yml`.

```yml
---
zipline:
image: ghcr.io/diced/zipline:v4
# ATTENTION !
# entrypoint: ['pnpm', 'db:prototype']
# Uncomment the above for the first run, then comment it out again after it runs once.
# The database is subject to change, this will reset the current db to match the prisma schema.
```

If you follow the instructions the `zipline` service within the docker-compose.yml file should look similar to this.

```yml
---
zipline:
image: ghcr.io/diced/zipline:v4
# ATTENTION !
entrypoint: ['pnpm', 'db:prototype']
```
This will run `pnpm db:protoype` which will sync the postgres schema with zipline's prisma schema.

You can simply run the following command to start the container with the prototype command now:

```bash
docker compose up
```

#### non docker-compose

If you aren't using docker compose, you can just run the following (this is assuming you have node@lts and pnpm@9 installed):

```bash
pnpm db:prototype
```

Stop the containers with `Ctrl + C` or `docker compose down` after the prisma command has finished running successfully (hopefully).

### after first run

Make sure to comment the `entrypoint` line in the docker-compose.yml file after the first run. If this is not run, every time the container is started it will run the prototype command instead of actually running Zipline.

Once you have run the prototype command, you can start the container with the following command:

```bash
docker compose up
```

or (detached)

```bash
docker compose up -d
```
There is also a guide on how to run Zipline v4 without docker [here](https://v4.zipline.diced.sh/docs/get-started/source).

# Contributing

Expand All @@ -86,55 +25,39 @@ Here are some simple instructions to get Zipline v4 running and ready to develop

## Setup

You should probably use a `.env` file to manage your environment variables, here is an example .env file:
You should probably use a `.env` file to manage your environment variables, here is an example .env file with every available environment variable:

````bash
DEBUG=zipline

# required
CORE_SECRET="a secret"
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/zipline?schema=public"

MFA_TOTP_ENABLED=true

FILES_ROUTE='/'
URLS_ROUTE='/'

FILES_REMOVE_GPS_METADATA=false

DATASOURCE_TYPE='local'
DATASOURCE_LOCAL_DIRECTORY='./uploads'

TASKS_METRICS_INTERVAL=1min

FILES_MAX_FILE_SIZE=100mb

# OAUTH_BYPASS_LOCAL_LOGIN=true
OAUTH_DISCORD_CLIENT_ID=x
OAUTH_DISCORD_CLIENT_SECRET=x

OAUTH_GITHUB_CLIENT_ID=x
OAUTH_GITHUB_CLIENT_SECRET=x
# required
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/zipline?schema=public"

OAUTH_GOOGLE_CLIENT_ID=x-x.apps.googleusercontent.com
OAUTH_GOOGLE_CLIENT_SECRET=x-x-x
# these are optional
CORE_PORT=3000
CORE_HOSTNAME=0.0.0.0

OAUTH_OIDC_CLIENT_ID=x
OAUTH_OIDC_CLIENT_SECRET=x
OAUTH_OIDC_AUTHORIZE_URL=http://localhost:9000/application/o/authorize/
OAUTH_OIDC_USERINFO_URL=http://localhost:9000/application/o/userinfo/
OAUTH_OIDC_TOKEN_URL=http://localhost:9000/application/o/token/
# one of these is required
DATASOURCE_TYPE="local"
DATASOURCE_TYPE="s3"

FEATURES_OAUTH_REGISTRATION=true
FEATURES_USER_REGISTRATION=true
# if DATASOURCE_TYPE=local
DATASOURCE_LOCAL_DIRECTORY="/path/to/your/local/files"

DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/x/x-x
DISCORD_ONUPLOAD_USERNAME=testupload
DISCORD_ONUPLOAD_CONTENT="hello {user.username} {file.name}\n```json\n{debug.jsonf}\n```"
# if DATASOURCE_TYPE=s3
DATASOURCE_S3_ACCESS_KEY_ID="your-access-key-id"
DATASOURCE_S3_SECRET_ACCESS_KEY="your-secret-access-key"
DATASOURCE_S3_REGION="your-region"
DATASOURCE_S3_BUCKET="your-bucket"
DATASOURCE_S3_ENDPOINT="your-endpoint" # if using a custom endpoint other than aws s3

DISCORD_ONSHORTEN_USERNAME=testshorten
DISCORD_ONSHORTEN_CONTENT="hello {user.username} {url.id} {link.returned} {url.createdAt::locale::en-UK,Pacific/Auckland}\n```json\n{debug.jsonf}\n```"
# optional but both are required if using ssl
SSL_KEY="/path/to/your/ssl/key"
SSL_CERT="/path/to/your/ssl/cert"

FEATURES_METRICS_ADMIN_ONLY=true
````

Install dependencies:
Expand All @@ -143,12 +66,6 @@ Install dependencies:
pnpm install
```

The next step is important! You need to prototype the database using prisma. The command below will read the `DATABASE_URL` environment variable to sync the database. To do this run the following command:

```bash
pnpm db:prototype
```

Finally you may start the development server:

```bash
Expand Down
7 changes: 2 additions & 5 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DATABASE=postgres
- POSTGRES_DATABASE=postgres2
volumes:
- pgdata:/var/lib/postgresql/data
healthcheck:
Expand All @@ -18,15 +18,12 @@ services:
build:
context: .
dockerfile: Dockerfile
# UNCOMMENT THE BELOW LINE ON THE FIRST RUN!
# entrypoint: ['pnpm', 'db:prototype']
# entrypoint: ['pnpm', 'prisma', 'migrate', 'reset', '--force']
ports:
- '3000:3000'
env_file:
- .env
environment:
- DATABASE_URL=postgres://postgres:postgres@postgres/postgres
- DATABASE_URL=postgres://postgres:postgres@postgres/postgres2
- CORE_SECRET=thissecretisverynotsecretbutshouldonlybeusedindevelopmentsoitsfineiguess
- CORE_HOSTNAME=0.0.0.0
depends_on:
Expand Down
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ services:

zipline:
image: ghcr.io/diced/zipline:v4
# ATTENTION !
# entrypoint: ['pnpm', 'db:prototype']
# Uncomment the above for the first run, then comment it out again after it runs once.
# The database is subject to change, this will reset the current db to match the prisma schema.
ports:
- '3000:3000'
env_file:
Expand Down
Loading

0 comments on commit 651efbc

Please sign in to comment.