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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions template/tests/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ module.exports = async () => {
// isUp = await statusCheck();
// }
// console.log(`[jest] server is up...`);
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."

testDatabaseUrl.searchParams.set('schema', testSchema);

global.schema = `test_${nanoid().toLowerCase()}`;
global.databaseUrl = `postgresql://postgres:postgres@localhost:5432/testing?schema=${global.schema}`;
global.schema = testSchema;
global.databaseUrl = testDatabaseUrl;

process.env.DATABASE_URL = global.databaseUrl;
global.process.env.DATABASE_URL = global.databaseUrl;
Expand Down