Skip to content

Commit 5e07038

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 e8c29f8 commit 5e07038

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
@@ -16,7 +16,7 @@ default: &default
1616
development:
1717
primary:
1818
<<: *default
19-
database: storage/development/data.sqlite3
19+
database: storage/development/data-<%= (`git branch --show-current`.chomp || 'default').parameterize %>.sqlite3
2020
pragmas:
2121
mmap_size: <%= 128 * 1024 * 1024 %> # 128MB
2222
cache:

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)