lukevella / rallly

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
https://rallly.co
GNU Affero General Public License v3.0
3.56k stars 338 forks source link

Can't create a poll [error 500] #158

Closed 9j7axvsLuF closed 2 years ago

9j7axvsLuF commented 2 years ago

I deployed a self-hosted instance of Rallly with Caprover. I connected the instance to a Postgres database. However, when I try to create a poll, I get the following error in the console:

Error: Request failed with status code 500

In the logs of my postgres instance I can see:

ERROR:  relation "public.User" does not exist at character 34
STATEMENT:  SELECT "public"."User"."id" FROM "public"."User" WHERE "public"."User"."email" = $1 OFFSET $2
lukevella commented 2 years ago

Looks like you forgot to run the migrations. This is needed to create the tables in the database. Run this before starting the server.

yarn prisma migrate deploy
9j7axvsLuF commented 2 years ago

This gives me the following error:

error Command failed with exit code 1.

info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{"code":1,"message":"The command '/bin/sh -c yarn prisma migrate deploy' returned a non-zero code: 1"}
The command '/bin/sh -c yarn prisma migrate deploy' returned a non-zero code: 1
9j7axvsLuF commented 2 years ago

@lukevella Following up on this, do you know what's causing the error?

lukevella commented 2 years ago

@9j7axvsLuF Can't say for sure because that error doesn't say much but most likely you are running yarn prisma migrate deploy at the wrong time or place. It needs to run before you start the server and you need to have DATABASE_URL pointing to your postgres database when this command runs otherwise it won't be able to set up the tables.

osresearch commented 2 years ago

I get the same error with a checkout of c07885beeeef1d74a82add8c944a6e335876bd47 running via docker-compose up. The compose file sets the container command as yarn prisma migrate deploy && yarn start, so the migrations are run before the server starts and it says "no migrations found":

# docker-compose up
Starting rallly_rallly_db_1 ... done
Starting rallly_rallly_1    ... done
Attaching to rallly_rallly_db_1, rallly_rallly_1
rallly_db_1  | 
rallly_db_1  | PostgreSQL Database directory appears to contain a database; Skipping initialization
rallly_db_1  | 
rallly_db_1  | 2022-05-19 18:24:32.896 UTC [1] LOG:  starting PostgreSQL 13.4 on x86_64-pc-linux-musl, compiled by gcc (Alpine 10.3.1_git20210424) 10.3.1 20210424, 64-bit
rallly_db_1  | 2022-05-19 18:24:32.896 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
rallly_db_1  | 2022-05-19 18:24:32.896 UTC [1] LOG:  listening on IPv6 address "::", port 5432
rallly_db_1  | 2022-05-19 18:24:32.903 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
rallly_db_1  | 2022-05-19 18:24:32.912 UTC [21] LOG:  database system was shut down at 2022-05-19 18:24:30 UTC
rallly_db_1  | 2022-05-19 18:24:32.916 UTC [1] LOG:  database system is ready to accept connections
rallly_1     | yarn run v1.22.19
rallly_1     | $ /usr/src/app/node_modules/.bin/prisma migrate deploy
rallly_1     | Prisma schema loaded from schema.prisma
rallly_1     | Datasource "db": PostgreSQL database "db", schema "public" at "rallly_db:5432"
rallly_1     | 
rallly_1     | No migration found in prisma/migrations
rallly_1     | 
rallly_1     | 
rallly_1     | No pending migrations to apply.
rallly_1     | Done in 2.39s.
rallly_1     | yarn run v1.22.19
rallly_1     | $ next start
rallly_1     | ready - started server on 0.0.0.0:3000, url: http://localhost:3000
rallly_db_1  | 2022-05-19 18:24:52.947 UTC [30] ERROR:  relation "public.users" does not exist at character 35
rallly_db_1  | 2022-05-19 18:24:52.947 UTC [30] STATEMENT:  SELECT "public"."users"."id" FROM "public"."users" WHERE "public"."users"."email" = $1 OFFSET $2
osresearch commented 2 years ago

By changing the command to yarn prisma migrate deploy --schema prisma/schema.prisma, it ran the migrations to create all the tables and I was able to create a demo poll on my instance. PR #182 adds this to the command.