Skip to content

Commit a1a2f01

Browse files
committed
fix: solve database pooling issue
1 parent 444ef3b commit a1a2f01

12 files changed

Lines changed: 40 additions & 136 deletions

File tree

Dockerfile.dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WORKDIR /rails
55

66
RUN apt-get update -qq && \
77
apt-get install --no-install-recommends -y \
8-
build-essential curl git libyaml-dev pkg-config \
8+
build-essential curl git libyaml-dev pkg-config libpq-dev \
99
libsqlite3-dev libsqlite3-0 nodejs && \
1010
rm -rf /var/lib/apt/lists /var/cache/apt/archives
1111

@@ -18,4 +18,4 @@ RUN bundle install
1818
COPY . .
1919

2020
EXPOSE 3001
21-
CMD ["sh", "-c", "bin/rails db:migrate 2>/dev/null; bin/rails server -p 3001 -b 0.0.0.0"]
21+
CMD ["sh", "-c", "rm -f tmp/pids/server.pid && bin/rails db:prepare 2>/dev/null && bin/rails leaguepedia:bootstrap 2>/dev/null || true && bin/rails server -p 3001 -b 0.0.0.0"]

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ group :development do
4949
end
5050

5151
gem "sqlite3", ">= 2.1"
52+
gem "pg", "~> 1.5"
5253
gem "solid_queue", "~> 1.1"
5354

5455
gem "faraday", "~> 2.14"

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ GEM
201201
parser (3.3.10.2)
202202
ast (~> 2.4.1)
203203
racc
204+
pg (1.6.3)
205+
pg (1.6.3-aarch64-linux)
206+
pg (1.6.3-aarch64-linux-musl)
207+
pg (1.6.3-x86_64-linux)
208+
pg (1.6.3-x86_64-linux-musl)
204209
pp (0.6.3)
205210
prettyprint
206211
prettyprint (0.2.0)
@@ -379,6 +384,7 @@ DEPENDENCIES
379384
kamal
380385
meta-tags (~> 2.22)
381386
oj (~> 3.16)
387+
pg (~> 1.5)
382388
propshaft
383389
puma (>= 5.0)
384390
rails (~> 8.0.4)

app/models/leaguepedia_record.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class LeaguepediaRecord < ApplicationRecord
2+
self.abstract_class = true
3+
4+
if ActiveRecord::Base.configurations.find_db_config("leaguepedia")
5+
connects_to database: { writing: :leaguepedia, reading: :leaguepedia }
6+
end
7+
end

app/models/lp_champion_stat.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class LpChampionStat < ApplicationRecord
1+
class LpChampionStat < LeaguepediaRecord
22
scope :for_tournament, ->(t) { where(tournament: t) }
33

44
def as_leaguepedia_hash

app/models/lp_game.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class LpGame < ApplicationRecord
1+
class LpGame < LeaguepediaRecord
22
scope :for_tournament, ->(t) { where(tournament: t) }
33
scope :ordered, -> { order(:datetime_utc) }
44

app/models/lp_match.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class LpMatch < ApplicationRecord
1+
class LpMatch < LeaguepediaRecord
22
scope :for_overview, ->(page) { where(overview_page: page) }
33
scope :played, -> { where.not(winner: [ nil, "" ]) }
44
scope :upcoming, -> { where(winner: [ nil, "" ]) }

app/models/lp_player.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class LpPlayer < ApplicationRecord
1+
class LpPlayer < LeaguepediaRecord
22
scope :for_tournament, ->(t) { where(tournament: t) }
33
scope :for_player, ->(slug) { where(player_link: slug) }
44

config/database.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ development:
1010
queue:
1111
<<: *default
1212
database: storage/development.sqlite3
13+
<% if ENV["DATABASE_URL"].present? %>
14+
leaguepedia:
15+
adapter: postgresql
16+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
17+
url: <%= ENV["DATABASE_URL"] %>
18+
<% end %>
1319

1420
test:
1521
<<: *default
@@ -22,3 +28,9 @@ production:
2228
queue:
2329
<<: *default
2430
database: storage/production.sqlite3
31+
<% if ENV["DATABASE_URL"].present? %>
32+
leaguepedia:
33+
adapter: postgresql
34+
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
35+
url: <%= ENV["DATABASE_URL"] %>
36+
<% end %>

db/queue_schema.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@
218218
t.index ["key"], name: "index_solid_queue_semaphores_on_key", unique: true
219219
end
220220

221-
add_foreign_key "solid_queue_blocked_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
222221
add_foreign_key "solid_queue_claimed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
223222
add_foreign_key "solid_queue_failed_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade
224223
add_foreign_key "solid_queue_ready_executions", "solid_queue_jobs", column: "job_id", on_delete: :cascade

0 commit comments

Comments
 (0)