Skip to content

Commit bb4ddd7

Browse files
justin808claude
andauthored
Setup PostgreSQL and add React on Rails gems (#4)
## Summary - Configure Rails with PostgreSQL database - Add react_on_rails and shakapacker gems - Setup database structure for PostgreSQL ## Changes - Add .ruby-version file for Ruby 3.3.4 - Configure PostgreSQL with database.yml - Add pg, shakapacker, and react_on_rails gems - Update CI workflow for PostgreSQL - Add database structure (schema.rb, seeds.rb) - Add minimal shakapacker configuration ## Test plan - [x] PostgreSQL databases created successfully - [x] Database connection verified - [ ] CI tests pass with PostgreSQL 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <[email protected]>
1 parent a4e3880 commit bb4ddd7

File tree

8 files changed

+231
-57
lines changed

8 files changed

+231
-57
lines changed

.github/workflows/ci.yml

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,15 @@ jobs:
4040
test:
4141
runs-on: ubuntu-latest
4242

43-
# services:
44-
# redis:
45-
# image: redis
46-
# ports:
47-
# - 6379:6379
48-
# options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5
43+
services:
44+
postgres:
45+
image: postgres:14
46+
ports:
47+
- 5432:5432
48+
env:
49+
POSTGRES_USER: postgres
50+
POSTGRES_PASSWORD: postgres
51+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
4952
steps:
5053
- name: Install packages
5154
run: sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config
@@ -59,8 +62,14 @@ jobs:
5962
ruby-version: .ruby-version
6063
bundler-cache: true
6164

65+
- name: Setup test database
66+
env:
67+
RAILS_ENV: test
68+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test
69+
run: bin/rails db:create db:schema:load
70+
6271
- name: Run tests
6372
env:
6473
RAILS_ENV: test
65-
# REDIS_URL: redis://localhost:6379/0
66-
run: bin/rails db:test:prepare test
74+
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test
75+
run: bin/rails test

Gemfile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ source "https://rubygems.org"
22

33
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
44
gem "rails", "~> 8.0.3"
5-
# The modern asset pipeline for Rails [https://github.com/rails/propshaft]
6-
gem "propshaft"
5+
6+
# Use postgresql as the database for Active Record
7+
gem "pg", "~> 1.1"
8+
9+
# React on Rails and Shakapacker for webpack integration
10+
gem "shakapacker", "9.0.0.beta.3"
11+
gem "react_on_rails", "16.1.1"
12+
13+
# Remove propshaft since we'll use shakapacker
14+
# gem "propshaft"
715
# Use the Puma web server [https://github.com/puma/puma]
816
gem "puma", ">= 5.0"
917
# Build JSON APIs with ease [https://github.com/rails/jbuilder]
@@ -19,10 +27,10 @@ gem "tzinfo-data", platforms: %i[ windows jruby ]
1927
gem "bootsnap", require: false
2028

2129
# Deploy this application anywhere as a Docker container [https://kamal-deploy.org]
22-
gem "kamal", require: false
30+
# gem "kamal", require: false
2331

2432
# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/]
25-
gem "thruster", require: false
33+
# gem "thruster", require: false
2634

2735
group :development, :test do
2836
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem

Gemfile.lock

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ GEM
7272
securerandom (>= 0.3)
7373
tzinfo (~> 2.0, >= 2.0.5)
7474
uri (>= 0.13.1)
75+
addressable (2.8.7)
76+
public_suffix (>= 2.0.2, < 7.0)
7577
ast (2.4.3)
7678
base64 (0.3.0)
77-
bcrypt_pbkdf (1.1.1)
7879
benchmark (0.4.1)
7980
bigdecimal (3.2.3)
8081
bindex (0.8.1)
@@ -90,11 +91,10 @@ GEM
9091
debug (1.11.0)
9192
irb (~> 1.10)
9293
reline (>= 0.3.8)
93-
dotenv (3.1.8)
9494
drb (2.2.3)
95-
ed25519 (1.4.0)
9695
erb (5.0.2)
9796
erubi (1.13.1)
97+
execjs (2.10.0)
9898
globalid (1.3.0)
9999
activesupport (>= 6.1)
100100
i18n (1.14.7)
@@ -108,17 +108,6 @@ GEM
108108
actionview (>= 7.0.0)
109109
activesupport (>= 7.0.0)
110110
json (2.15.0)
111-
kamal (2.7.0)
112-
activesupport (>= 7.0)
113-
base64 (~> 0.2)
114-
bcrypt_pbkdf (~> 1.0)
115-
concurrent-ruby (~> 1.2)
116-
dotenv (~> 3.1)
117-
ed25519 (~> 1.4)
118-
net-ssh (~> 7.3)
119-
sshkit (>= 1.23.0, < 2.0)
120-
thor (~> 1.3)
121-
zeitwerk (>= 2.6.18, < 3.0)
122111
language_server-protocol (3.17.0.5)
123112
lint_roller (1.1.0)
124113
logger (1.7.0)
@@ -141,13 +130,8 @@ GEM
141130
net-protocol
142131
net-protocol (0.2.2)
143132
timeout
144-
net-scp (4.1.0)
145-
net-ssh (>= 2.6.5, < 8.0.0)
146-
net-sftp (4.0.0)
147-
net-ssh (>= 5.0.0, < 8.0.0)
148133
net-smtp (0.5.1)
149134
net-protocol
150-
net-ssh (7.3.0)
151135
nio4r (2.7.4)
152136
nokogiri (1.18.10-aarch64-linux-gnu)
153137
racc (~> 1.4)
@@ -163,26 +147,31 @@ GEM
163147
racc (~> 1.4)
164148
nokogiri (1.18.10-x86_64-linux-musl)
165149
racc (~> 1.4)
166-
ostruct (0.6.3)
150+
package_json (0.1.0)
167151
parallel (1.27.0)
168152
parser (3.3.9.0)
169153
ast (~> 2.4.1)
170154
racc
155+
pg (1.6.2)
156+
pg (1.6.2-aarch64-linux)
157+
pg (1.6.2-aarch64-linux-musl)
158+
pg (1.6.2-arm64-darwin)
159+
pg (1.6.2-x86_64-linux)
160+
pg (1.6.2-x86_64-linux-musl)
171161
pp (0.6.2)
172162
prettyprint
173163
prettyprint (0.2.0)
174164
prism (1.5.1)
175-
propshaft (1.3.1)
176-
actionpack (>= 7.0.0)
177-
activesupport (>= 7.0.0)
178-
rack
179165
psych (5.2.6)
180166
date
181167
stringio
168+
public_suffix (6.0.2)
182169
puma (7.0.4)
183170
nio4r (~> 2.0)
184171
racc (1.8.1)
185172
rack (3.2.1)
173+
rack-proxy (0.7.7)
174+
rack
186175
rack-session (2.1.1)
187176
base64 (>= 0.1.0)
188177
rack (>= 3.0.0)
@@ -225,6 +214,13 @@ GEM
225214
rdoc (6.14.2)
226215
erb
227216
psych (>= 4.0.0)
217+
react_on_rails (16.1.1)
218+
addressable
219+
connection_pool
220+
execjs (~> 2.5)
221+
rails (>= 5.2)
222+
rainbow (~> 3.0)
223+
shakapacker (>= 6.0)
228224
regexp_parser (2.11.3)
229225
reline (0.6.2)
230226
io-console (~> 0.5)
@@ -258,19 +254,15 @@ GEM
258254
rubocop-rails (>= 2.30)
259255
ruby-progressbar (1.13.0)
260256
securerandom (0.4.1)
261-
sshkit (1.24.0)
262-
base64
263-
logger
264-
net-scp (>= 1.1.2)
265-
net-sftp (>= 2.1.2)
266-
net-ssh (>= 2.8.0)
267-
ostruct
257+
semantic_range (3.1.0)
258+
shakapacker (9.0.0.beta.3)
259+
activesupport (>= 5.2)
260+
package_json
261+
rack-proxy (>= 0.6.1)
262+
railties (>= 5.2)
263+
semantic_range (>= 2.3.0)
268264
stringio (3.1.7)
269265
thor (1.4.0)
270-
thruster (0.1.15)
271-
thruster (0.1.15-aarch64-linux)
272-
thruster (0.1.15-arm64-darwin)
273-
thruster (0.1.15-x86_64-linux)
274266
timeout (0.4.3)
275267
tsort (0.2.0)
276268
tzinfo (2.0.6)
@@ -307,12 +299,12 @@ DEPENDENCIES
307299
brakeman
308300
debug
309301
jbuilder
310-
kamal
311-
propshaft
302+
pg (~> 1.1)
312303
puma (>= 5.0)
313304
rails (~> 8.0.3)
305+
react_on_rails (= 16.1.1)
314306
rubocop-rails-omakase
315-
thruster
307+
shakapacker (= 9.0.0.beta.3)
316308
tzinfo-data
317309
web-console
318310

config/database.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# PostgreSQL. Versions 9.3 and up are supported.
2+
#
3+
# Install the pg driver:
4+
# gem install pg
5+
# On macOS with Homebrew:
6+
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
7+
# On Windows:
8+
# gem install pg
9+
# Choose the win32 build.
10+
# Install PostgreSQL and put its /bin directory on your path.
11+
#
12+
# Configure Using Gemfile
13+
# gem "pg"
14+
#
15+
default: &default
16+
adapter: postgresql
17+
encoding: unicode
18+
# For details on connection pooling, see Rails configuration guide
19+
# https://guides.rubyonrails.org/configuring.html#database-pooling
20+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
21+
22+
development:
23+
<<: *default
24+
database: react_on_rails_v16_generator_playground_development
25+
26+
# The specified database role being used to connect to PostgreSQL.
27+
# To create additional roles in PostgreSQL see `$ createuser --help`.
28+
# When left blank, PostgreSQL will use the default role. This is
29+
# the same name as the operating system user running Rails.
30+
#username: react_on_rails_v16_generator_playground
31+
32+
# The password associated with the PostgreSQL role (username).
33+
#password:
34+
35+
# Connect on a TCP socket. Omitted by default since the client uses a
36+
# domain socket that doesn't need configuration. Windows does not have
37+
# domain sockets, so uncomment these lines.
38+
#host: localhost
39+
40+
# The TCP port the server listens on. Defaults to 5432.
41+
# If your server runs on a different port number, change accordingly.
42+
#port: 5432
43+
44+
# Schema search path. The server defaults to $user,public
45+
#schema_search_path: myapp,sharedapp,public
46+
47+
# Minimum log levels, in increasing order:
48+
# debug5, debug4, debug3, debug2, debug1,
49+
# log, notice, warning, error, fatal, and panic
50+
# Defaults to warning.
51+
#min_messages: notice
52+
53+
# Warning: The database defined as "test" will be erased and
54+
# re-generated from your development database when you run "rake".
55+
# Do not set this db to the same as development or production.
56+
test:
57+
<<: *default
58+
database: react_on_rails_v16_generator_playground_test
59+
60+
# As with config/credentials.yml, you never want to store sensitive information,
61+
# like your database password, in your source code. If your source code is
62+
# ever seen by anyone, they now have access to your database.
63+
#
64+
# Instead, provide the password or a full connection URL as an environment
65+
# variable when you boot the app. For example:
66+
#
67+
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
68+
#
69+
# If the connection URL is provided in the special DATABASE_URL environment
70+
# variable, Rails will automatically merge its configuration values on top of
71+
# the values provided in this file. Alternatively, you can specify a connection
72+
# URL environment variable explicitly:
73+
#
74+
# production:
75+
# url: <%= ENV["MY_APP_DATABASE_URL"] %>
76+
#
77+
# Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
78+
# for a full overview on how database connection configuration can be specified.
79+
#
80+
production:
81+
<<: *default
82+
database: react_on_rails_v16_generator_playground_production
83+
username: react_on_rails_v16_generator_playground
84+
password: <%= ENV["REACT_ON_RAILS_V16_GENERATOR_PLAYGROUND_DATABASE_PASSWORD"] %>

config/initializers/assets.rb

Lines changed: 0 additions & 7 deletions
This file was deleted.

config/shakapacker.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Note: You must restart bin/shakapacker-dev-server for changes to take effect
2+
3+
default: &default
4+
source_path: app/javascript
5+
source_entry_path: packs
6+
public_root_path: public
7+
public_output_path: packs
8+
cache_path: tmp/shakapacker
9+
webpack_compile_output: true
10+
11+
# Additional paths webpack should look up modules
12+
# ['app/assets', 'engine/foo/app/assets']
13+
additional_paths: []
14+
15+
# Reload manifest.json on all requests so we reload latest compiled packs
16+
cache_manifest: false
17+
18+
development:
19+
<<: *default
20+
compile: true
21+
22+
# Reference: https://webpack.js.org/configuration/dev-server/
23+
dev_server:
24+
host: localhost
25+
port: 3035
26+
# Hot Module Replacement updates modules while the application is running without a full reload
27+
hmr: false
28+
# If HMR is on, CSS will by inlined by delivering it as part of the JS payload via style-loader. Be sure to add Mini Css Extract Plugin to your webpack config if hmr is false.
29+
inline_css: true
30+
client:
31+
overlay: true
32+
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
33+
compress: true
34+
# Should we use gzip compression?
35+
allowed_hosts: "all"
36+
# Specifies allowedHosts for webpack-dev-server (useful for use with ngrok). Accepts a string value or an array of strings
37+
pretty: true
38+
# Shows progress and colorizes output of webpack compilation
39+
headers:
40+
'Access-Control-Allow-Origin': '*'
41+
static:
42+
watch:
43+
ignored: '**/node_modules/**'
44+
45+
test:
46+
<<: *default
47+
compile: true
48+
49+
# Compile test packs to a separate directory
50+
public_output_path: packs-test
51+
52+
production:
53+
<<: *default
54+
55+
# Production depends on precompilation of packs prior to booting for performance.
56+
compile: false
57+
58+
# Cache manifest.json for performance
59+
cache_manifest: true
60+
61+
# Compile packages for SSR
62+
server_rendering: true

db/schema.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file is auto-generated from the current state of the database. Instead
2+
# of editing this file, please use the migrations feature of Active Record to
3+
# incrementally modify your database, and then regenerate this schema definition.
4+
#
5+
# This file is the source Rails uses to define your schema when running `bin/rails
6+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
7+
# be faster and is potentially less error prone than running all of your
8+
# migrations from scratch. Old migrations may fail to apply correctly if those
9+
# migrations use external dependencies or application code.
10+
#
11+
# It's strongly recommended that you check this file into your version control system.
12+
13+
ActiveRecord::Schema[8.0].define(version: 0) do
14+
# These are extensions that must be enabled in order to support this database
15+
enable_extension "plpgsql"
16+
17+
end

0 commit comments

Comments
 (0)