Skip to content

Commit

Permalink
feat(cli): ask for database information (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
cball authored Aug 25, 2020
1 parent 02e4a93 commit ef2e47a
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ npx create-bison-app MyApp

## Setup the database

1. Create a new database locally (Postgres is the only type fully supported right now)
1. Setup a database locally (Postgres is the only type fully supported right now)
1. Make sure your database user has permission to create schemas and databases. We recommend using a superuser account locally to keep things easy.
1. Search for DATABASE_URL in the project, and make sure the values are correct for your system.
1. Setup your local database with `yarn db:setup`. You'll be prompted to create it if it doesn't already exist:

![Prisma DB Create Prompt](https://user-images.githubusercontent.com/14339/88480536-7e1fb180-cf24-11ea-85c9-9bed43c9dfe4.png)
Expand Down
36 changes: 36 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@ function generateQuestions(appName) {
type: "input",
message: "Create a new GitHub repo and paste the url here:",
},
{
name: "db.dev.name",
type: "input",
message: "What is the local database name?",
default: `${appName}_dev`,
},
{
name: "db.dev.user",
type: "input",
message: "What is the local database username?",
default: "postgres",
},
{
name: "db.dev.password",
type: "input",
message: "What is the local database password?",
default: "",
},
{
name: "db.dev.host",
type: "input",
message: "What is the local database host?",
default: "localhost",
},
{
name: "db.dev.port",
type: "input",
message: "What is the local database port?",
default: "5432",
},
{
name: "db.test.name",
type: "input",
message: "What is the local test database name?",
default: `${appName}_test`,
},
{
name: "host.name",
type: "list",
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ module.exports = async ({ name, ...answers }) => {
variables
),

copyWithTemplate(
fromPath("tests/jest.setup.js.ejs"),
toPath("tests/jest.setup.js"),
variables
),

...herokuFiles(),

cpy(
Expand All @@ -134,11 +140,12 @@ module.exports = async ({ name, ...answers }) => {
"pages",
"!pages/api/graphql*",
"prisma",
"!prisma/_.env",
"!prisma/_.env*",
"public",
"scripts",
"services",
"tests",
"!tests/jest.setup*",
"utils",
".eslintrc.js",
".gitignore",
Expand Down
2 changes: 1 addition & 1 deletion template/_.env.test.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# ENV vars here override .env when running tests
DATABASE_URL="postgresql://postgres@localhost:5432/<%= name %>_test?schema=public"
DATABASE_URL="postgresql://<%= db.dev.user %><%= db.dev.password %>@<%= db.dev.host %>:<%= db.dev.port %>/<%= db.test.name %>?schema=public"
APP_SECRET=foo
2 changes: 1 addition & 1 deletion template/prisma/_.env.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL and SQLite.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://postgres@localhost:5432/<%= name %>_dev?schema=public"
DATABASE_URL="postgresql://<%= db.dev.user %><%= db.dev.password %>@<%= db.dev.host %>:<%= db.dev.port %>/<%= db.dev.name %>?schema=public"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = async () => {
// isUp = await statusCheck();
// }
// console.log(`[jest] server is up...`);
const testDatabaseName = 'testing';
const testDatabaseName = '<%= db.test.name %>';
const testSchema = `test_${nanoid().toLowerCase()}`;
const testDatabaseUrl = new URL(process.env.DATABASE_URL);
testDatabaseUrl.pathname = `/${testDatabaseName}`;
Expand Down

0 comments on commit ef2e47a

Please sign in to comment.