Skip to content

Commit 37cd008

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 b078e19 commit 37cd008

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
@@ -14,7 +14,7 @@ default: &default
1414
development:
1515
primary:
1616
<<: *default
17-
database: storage/development/data.sqlite3
17+
database: storage/development/data-<%= (`git branch --show-current`.chomp || 'default').parameterize %>.sqlite3
1818
cache:
1919
<<: *default
2020
database: storage/development/cache.sqlite3

config/environments/development.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,10 @@
9999
else
100100
"POSTMARK_API_TEST"
101101
end
102+
103+
# With branch-specific databases for development defined in config/database.yml
104+
# we need to prepare the databases before starting the server
105+
config.after_initialize do
106+
ActiveRecord::Tasks::DatabaseTasks.prepare_all
107+
end
102108
end

0 commit comments

Comments
 (0)