Skip to content

Commit 2696009

Browse files
committed
fix: solve database pooling and matches stats
1 parent a33b3e8 commit 2696009

3 files changed

Lines changed: 115 additions & 4 deletions

File tree

config/database.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ development:
1010
queue:
1111
<<: *default
1212
database: storage/development.sqlite3
13-
<% if ENV["DATABASE_URL"].present? %>
13+
<% if ENV["LEAGUEPEDIA_DATABASE_URL"].present? %>
1414
leaguepedia:
1515
adapter: postgresql
1616
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
17-
url: <%= ENV["DATABASE_URL"] %>
17+
url: <%= ENV["LEAGUEPEDIA_DATABASE_URL"] %>
1818
<% end %>
1919

2020
test:
@@ -28,9 +28,9 @@ production:
2828
queue:
2929
<<: *default
3030
database: storage/production.sqlite3
31-
<% if ENV["DATABASE_URL"].present? %>
31+
<% if ENV["LEAGUEPEDIA_DATABASE_URL"].present? %>
3232
leaguepedia:
3333
adapter: postgresql
3434
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
35-
url: <%= ENV["DATABASE_URL"] %>
35+
url: <%= ENV["LEAGUEPEDIA_DATABASE_URL"] %>
3636
<% end %>

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ services:
44
context: .
55
dockerfile: Dockerfile.dev
66
image: kings_lendas_dev
7+
env_file: .env
78
environment:
89
RAILS_ENV: development
910
RAILS_MASTER_KEY: ${RAILS_MASTER_KEY}
@@ -17,6 +18,7 @@ services:
1718
worker:
1819
image: kings_lendas_dev
1920
command: bin/jobs
21+
env_file: .env
2022
environment:
2123
RAILS_ENV: development
2224
RAILS_MASTER_KEY: ${RAILS_MASTER_KEY}

lib/tasks/leaguepedia.rake

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,115 @@ namespace :leaguepedia do
188188
puts "Done."
189189
end
190190

191+
desc "Create lp_* tables in Supabase (leaguepedia DB) — idempotent"
192+
task setup_supabase: :environment do
193+
conn = LeaguepediaRecord.connection
194+
195+
unless conn.table_exists?(:lp_matches)
196+
conn.create_table :lp_matches do |t|
197+
t.string :overview_page, null: false
198+
t.string :team1
199+
t.string :team2
200+
t.string :datetime_utc
201+
t.integer :best_of
202+
t.string :winner
203+
t.integer :team1_score
204+
t.integer :team2_score
205+
t.integer :match_day
206+
t.string :phase
207+
t.timestamps
208+
end
209+
conn.add_index :lp_matches, :overview_page
210+
conn.add_index :lp_matches, :datetime_utc
211+
puts " created lp_matches"
212+
else
213+
puts " lp_matches already exists"
214+
end
215+
216+
unless conn.table_exists?(:lp_games)
217+
conn.create_table :lp_games do |t|
218+
t.string :unique_game, null: false
219+
t.string :tournament
220+
t.string :team1
221+
t.string :team2
222+
t.string :winner
223+
t.string :gamelength
224+
t.string :datetime_utc
225+
t.text :team1_picks
226+
t.text :team2_picks
227+
t.text :team1_bans
228+
t.text :team2_bans
229+
t.integer :team1_kills
230+
t.integer :team2_kills
231+
t.integer :team1_gold
232+
t.integer :team2_gold
233+
t.string :patch
234+
t.integer :team1_towers
235+
t.integer :team2_towers
236+
t.integer :team1_inhibitors
237+
t.integer :team2_inhibitors
238+
t.integer :team1_dragons
239+
t.integer :team2_dragons
240+
t.integer :team1_barons
241+
t.integer :team2_barons
242+
t.integer :team1_rift_heralds
243+
t.integer :team2_rift_heralds
244+
t.integer :team1_void_grubs
245+
t.integer :team2_void_grubs
246+
t.string :win_type
247+
t.timestamps
248+
end
249+
conn.add_index :lp_games, :unique_game, unique: true
250+
conn.add_index :lp_games, :tournament
251+
puts " created lp_games"
252+
else
253+
puts " lp_games already exists"
254+
end
255+
256+
unless conn.table_exists?(:lp_players)
257+
conn.create_table :lp_players do |t|
258+
t.string :unique_game, null: false
259+
t.string :tournament
260+
t.string :player_link
261+
t.string :champion
262+
t.integer :kills
263+
t.integer :deaths
264+
t.integer :assists
265+
t.integer :cs
266+
t.integer :gold
267+
t.integer :damage_to_champions
268+
t.string :team
269+
t.string :role
270+
t.string :side
271+
t.timestamps
272+
end
273+
conn.add_index :lp_players, [ :unique_game, :player_link ], unique: true
274+
conn.add_index :lp_players, :tournament
275+
conn.add_index :lp_players, :player_link
276+
puts " created lp_players"
277+
else
278+
puts " lp_players already exists"
279+
end
280+
281+
unless conn.table_exists?(:lp_champion_stats)
282+
conn.create_table :lp_champion_stats do |t|
283+
t.string :tournament, null: false
284+
t.string :champion, null: false
285+
t.integer :picks, default: 0
286+
t.integer :bans, default: 0
287+
t.integer :wins, default: 0
288+
t.integer :games, default: 0
289+
t.timestamps
290+
end
291+
conn.add_index :lp_champion_stats, [ :tournament, :champion ], unique: true
292+
puts " created lp_champion_stats"
293+
else
294+
puts " lp_champion_stats already exists"
295+
end
296+
297+
puts "Supabase setup complete."
298+
end
299+
191300
desc "Show current DB counts"
192301
task status: :environment do
193302
puts "DB Status:"

0 commit comments

Comments
 (0)