diff --git a/Gemfile b/Gemfile index af734b8..dbfc94a 100644 --- a/Gemfile +++ b/Gemfile @@ -8,8 +8,8 @@ gem "rails", "~> 7.1.3" # The original asset pipeline for Rails [https://github.com/rails/sprockets-rails] gem "sprockets-rails" -# Use sqlite3 as the database for Active Record -gem "sqlite3", "~> 1.4" +# Use postgres for all env dbs +gem "pg" # Use the Puma web server [https://github.com/puma/puma] gem "puma", ">= 5.0" @@ -85,4 +85,3 @@ group :development do # Speed up commands on slow machines / big apps [https://github.com/rails/spring] # gem "spring" end - diff --git a/Gemfile.lock b/Gemfile.lock index 17fa45e..5eca2d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -205,7 +205,6 @@ GEM matrix (0.4.2) method_source (1.0.0) mini_mime (1.1.5) - mini_portile2 (2.8.5) minitest (5.22.2) msgpack (1.7.2) multi_test (1.1.0) @@ -239,6 +238,8 @@ GEM notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) + pg (1.5.5) + pg (1.5.5-x86-mingw32) popper_js (2.11.8) pry (0.14.2) coderay (~> 1.1) @@ -339,14 +340,6 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.7.2) - mini_portile2 (~> 2.8.0) - sqlite3 (1.7.2-aarch64-linux) - sqlite3 (1.7.2-arm-linux) - sqlite3 (1.7.2-arm64-darwin) - sqlite3 (1.7.2-x86-linux) - sqlite3 (1.7.2-x86_64-darwin) - sqlite3 (1.7.2-x86_64-linux) stimulus-rails (1.3.3) railties (>= 6.0.0) stringio (3.1.0) @@ -398,13 +391,13 @@ DEPENDENCIES jbuilder jquery-rails lms-api + pg puma (>= 5.0) rails (~> 7.1.3) rspec-rails sassc-rails (~> 2.1) simplecov sprockets-rails - sqlite3 (~> 1.4) stimulus-rails turbo-rails tzinfo-data diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3089d14 --- /dev/null +++ b/Makefile @@ -0,0 +1,26 @@ +# 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 + @command -v overmind > /dev/null 2>&1 || { echo >&2 "please install overmind first"; exit 1; } + @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 diff --git a/Procfile.dev b/Procfile.dev new file mode 100644 index 0000000..f6a9573 --- /dev/null +++ b/Procfile.dev @@ -0,0 +1 @@ +web: bundle exec rails s -p 3000 diff --git a/README.md b/README.md index 6bb9bc4..ee17fbf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,42 @@ -# flextensions +# 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) \ No newline at end of file +[![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 you must first install [Overmind](https://github.com/DarthSim/overmind). + Development has been tested with overmind 2.4.0 + +With Overmind, you can run `$make dev` or `$make` diff --git a/config/database.yml b/config/database.yml index 796466b..660574a 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 1b4bd96..f913998 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,5 +10,8 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_02_20_081032) do +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 diff --git a/package.json b/package.json new file mode 100644 index 0000000..24f1016 --- /dev/null +++ b/package.json @@ -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": "overmind s -f Procfile.dev" + }, + "author": "CS169l flextentions development team", + "license": "BSD-2-Clause" +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + +