Skip to content

Commit 9e0157f

Browse files
authored
Merge pull request #52 from kejkz/use-separate-db
feat: Add alternative database support
2 parents 5bf4376 + 9871af5 commit 9e0157f

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,35 @@ Useful also with platforms like Heroku (due to their ephemeral file system).
2626
- Change Active Storage service in *config/environments/development.rb* to: `config.active_storage.service = :db`
2727
- Add to *config/storage.yml*:
2828

29-
```
29+
```yml
3030
db:
3131
service: DB
3232
```
3333
34+
If there is a need to support a separate database connection for storing the `ActiveStorageDB` files:
35+
36+
1. Add a separate database configuration for the environment (this one is just an example)
37+
38+
```yml
39+
attachments:
40+
database: attachments
41+
pool: 5
42+
username: root
43+
migrations_paths: config/attachments_migrate
44+
```
45+
46+
2. Create a separate initializer file in `config/initializera/active_storage_db.rb` to set the database:
47+
48+
```rb
49+
# app/overrides/models/active_storage_db/application_record_override.rb
50+
ActiveStorageDB::ApplicationRecord.class_eval do
51+
connects_to database: { reading: :attachments, writing: :attachments }
52+
end
53+
```
54+
55+
3. Move the `ActiveStorageDB` related migrations to a configured storage migrations path
56+
4. Create the database and execute the migrations
57+
3458
## Misc
3559

3660
Some utility tasks are available:

0 commit comments

Comments
 (0)