WhatsApp / WhatsApp-Business-API-Setup-Scripts

The scripts related to setting up WhatsApp business API
MIT License
410 stars 433 forks source link

Add support for WA_DB_NAME #19

Closed lforite closed 3 years ago

lforite commented 4 years ago

We are looking into deploying WhatsApp Business API but we noticed that the DB name cannot be set through envionment variables, even though it's possible all the other variables such as WA_DB_ENGINE, WA_DB_HOSTNAME, ... .

Would it be possible to add the support for the WA_DB_NAME environment variable ?

mengyiyuan commented 4 years ago

Hi Louis,

Can you please elaborate why you need to use different DB names? Please note that you can prefix DB names using the variable WA_DB_NAME_PREFIX as documented https://developers.facebook.com/docs/whatsapp/guides/mysql.

lforite commented 4 years ago

Hey I missed that part of the documentation, thanks for pointing it out ! Does it also work for PG ?

lforite commented 4 years ago

I just tried and it looks like it cannot parse db names with hyphens.

The following query works in PG: CREATE DATABASE "test-db"; but this one fails CREATE DATABASE test-db;. Now, trying to use prefix and postgres, we get the following error :

Failed to create web db or store db settings to database.yml file.
An exception occurred while executing 'CREATE DATABASE mydb-multiwaweb':

SQLSTATE[42601]: Syntax error: 7 ERROR:  syntax error at or near "-"
LINE 1: CREATE DATABASE mydb-multiwaweb

Could you please add quotes around the DB name so it is compatible with PG ? Thanks a lot

mengyiyuan commented 4 years ago

Hi @lforite

Did you set WA_DB_ENGINE to be PGSQL? Asking just in case you missed it.

Can you try setting WA_DB_HOSTNAME to "test-db" and see if it works? Will this be sufficient for you?

jdc-developer commented 4 years ago

Sorry if I seem ignorant, but I can't figure it out how this works. How do I tell the program what is the database name? I did the instructions as told and set the database server but it is stuck into: Database is not up yet - sleeping I guess that's because it doesn't know which database to connect in the server? And why DB_HOSTNAME is supposed to be database name? If I put the database name there I get, nc: getaddrinfo: Name or service not known , but if I put there localhost it works, but it is stuck into Database is not up yet - sleeping

If you may help, I'l be very glad.

jdc-developer commented 4 years ago

Also, I'm using Postgres, and set PGSQL as engine

mengyiyuan commented 4 years ago

@jdc-developer You needn't set your db name, you should set DB hostname as the value of WA_DB_HOSTNAME.

The API client will create a list of DBs for you on the DB host during initial setup.

Also make sure that WA_DB_USERNAME is a db user that has highest privileges.