Same code different database

I want to run the same code, just connection parameters to a different database. One URL points to one database and another to a different database.
I have achieved this by replicated the projects and then having the constants changed in each project whilst the code remains the same. I am sure there is a better way than having duplicate code because this causes me syncronisation problems, so an enhancement/bug fix has to be kept in line in two different projects which is a pain.
Richard

Hi there

What is the scenario/problem you’re trying to solve? This sounds like a X/Y Problem ( The XY Problem) - but I’m guessing this is for test vs prod?

One solution is:

  1. Create two repos A and B
  2. Repo A contains the actual code and render.yaml
  3. Repo B contains no code only render.yaml

Repo A uses no repo key in the yaml (default current repo)
Repo B uses repo key and points to Repo A

See: Blueprint Specification | Render

Repo A points to Database A in its yaml
Repo B points to Databae B in its yaml

Two repos, same code, two connection strings.

I have this setup, one has automatic deployment (staging) and the other manual deployment (prod) and it works fine. The two repos isn’t maybe ideal / very clean, but it works.

To give an example if your code is at: https://github.com/myuser/myrepo.git and Repo A contains all your code then you can do this:

Repo A:

services:
  - type: web
    name: project-test
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: database-test
          property: connectionString

Repo B

services:
  - type: web
    name: project-prod
    repo: https://github.com/myuser/myproject
    envVars:
      - key: DATABASE_URL
        fromDatabase:
          name: database-prod
          property: connectionString

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.