Update / maintain production deployment
Lets say i deploy to fly my V1 of my app. How would i then maintain it and for example update it without having users loose data.
Let say i add a new page and some new actions locally. How can i push these to fly?
42 Replies
Hi @Sven. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To update your deployed app on Fly with the latest changes, you can use the
wasp deploy
command. Here's how you can do it:
This command pushes your client and server live. Run this command whenever you want to update your deployed app with the latest changes [^1^].
If you are deploying manually, for example on Railway, you would need to run wasp build
to rebuild your app and then railway up
in the .wasp/build
directory (server). Repeat all the steps in the .wasp/build/web-app
directory (client) [^3^].
When it comes to data migrations, it's important to have a good migration workflow and documentation for production. This is especially crucial when you're updating your app to ensure users don't lose data [^9^].
If you need to modify the server code a bit to execute some code after login / after signup, you can modify the .wasp/out
files. However, when deploying to Fly, Wasp builds a fresh build in .wasp/build
so those manual changes won't be deployed. One way to solve this is to have a "patched" version of the file you need to modify, somewhere in the project root. Then you provide your own custom Dockerfile
(which can be just the copy-paste version of the Dockerfile
in .wasp/build
folder). In that Dockerfile
include a line with something like cp ./my-patched-file.js server/something/somewhere.js
[^2^].
[^1^]: (source: https://wasp-lang.dev/docs/advanced/deployment/cli#deploy)
[^2^]: (source: https://discord.com/channels/686873244791210014/1223671727943319584)
[^3^]: (source: https://wasp-lang.dev/docs/advanced/deployment/manually#updates--redeploying)
[^9^]: (source: https://github.com/wasp-lang/wasp/issues/330)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?Huh?
A migration doesn't break your production database
Use wasp deploy fly deploy to deploy to prod
Ahh so then it updates all stuff
And lets say i add an env var i use -server-secret?
Or secret set
Thanks to
It's in the wasp deploy docs but yeah something like that
This is not in all cases, it depends what you’re changing. Some migrations can require manual intervention
Hmm why is that?
Let’s say you have a field that’s a string in prod, if you’re changing it to a Date field you’re going to run into issues
If you do migrate dev locally and it runs into issues like that, the same thing will happen in prod. You can ssh to the db and fix it in that case though
Wohooo @wardbox, you just became a Waspeteer level 9!
Usually when I need to change a field like that i add a brand new field with a slightly different name, leave the old one and make it optional if it isn’t already, and update references to the field to use the new one with the new type. Then once all references to the old field are eventually not in use you can just remove the old field from the schema
But if you aren’t changing types or adding unique constraints, most of the time the migration is fine
Yeah thanks clear
Sure - I agree, any migration that requires manual intervention on your local development side as well.
So when wasp db-migrate dev requires manual intervention then manual intervention in prod -- if you or anyone from wasp could make a slight guide or tell me some tips about how to do this this would be great.
This is the only part which I'm queasy about. The SQL migrations when new fields are added - do you have any helpful tips/links about that?
Wohooo @Adam, you just became a Waspeteer level 4!
https://www.prisma.io/dataguide/types/relational/migration-strategies
not wasp specific, but this outlines strategies for handling migrations
Prisma's Data Guide
Migrating database schema changes | Prisma's Data Guide
Learn about the advantages and disadvantages of various techniques for deploying schema changes to your database.
Awesome thanks!
But ward,
Lets say I changed somethings on the frontend. And added some actions. How would i makensure these changes get to production? After i already deployed the first version?
You just do a new deploy
any tips on connecting to prod. database with ext tools?
to view tables
@kapa.ai how do you connect over wireguard to fly.io Postgres database with wasp db studio
Let me check the knowledge base for you again. One moment! :books:
----------------------
To connect to your Fly production database, you can open up a tunnel with the following command:
After setting up the tunnel, you can execute
wasp db studio
to interact with your database using Prisma Studio [^1^].
However, please note that you should be careful when interacting with your production database. It's recommended to remove the DATABASE_URL
with the production database URL from .env.server
after you're done, to avoid accidentally making unwanted changes to the production database [^1^].
For more detailed steps on how to seed a production database, you can refer to this Github issue (https://github.com/wasp-lang/wasp/issues/1464) [^5^].
[^1^]: (source: https://discord.com/channels/686873244791210014/1220423321422663820)
[^5^]: (source: https://github.com/wasp-lang/wasp/issues/1464)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @wardbox, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?@kapa.ai how i ran the fly proxy 5432 -a <db-name>
, how can i now show the prisma studio in browser?
Let me check the knowledge base for you again. One moment! :books:
----------------------
After you've set up the tunnel with
fly proxy 5432 -a <db-name>
, you can run Prisma Studio with the following command:
This command will start Prisma Studio and automatically open it in your default web browser [^1^].
Please ensure that you've set the correct DATABASE_URL
in your .env.server
file. If Prisma Studio fails to connect, it might be due to an incorrect DATABASE_URL
(wrong password or database name), or something else might already be running on port 5432 [^5^].
[^1^]: (source: https://discord.com/channels/686873244791210014/1220423321422663820)
[^5^]: (source: https://github.com/wasp-lang/wasp/issues/1464)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?ah cool clear. now i also have my own server. What I want it for it to fill the production database table "datatable" with data everyday (python). I already have it working with a different postgres db. but how would i connect to it using my production DB?
psycopg2 is what i use.
Not sure, I haven’t used python with wasp
ahh but like how could i connect from an external server?
what credentials do i use?
@kapa.ai I have an app running on a server, how can iconnect to my production database (fly) through this python app? I want the app to inset data into a table everyday/
Let me check the knowledge base for you again. One moment! :books:
----------------------
To connect to your production database from a Python app, you'll need to use a PostgreSQL client for Python, such as
psycopg2
or sqlalchemy
. You'll also need the connection details for your database, which include the host, port, database name, username, and password.
Here's a basic example of how you might establish a connection using psycopg2
:
To get the connection details, you can use the fly postgres connect -a <db-name>
command to get the DB name [^5^]. For the DB password, you can use the fly ssh console -a <db-name>
command and then echo $OPERATOR_PASSWORD
[^5^].
Please note that this is a basic example and doesn't include error handling or other best practices for working with databases in Python. You'll also need to install the psycopg2
package, which you can do with pip install psycopg2
.
For inserting data into a table every day, you might want to look into using a task scheduler like cron on Unix-based systems, or Task Scheduler on Windows.
[^5^]: (source: https://github.com/wasp-lang/wasp/issues/1464)
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
Let me check the knowledge base for you again. One moment! :books:
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?but this is for localhost, how can i conect from a app running on a server? @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
To connect to your Fly production database from a Python app running on a server, you'll need to replace the
localhost
in the connection string with the actual host of your Fly database.
The host is typically a URL or IP address that points to the location of your database on the internet. You can find this information in the settings or configuration of your Fly database.
Here's how you might modify the previous Python code:
Remember to replace <your-fly-db-host>
, <db_name>
, and <password>
with your actual database host, database name, and password respectively.
Please note that exposing your database to the public internet can have security implications. It's recommended to secure your database connection, for example by using SSL/TLS encryption or by setting up a VPN or SSH tunnel. You might also want to restrict access to your database to specific IP addresses or ranges.
For more information on how to connect to your Fly database, you can refer to the Fly documentation (https://fly.io/docs/) or the Fly CLI command reference (https://fly.io/docs/flyctl/).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Sorry @Sven, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?any wasp team that could help, i would like to connect to my fly.io database from a python app running on a server.
which does some actoins everyday and inserts data in a table. Is there any way of connecting to my production fly postgres (from a server)?
Any tips? Maybe should i deploy my database somewhere else? And how would I make my app connect to that one then? Just secret set “DATABASE_URL” to my other host? And will this then automaticallly create the tables?
@Wasp Team I know u guys don like me tagging, but i have been searching the whole day and nothing works...
Not sure why you need to manually add data in your production app, but did you try seeding it? They have information about seeding.
If you need to access your production database, when you deployed to fly you needed to press a button after they showed you the database url and username and password, download dbbeaver and use that to connect and modify if you need.
Yeah I think we'd all benefit from a database migration document I'll work on writing something as well - I actually have been running into snags as well, for example I change something in my schema.prisma, i push to prod and expect the GitHub action to run the migration, but it doesn't pick the migration up. I've had to delete my app to pick up the migration, which is curious - I've looked at my logs and see there are conflicts, so maybe it is just my problem
Hmm well, my app provides valuablw information about searchdata for the past 30 days.
So that table needst to be updated everyday. I already have a working py script that updates these in a test table. Now i want to connect to my production table from thst “python app on my server”
Interesting approach, you have a local db that you want to connect with the prod database. I don't think that's really wasp specific, I would look into how to connect my database to the fly database.
Have you used cursor? It gives really good help
You also could have a job that does specific actions on your server, modifications of your database and so. I would probably do that approach actually, to forgo some weird joins, but your mileage may vary. Definitley try out cursor
well i already have a working script i want to use as it inovlves web scraping. And i just want my python app running on heroky to be able to connect to my fly postgres to insert data
Wohooo @Sven, you just became a Waspeteer level 11!
ok, yea I see would be great if wasp wanted to help pro bono, but I that's more app specific I think
so yeah any help would be apreciated
Okay Solved!
but i follwed these steps:
https://fly.io/docs/postgres/connecting/connecting-external/
Yup this is the best way to do it, I tihnk there is even a name for it, forward migrations or something like that, but it is the best practice.
@Adam you are right, we could do with better docs on migrations for sure, and also maybe a bit better setup on Wasp side (gihtub action, even in docker container).
We have an issue open for it here, hasn't been high priroty so far, but will happen before 1.0 for sure: https://github.com/wasp-lang/wasp/issues/330 .
GitHub
Support data migrations & provide best practices and examples · Iss...
While developing Waspello, at some point I wanted to migrate data in my db. I added pos field to List entity so I wanted to assign a default pos value to each existing List, otherwise the changed s...
@Sven -> this, what @Adam said. Best approach here would most likely be to make this a
job
in your Wasp app. This is safer, and should be easier to manage because python script now ships with your wasp app, you can version them together, you can test it locally, ... . You could rewrite that python to JS and do it that way. Or you can even keep using python script, but call it from wasp's job
, from JS, get the result from your python script, and then have JS update the database with it, via Prisma. So python does the scraping, JS does putting into the database. That way you can utilize Prisma. How can you call python from JS? Easiest way is probably to just run it as a process on the machine (something like child_process.execSync) and get output from its stdout, or have it write it to a tmp file and then read it from there.
Here you can find more info on how to possibly run python from Wasp https://github.com/wasp-lang/wasp/issues/1940 + you can see what some other users did.Okay cool, hmm i wold like to keep them seperated because the scraping can be intensive etc.
overall it should not matter as it just appends data daily and that data is used in my dashboard
If scraping is intensive, than that is a good argument to keep them separated, that is true. Is it really so intensive that you need another server machine though? You will know that the best!