I might eventually turn this into a template but for now just keeping notes for myself

On Github: Create Github repo, do NOT initialize with README, get ssh for project. (git@github.com:harrisjb/<project-name>.git)

On my machine:

rails new <project-name> --api --database=postgresql

git remote add origin git@github.com:harrisjb/<project-name>.git

Create DB: rails db:create

Gems:

#Authorization 
gem 'jwt'

#RBAC/ABAC
gem 'pundit'

#CORS permissions
gem 'rack-cors'

#JSON API serialization
gem 'fast_jsonapi'

# Jobs:
gem 'sidekiq'
gem 'redis-namespace'

#Utils
gem 'aws-sdk'
gem 'dotenv-rails'
gem 'faker' #generate test data

#exception monitoring
# gem 'sentry-raven' #free to start
# gem 'honeybadger' #costs $59/mo
gem 'bugsnag' #free

#payments with stripe
#omniauth to allow vendors to connect
gem 'stripe'
gem 'omniauth'
gem 'omniauth-stripe-connect'

group :development do
  gem 'letter_opener' #local emails
  gem 'bullet' # n+1 query notification
end

group :development, :test do
  gem 'awesome_print'
end

bundle install

Create PSQL user, role

create role <project-name> with superuser createdb login;

grant all privileges on database "<project-name>_development" to <psql-user>;

ALTER ROLE <psql-user> WITH PASSWORD '<password>';

Edit config/database.yml to use new user, add actual values to .env

development:
  <<: *default
  database: <%= ENV['database_name'] %>
  pool: 5
  username: <%= ENV['database_username'] %>
  password: <%= ENV['database_password'] %>
  host: <%= ENV['database_url'] %>
  port: <%= ENV['database_port'] %>
  reaping_frequency: 10

Add dotenv-rails to config/application.rb:require "dotenv/load"

Load console to confirm db connection:rails c (if it hangs try bin/spring stop and try again.

Create a User model:rails g model User username full_name email password_digest first_name last_name superadmin stripe_customer_id referral_code guid auth_token auth_token_created_at auth_token_expires_at challenge_token challenge_token_expires_at

Edit migration for some types and defaults i.e. change superadmin to boolean not string and default to false t.boolean :superadmin, default: false

Create a Payments model rails g model Payment stripe_confirmation_id amount paid_at refunded_at payment_type payment_purpose order_id

rails db:migrate

git push -u origin master

aws eb deploy (NOTES ON ELASTIC BEANSTALK DEPLOYMENT IN FUTURE POST)

Links:

https://www.pluralsight.com/guides/token-based-authentication-with-ruby-on-rails-5-apihttps://github.com/binarylogic/authlogic

https://github.com/bkeepers/dotenv

https://github.com/varvet/pundit