Skip to content

Commit 8f70e30

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 cd61c2c commit 8f70e30

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
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
@@ -95,4 +95,10 @@
9595
else
9696
"POSTMARK_API_TEST"
9797
end
98+
99+
# With branch-specific databases for development defined in config/database.yml
100+
# we need to prepare the databases before starting the server
101+
config.after_initialize do
102+
ActiveRecord::Tasks::DatabaseTasks.prepare_all
103+
end
98104
end

db/cache_schema.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
t.integer "seq"
2020
end
2121

22-
# Could not dump table "data" because of following StandardError
23-
# Unknown type 'ANY' for column 'value'
24-
2522
create_table "solid_cache_entries", force: :cascade do |t|
2623
t.binary "key", limit: 1024, null: false
2724
t.binary "value", limit: 536870912, null: false

0 commit comments

Comments
 (0)