Here is how I have done it:
- Create two publish targets -
dev
&prod
(which you too have probably done) - Make sure
dev
&prod
MySQL db schema are replicas - Create one db connection
- When using
dev
, go to any server action, edit the db connection and set values as per your dev environment. When you save db connection settings,dev
MySQL schema is applied.
Publish your app and everything should work fine. - When using
prod
, go to any server action, edit the db connection and set values as per yourprod
env. eg: server would be some IP instead of localhost. Username, password, db name could be different too.
Save, schema will refresh, but remain same. Publish & everything should work fine onprod
.
I did this multiple times while developing my application and found no issues.
Just make sure all server actions use the same db connection.
If you want, you can also create two db connections. Then you will be shown an option to select the connection. But this would require you to edit each and every server action every time you need to switch between dev
& prod
.