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: Allow user to select a different database type #124

Binary file added docs/elephant.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions docs/homebrewPostgresInstructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Homebrew - (Mac Only)
## Installing PostgreSQL

1. Install using hombrew: `brew install postgres`
2. Add a local user (we recommend creating as a superuser to keep setup simple): `create user postgres --superuser`

## Start Server and Login

```
$ brew services start postgresql
$ psql postgres
```
8 changes: 8 additions & 0 deletions docs/postgres.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Installing Postgres
![Postgres Logo](./docs/elephant.png)

[Postgres.app - Mac](./docs/postgresAppInstructions.md)

[Homebrew - Mac](./docs/homebrewPostgresInstructions.md)

[Enterprise Database - (Windows, Mac, and Linux)](./docs/postgresqlEDBInstructions.md)
31 changes: 31 additions & 0 deletions docs/postgresAppInstructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Postgres.app (Mac Only)
**This is only available for Mac users*

[Download Postgres.app]([https://postgresapp.com/downloads.html](https://postgresapp.com/downloads.html))

[https://postgresapp.com/downloads.html](https://postgresapp.com/downloads.html)

## What is PostgreSQL?

Open-sourced relational database management system (RDBMS) used to create and modify databases

## Installing and Setting up Postgres.app

1. Download the Latest Version → Move it to Applications folder (required) → Double Click
2. Create a new server by clicking "Initialize"
3. Copy and paste the following to configure the `$PATH` and use the command line tools

```
sudo mkdir -p /etc/paths.d &&
echo /Applications/Postgres.app/Contents/Versions/latest/bin | sudo tee /etc/paths.d/postgresapp
```

4. Start [Postgres.app](http://postgres.app) and restart your terminal

### Default Settings:

![https://s3-us-west-2.amazonaws.com/secure.notion-static.com/95472c60-f022-4240-bea2-1d8bc885e51d/Screen_Shot_2020-12-30_at_5.15.46_PM.png](https://s3-us-west-2.amazonaws.com/secure.notion-static.com/95472c60-f022-4240-bea2-1d8bc885e51d/Screen_Shot_2020-12-30_at_5.15.46_PM.png)

## Connect to a Database using Postgres.app

Double click the database you want to connect to
29 changes: 29 additions & 0 deletions docs/postgresqlEDBInstructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# EDB - (Windows, Mac, and Linux)
[PostgreSQL Database Download](https://www.enterprisedb.com/downloads/postgres-postgresql-downloads)

## What is EDB Postgres?

> A scalable platform designed to help users with everything from maintenance and distribution to support and documentation - *EDB.com*


## Operating Systems:

macOS

Windows

Linux x86-64

Linux x86-32

## What is included:

PostgreSQL Server

pgAdmin

- Graphical tool for managing your databases

StackBuilder

- Package manager used to download and install additional tools and drivers
59 changes: 53 additions & 6 deletions packages/create-bison-app/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const createBisonApp = require(".");
const inquirer = require("inquirer");
const Logo = require("./logo");
const execa = require("execa");
const chalk = require('chalk');

const TYPE_MAPPING = {
input: "string",
Expand Down Expand Up @@ -51,40 +52,86 @@ function generateQuestions(appName) {
default: "main",
when: (answers) => answers.repo.addRemote,
},
{
name: "db.dev.databaseType",
type: "list",
message: "What type of database would you like to use?",
description: "The database type",
choices: [
{ name: "Postgres", value: "postgres" },
{ name: "MySQL", value: "MySQL" },
{ name: "SQLite", value: "SQLite" },
Copy link
Member

Choose a reason for hiding this comment

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

Thoughts on adding an array of supported databases as a constant? I haven't tested this, but the following should work:

const SUPPORTED_DATABASES = {
  postgres: { label: "Postgres", defaultPort: 5432 },
  mysql: { label: "MySQL", defaultPort: 3306 },
  sqlite: { label: "SQLite", defaultPort: "file:./dev.db" },
}

// use it to create the choices
{
  choices: Object.values(SUPPORTED_DATABASES)
}

Copy link
Member

Choose a reason for hiding this comment

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

It changes some of the methods, but instead of just checking against postgres everywhere we can keep the information in one place.

],
default: "postgres",
},
{
name: "db.dev.localDatabasePrompt",
type: "confirm",
message: "Do you have it setup?",
description: "Verify user has a db setup",
default: true,
},
{
name: "db.dev.continue",
type: "confirm",
message: "Visit https://github.com/echobind/bisonapp/blob/main/docs/postgres.md for intructions to setup a new database.\n\bContinue? Press [Enter] for YES",
description: "Provide link to help install Postgres",
when: (answers) => answers.db.dev.localDatabasePrompt == false && answers.db.dev.databaseType == "postgres",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
when: (answers) => answers.db.dev.localDatabasePrompt == false && answers.db.dev.databaseType == "postgres",
when: (answers) => answers.db.dev.localDatabasePrompt === false && answers.db.dev.databaseType === SUPPORTED_DATABASES.POSTGRES.value,

default: true,
},
{
name: "db.dev.name",
type: "input",
message: "What is the local database name?",
prefix: "The name you will use for the new database (or current).\n",
message: `${chalk.green("\b?")} Local database name`,
description: "The database to use in development",
default: `${appName}_dev`,
},
{
name: "db.dev.user",
type: "input",
message: "What is the local database username?",
prefix: "The username you will use for the new database (or current).\n",
message: `${chalk.green("\b?")} Local database username`,
description: "The database user",
default: "postgres",
},
{
name: "db.dev.password",
type: "input",
message: "What is the local database password?",
prefix: "The password you will use for the new database (or current).\n",
message: `${chalk.green("\b?")} Local database password`,
description: "The database password",
default: "",
},
{
name: "db.dev.host",
type: "input",
message: "What is the local database host?",
prefix: "The host you will use for the new database (or current).\n",
message: `${chalk.green("\b?")} Local database host`,
description: "The database host",
default: "localhost",
},
{
name: "db.dev.port",
type: "input",
message: "What is the local database port?",
prefix: "The port you will use for the new database (or current).\n",
message: `${chalk.green("\b?")} Local database port`,
description: "The database port",
default: "5432",
default: (answers) => {
switch (answers.db.dev.databaseType) {
case "postgres":
return 5432;
break;
case "SQLite":
return "file:./dev.db";
break;
case "MySQL":
return 3306;
break;
default: 5432;
break;
}
Copy link
Member

Choose a reason for hiding this comment

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

If we make the suggested change above, we can change to:

{
  default: (answers) =>. {
    const database = SUPPORTED_DATABASES.find(d => d.value === answers.db.dev.databaseType);
    if (!database) return SUPPORTED_DATABASES.POSTGRES.value;

    return database.value;
  }  
}

I'm not sure the default port as postgres actually buys us anything, but it's good to be defensive about it 👍

},
},
{
name: "db.test.name",
Expand Down