forked from saasbook/flextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from cs169/187042246-dev-pg-config
[FEAT!] Set Up Postgres For All Environments
- Loading branch information
Showing
11 changed files
with
127 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# These targets were made with unix in mind. If you are not on unix, feel free to update for support. | ||
-include .env | ||
.DEFAULT_GOAL = dev | ||
|
||
env: | ||
@export DB_PORT=${DB_PORT} | ||
@export DB_USER=${DB_USER} | ||
@export DB_PASSWORD=${DB_PASSWORD} | ||
@export DB_NAME=${DB_NAME} | ||
@echo 'db environment updated' | ||
|
||
dev: env | ||
@yarn run dev | ||
|
||
db-migrate: env | ||
bin/rails db:migrate | ||
|
||
db-seed: env | ||
bin/rails db:seed | ||
|
||
init: env | ||
@command -v yarn > /dev/null 2>&1 || { echo >&2 "please install yarn first"; exit 1; } | ||
bin/rails db:setup | ||
bin/rails db:migrate | ||
bin/rails db:seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: bundle exec rails s -p 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,44 @@ | ||
# flextensions | ||
Back end/API for UC Berkeley EECS "Flextensions" software | ||
|
||
[![Maintainability](https://api.codeclimate.com/v1/badges/8d99ec9a1784ddba34ac/maintainability)](https://codeclimate.com/github/cs169/flextensions/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/8d99ec9a1784ddba34ac/test_coverage)](https://codeclimate.com/github/cs169/flextensions/test_coverage) | ||
[![Maintainability](https://api.codeclimate.com/v1/badges/8d99ec9a1784ddba34ac/maintainability)](https://codeclimate.com/github/cs169/flextensions/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/8d99ec9a1784ddba34ac/test_coverage)](https://codeclimate.com/github/cs169/flextensions/test_coverage) | ||
|
||
## Installation | ||
|
||
### Environment Variables | ||
|
||
For the environment variables, you will need to configure on your local system (and any deployment machines) the following environment variables (recommended through a `.env` file at root): | ||
|
||
- DB_PORT (default: 5432) | ||
- DB_USER (default: postgres) | ||
- DB_PASSWORD (default: password) | ||
- DB_NAME (default: postgres) | ||
|
||
Changing only the user and password then running `$make env` should be sufficient. | ||
|
||
### Postgres Installation | ||
|
||
#### MacOS | ||
|
||
- `brew install postgresql chromedriver` | ||
- Start postgres if necessary. `brew services start postgresql` | ||
|
||
#### Linux/WSL | ||
|
||
- `sudo apt install postgresql` | ||
- Create a postgres user. | ||
- `sudo su - postgres` (to get into postgres shell) | ||
- `createuser --interactive --pwprompt` (in postgres shell) | ||
- Save `DB_USER` and `DB_PASSWORD` fields in the `.env` file. | ||
- Start postgres if necessary. `pg_ctlcluster 12 main start` | ||
- Note: if you are using WSL2 on windows, the command to start postgres is `sudo service postgresql start` | ||
|
||
### Stand Up Server | ||
|
||
In order to stand up the server with [Overmind](https://github.com/DarthSim/overmind) in dev, run: | ||
|
||
```bash | ||
make dev | ||
``` | ||
|
||
*NOTE:* The Overmind binary is stored in `bin/overmind` and needs to be maintained manually. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
overmind (= 2.4.0) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
# SQLite. Versions 3.8.0 and up are supported. | ||
# gem install sqlite3 | ||
# | ||
# Ensure the SQLite 3 gem is defined in your Gemfile | ||
# gem "sqlite3" | ||
# | ||
default: &default | ||
adapter: sqlite3 | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
adapter: postgresql | ||
pool: 5 | ||
timeout: 5000 | ||
host: localhost | ||
port: <%= ENV['DB_PORT'] || '5432' %> | ||
username: <%= ENV['DB_USER'] || ENV['USER'] || 'postgres' %> | ||
password: <%= ENV['DB_PASSWORD'] || 'password' %> | ||
database: <%= ENV['DB_NAME'] || 'postgres' %> | ||
|
||
development: | ||
<<: *default | ||
database: storage/development.sqlite3 | ||
database: flextentions_dev | ||
|
||
# Warning: The database defined as "test" will be erased and | ||
# re-generated from your development database when you run "rake". | ||
# Do not set this db to the same as development or production. | ||
test: | ||
<<: *default | ||
database: storage/test.sqlite3 | ||
database: flextentions_test | ||
|
||
staging: | ||
adapter: postgresql | ||
pool: 5 | ||
timeout: 5000 | ||
database: flextentions_stage | ||
|
||
# MAKE SURE THE ENVIRONMENT CONFIG IS SET UP FOR PROD | ||
production: | ||
<<: *default | ||
database: storage/production.sqlite3 | ||
adapter: postgresql | ||
pool: 5 | ||
timeout: 5000 | ||
database: flextentions_prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# This file is auto-generated from the current state of the database. Instead | ||
# of editing this file, please use the migrations feature of Active Record to | ||
# incrementally modify your database, and then regenerate this schema definition. | ||
# | ||
# This file is the source Rails uses to define your schema when running `bin/rails | ||
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to | ||
# be faster and is potentially less error prone than running all of your | ||
# migrations from scratch. Old migrations may fail to apply correctly if those | ||
# migrations use external dependencies or application code. | ||
# | ||
# It's strongly recommended that you check this file into your version control system. | ||
|
||
ActiveRecord::Schema[7.1].define(version: 0) do | ||
# These are extensions that must be enabled in order to support this database | ||
enable_extension "plpgsql" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "flextensions", | ||
"version": "1.0.0", | ||
"description": "Back end/API for UC Berkeley EECS \"Flextensions\" software", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"scripts": { | ||
"dev": "bin/overmind s -f Procfile.dev" | ||
}, | ||
"author": "CS169l flextentions development team", | ||
"license": "BSD-2-Clause" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|