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

feat: generate the db url based on the .env DATABASE_URL #34

Merged

Conversation

isaiahgrey93
Copy link
Contributor

@isaiahgrey93 isaiahgrey93 commented Aug 20, 2020

Changes

  • Generate the db url based on the .env DATABASE_URL by manipulating the path + schema param with node.js URL

Screenshots

(prefer animated gif)

Checklist

  • Requires dependency update?
  • Generating a new app works

Fixes #19

@isaiahgrey93 isaiahgrey93 self-assigned this Aug 20, 2020
@isaiahgrey93 isaiahgrey93 force-pushed the isaiahgrey93/generate-test-db-url-based-on-env-url branch from 915206c to 2a1c40b Compare August 20, 2020 17:06
@isaiahgrey93 isaiahgrey93 changed the base branch from main to next August 20, 2020 17:06
const testDatabaseName = 'testing';
const testSchema = `test_${nanoid().toLowerCase()}`;
const testDatabaseUrl = new URL(process.env.DATABASE_URL);
testDatabaseUrl.pathname = `/${testDatabaseName}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to modify the database used @cball? Or will the different schema suffice?

Copy link
Member

Choose a reason for hiding this comment

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

The only potential downside I can think of here is if someone creates a postgres user that is not a super user or does not have create schema permissions.

We either need to require that the postgres user has the right permissions, or we should take DATABASE_URL wholesale if defined.

I'm leaning towards requiring a postgres user with the right permissions and keeping the auto generated schema. what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm there with you on requiring the user with the right permissions vs using the existing dev database which might lead to test issues.

Should we document how to do this, or simply mention that the postgres user needs x permissions or is a super user?

Copy link
Member

Choose a reason for hiding this comment

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

Cool.

We should probably add to the docs (probably in getting started). Something like "When setting up postgres locally, we recommend creating a superuser to keep things easy, but if you'd like to change it just ensure the user has create schema permission."

Copy link
Member

@cball cball left a comment

Choose a reason for hiding this comment

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

looks good! :shipit:

@isaiahgrey93 isaiahgrey93 merged commit 23cb253 into next Aug 21, 2020
@isaiahgrey93 isaiahgrey93 deleted the isaiahgrey93/generate-test-db-url-based-on-env-url branch August 21, 2020 16:49
@github-actions
Copy link

🎉 This PR is included in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

cball pushed a commit that referenced this pull request Aug 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants