Today, many people talk about microservice. The new-born EdgeDB also doesn't stay outside that trend. But not every website is applicable for microservice. Due to low traffic, low budget, some websites still prefer single-server deployment, meaning that everything, application and databases, are hosted in the same server. But EdgeDB lacks a traightforward documentation for this setup. This post is to guide how to do.
EdgeDB was renamed to Gel.
Install Gel package
Follow this guide to install Gel package on your server, but hold on before "Enable a systemd unit" section.
Setup simple authentication for Gel
In single-server deployment, the database systems don't serve applications outside that server. We can configure to:
- Gel server only listens on localhost (127.0.0.1).
- Not require password for connection from same-server apps.
In PostgreSQL, password-less authentication can be achieved by using peer authentication. But in EdgeDB, I haven't found that mode yet, so we will use "trust" method.
Run
sudo systemctl edit gel-server-7
to create a file /etc/systemd/system/gel-server-7.service.d/override.conf. Add this content:
[Service]
ExecStart=
ExecStart=/usr/lib/x86_64-linux-gnu/gel-server-7/bin/gel-server --data-dir=${GELDATA} --runstate-dir=%t/gel --tls-cert-mode=generate_self_signed --default-auth-method=trust --binary-endpoint-security=optional
Note that, you just copy the original ExectStart then add two parameters --default-auth-method and --binary-endpoint-security.
If you want to edit the file with Helix editor, run sudo as:
$ sudo VISUAL=hx systemctl edit ...
Save the file and start the Gel server by:
$ sudo systemctl start gel-server-7
At the first time we run this, it will take a while, for EdgeDB to generate self-signed TLS certificate.
After this, we can make Gel server auto-start:
$ sudo systemctl enable gel-server-7
Create database
Assume that our application wants the database to be named our-db-name, we create it by:
$ gel --port 5656 --tls-security insecure branch create our-db-name
Create instance linking with created database
For convenience, we should define a Gel instance:
$ gel project init --link -I OurWeb --tls-security insecure --no-migrations
When this command asks for database name, give it the value in the previous step.
From now on, we can connect to our Gel database, from CLI or from our app, with this instance name.
$ gel -I OurWeb -b our-db-name restore