W
Wasp-langβ€’3mo ago
manaphy

Running database migrations on hosted app

Hey everyone! I have my app hosted on Fly. - When I try to sign up or log in, it says "Save failed: there was a database error" (see image 1). - The Fly monitoring logs state the issue quite clearly: "🐝 This error can happen if you did't run the database migrations" (see image 2). How do I go about running database migrations before I deploy a new release? I was looking at the Fly docs https://fly.io/docs/reference/configuration/#the-deploy-section, which say to add a release_command to the .toml file.
Fly
Fly Launch configuration (fly.toml)
Documentation and guides from the team at Fly.io.
No description
No description
14 Replies
miho
mihoβ€’3mo ago
In a deployed app, we run the migrations on every application start. If there are any new migrations, they get applied, if not, nothing happens πŸ˜„ so I don't think you need to do anything for migrations AFAIK The error message that says "🐝 This error can happen if you did't run the database migrations" might be right but maybe we have some other issue as well. - Could maybe scroll a bit up in the backend logs to see the full error? πŸ™‚ - Does your app work locally okay? πŸ™‚
manaphy
manaphyβ€’3mo ago
Hi @miho thanks so much for responding. I attached a video showing the console errors and Fly logs as I load the website and attempt signup. The app works locally just fine! πŸ™‚
MEE6
MEE6β€’3mo ago
Wohooo @manaphy, you just became a Waspeteer level 1!
miho
mihoβ€’3mo ago
I see that it says "public.User" doesn't exist in the current database 🀨 I think we need to connect to the production database and see what's inside! 1️⃣ You can use the Fly CLI for that:
fly postgres connect -a <your-db-name>
fly postgres connect -a <your-db-name>
It will connect you to the PSQL tool that Postgres uses to give commands to the DB. 2️⃣ Write:
\l
\l
3️⃣ You'll se a list of available databases. Connect to your DB by running:
\c <database-name>
\c <database-name>
4️⃣ Execute the following to see the list of DB tables:
select table_name from information_schema.tables where table_schema='public';
select table_name from information_schema.tables where table_schema='public';
For the usual scenario, we expect to see something like this:
table_name
--------------------
_prisma_migrations
User
Auth
AuthIdentity
Session
table_name
--------------------
_prisma_migrations
User
Auth
AuthIdentity
Session
martinsos
martinsosβ€’3mo ago
@manaphy which Wasp version is this, 0.11 or 0.12? Also, did you do any changes between when the app was still working and when it stopped working?
manaphy
manaphyβ€’3mo ago
Hi @miho and @martinsos, thank you for your responses! - After \l, I'm able to view the list of databases (see image), but I can't connect to any of them. Any key I hit causes the Windows error sound. πŸ˜• - This is Wasp v0.12.4. After my hosting issue (https://discord.com/channels/686873244791210014/1216905991958827018), I updated to 0.12.4 and was successfully able to deploy. But that's all I've been able to do (deploy and view the landing page). I haven't been able to log in or sign up at all.
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
No description
miho
mihoβ€’3mo ago
@manaphy after you see the list of the DBs press q to exit that view and then you'll be able to continue 😊
manaphy
manaphyβ€’3mo ago
Interesting, this is all I see. prisma_migrations is there but none of the other stuff!
No description
miho
mihoβ€’3mo ago
Could you do SELECT * FROM _prisma_migrations; Obv something went wrong when applying migrations. Maybe deleting the apps on Fly and redeploying would be the best
manaphy
manaphyβ€’3mo ago
Nothing happens when I enter SELECT * FROM _prisma_migrations in the CLI 😦 I also tried deleting the apps and redeploying, but the same issue is occurring 😦
miho
mihoβ€’3mo ago
Could you DM me with your repository 🀨 I'll try to debug it on my computer 😊
manaphy
manaphyβ€’3mo ago
Yes, I just sent you the link! Thanks so much
miho
mihoβ€’3mo ago
One thing I noticed in your repository is that you don't have any migrations. This leads me to believe you never ran the wasp db migrate-dev πŸ™‚ This is something listed here: https://docs.opensaas.sh/start/getting-started/ It's important to run that command to get the latest Prisma models ready for your DB (which will be added to your local DB when you run the command and on deploy to your production DB). This will enable you to login and have a functioning app in general πŸ˜„ Read more about entities in the Wasp docs: https://wasp-lang.dev/docs/data-model/entities I'd suggest even going through the Wasp tutorial quickly: https://wasp-lang.dev/docs/tutorial/create
manaphy
manaphyβ€’3mo ago
Thanks @miho! I ran a database migration and redeployed. Login/signup work perfectly now! I appreciate your patience and willingness to help. :wasplang: ☺️ @Wasp Team I learned a lot playing around with Wasp and had a lot of fun. Thank you for building and releasing it for free. :boi: