Skip to content

Commit de404b5

Browse files
committed
Support branch specific databases for dev
Following instruction from fractaledmind in this post: https://fractaledmind.github.io/2023/09/06/enhancing-rails-sqlite-branch-databases/ I‘m only adding this feature for development of the primary data store. I don‘t anticipate cache, queue, and cable databases needing to change often so leaving them out of branch-specific support for the time being.
1 parent c3a3423 commit de404b5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ default: &default
1515
development:
1616
primary:
1717
<<: *default
18-
database: storage/development/data.sqlite3
18+
database: storage/development/data-<%= (`git branch --show-current`.chomp || 'default').parameterize %>.sqlite3
1919
cache:
2020
<<: *default
2121
database: storage/development/cache.sqlite3

config/environments/development.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,10 @@
9292
config.solid_queue.connects_to = {database: {writing: :queue, reading: :queue}}
9393

9494
config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "debug")
95+
96+
# With branch-specific databases for development defined in config/database.yml
97+
# we need to prepare the databases before starting the server
98+
config.after_initialize do
99+
ActiveRecord::Tasks::DatabaseTasks.prepare_all
100+
end
95101
end

0 commit comments

Comments
 (0)