Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Change to use database environment variables in dev mode #8951

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

0417taehyun
Copy link
Contributor

@0417taehyun 0417taehyun commented Dec 10, 2024

About the changes

Problems

  • I need to change the server-dev.ts code manually when trying to disable the migration even though it could be provided by the environment variable,DATABASE_DISABLE_MIGRATION.

Development Environment

  • I usually handle my environment variables like the one below with .envrc, which are the same ways that I've been using on development and production environment.
export DATABASE_USERNAME=
export DATABASE_PASSWORD=
export DATABASE_HOST=
export DATABASE_PORT=
export DATABASE_NAME=
export DATABASE_SCHEMA=
export DATABASE_APPLICATION_NAME=
export DATABASE_DISABLE_MIGRATION=
  • It might be better to handle them as the seamless way on the dev mode for the development experience.

Solutions

  • I change to use database environment variables such as DATABASE_HOST when running dev mode
  • I change contributing backend overview document to describe how to use pre-defined database with environment variables

Discussion points

In some cases, users want to use their pre-defined database in dev mode and now they only can use DATABASE_URL. However, it is more efficient to help them use separated options such as DATABASE_HOST and DATABASE_PORT.

Copy link

vercel bot commented Dec 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 0:03am
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 11, 2024 0:03am

Copy link

vercel bot commented Dec 10, 2024

@0417taehyun is attempting to deploy a commit to the unleash-team Team on Vercel.

A member of the Team first needs to authorize it.

process.env.DATABASE_APPLICATION_NAME ||
'unleash',
disableMigration: parseEnvVarBoolean(
process.env.DATABASE_DISABLE_MIGRATION,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to handle migration flag through environment variable in dev mode because sometimes users don't want to run migration and they have to turn it off by fixing code if they can't handle it via environment variable.

@@ -61,7 +61,7 @@
"test:coverage:jest": "NODE_ENV=test PORT=4243 jest --silent --ci --json --coverage --testLocationInResults --outputFile=\"report.json\" --forceExit --testTimeout=10000",
"test:updateSnapshot": "NODE_ENV=test PORT=4243 jest --updateSnapshot --testTimeout=10000",
"seed:setup": "ts-node --compilerOptions '{\"strictNullChecks\": false}' src/test/e2e/seed/segment.seed.ts",
"seed:serve": "UNLEASH_DATABASE_NAME=unleash_test UNLEASH_DATABASE_SCHEMA=seed yarn run start:dev",
"seed:serve": "DATABASE_NAME=unleash_test DATABASE_SCHEMA=seed yarn run start:dev",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn seed:serve also use start:dev and it would be better to use the same environment variables instead of using different name such as UNLEASH_DATABASE_NAME.

Copy link
Collaborator

@melindafekete melindafekete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Left some suggestions for the docs.

website/docs/contributing/backend/overview.md Outdated Show resolved Hide resolved
website/docs/contributing/backend/overview.md Outdated Show resolved Hide resolved
website/docs/contributing/backend/overview.md Outdated Show resolved Hide resolved
@0417taehyun
Copy link
Contributor Author

@melindafekete

Thanks! I applied your review on 34c6998 commit.

@0417taehyun
Copy link
Contributor Author

I don't know why the test was failed even though I didn't change anything related of that 🤔

FAIL src/lib/features/metrics/instance/metrics.test.ts (8.894 s)
  ● bulk metrics › filters out metrics for environments we do not have access for. No auth setup so we can only access default env

    expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 0
    Received array:  []

      312 |             );
      313 |         expect(developmentReport).toHaveLength(0);
    > 314 |         expect(defaultReport).toHaveLength(1);
          |                               ^
      315 |         expect(defaultReport[0].yes).toBe(1000);
      316 |     });
      317 |

      at Object.toHaveLength (src/lib/features/metrics/instance/metrics.test.ts:314:31)

@ivarconr ivarconr self-requested a review December 12, 2024 12:37
@ivarconr
Copy link
Member

Thanks @0417taehyun!

In general the changes seems fine. But could you update the description to explain which problem it is solving for you and put some words on how you run Unleash / postgres locally while developing Unleash.

@0417taehyun
Copy link
Contributor Author

@ivarconr

Hi, I've updated my description. Thanks!

@0417taehyun
Copy link
Contributor Author

@ivarconr

Hi, is there any progress of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Investigating
Development

Successfully merging this pull request may close these issues.

3 participants