Need clarity with two databases for development and production

Hi!

I’m trying to set up work with separate databases for development and productiont on NodeJS with PostgreSQL.
I have set up two different targets with these bases, but when I work with localhost it still uses the product base.
How can I make it use the test database?
I read that there should be only one database in a Database connection, but the question is - which one?

Database connections are per target, it sound like you have overwritten the dev target setting with the production.
Always close the settings tab before changing target and reopen again or the page will not be refreshed with the related settings.

I checked this and saved again - but now after saving Wappler itself added a second database to the Database connections section - but I don’t understand why it is needed there if SC uses the first database, which was there alone before


When we use DB connection, what database should be specified there in the connection settings, the test one? And then, when publishing, Wappler will replace it with the production version when publishing the project?

You have somehow managed to create a second connection on the same target rather than pointing one connection to both targets

I don’t know, even if I delete the unnecessary stuff, when saving the project properties, Wappler creates it again

You need to configure DB credentials in two places

The other place is in the Server Workflow tab (I think that’s what called). Did you do it?

There I also now have two different connections and in the target settings there are also two different ones

And I don’t understand why Wappler connects the production base to the local server instead of the one that is explicitly specified in the Devolopment goal?

you need just one database connection - that is usually called “db”

The connection then has different options based on the currently selected target. So select the right target - enter the options and save. Then choose your product target and edit the options there and save.

After that when switching targets the right db options will be automatically switched.

2 Likes

I suggest you view this video from about 15 minutes in where I go through the process of creating development targets and production targets.
While video is about orangehost, the setup process is generic.

https://youtube.com/playlist?list=PLUjqTJN3byC8qIOJu2tAQK6CgcPjRMNi0&si=e9LPIaNMQWpBIi1y

3 Likes

It seems that I managed to connect the test database to the local target, but I have a question - in Server Actions, when writing queries, should we specify the connection for production?

You should only have one connection!
Wappler will select the per target settings dependent of the target selected automatically.

I understand that there should be one connection, and in Globals there is one, there is a test base, but in Database Connections Wappler itself creates a second one

Yes, when you add the database to the project settings it creates a default connection for you called db, no need to create another.
If you really want an alternative connection name, delete the db connection and edit the settings in VEF_ocean for each of the targets remembering to close and reopen the settings panel when switching targets.

1 Like

I don’t quite understand this detail - in the project settings, the database name is the real name of the database on the database server and there is no separate field for the name of the connection in Wappler to set it exactly specific. And then it cannot be changed in the Name field in the Database, since it is not saved. Or is it necessary to have an exact match of database names on servers for one project?

Maybe this can help you…

Did you watch the video I shared?
That should have clarified things.
The connection is just a connection name and does NOT need to be the same as your database name, in fact that probably bad for security

No, my question is that this is not an empty project and I have already used the connection name in many places in Server Actions and I would not like to change everything there manually again. And the connection name is used there, right?

Then just delete the db connection and work with the other one!

1 Like