active_storage_db 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc9d5bd1bf2f6b199a9632ad1f7927074de7613d9170c318f82a6c79b270c862
|
4
|
+
data.tar.gz: fa1e168bff6d46c650c71ea64316c7c31e64c9a3061746f50004c6738b3eda7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25faf4f5a9ca098017364f5f73b2a1208972382e08bce0e3ea578f80e922526642d385d6e6deb6e5902262deda0508afbf95ef6405a6b4cedc2d8801979426a2
|
7
|
+
data.tar.gz: 582eda7e799f912d955f18d99213ed9dc7d80a060329732817e6696812562e0c2e103b1624bddbf6b967d7b66252de4c23b4423a85fdcfea50cdcc963f010664
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
[](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_71.yml)
|
9
9
|
[](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_mysql_71.yml)
|
10
10
|
|
11
|
-
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database. Experimental support also for MSSQL.
|
11
|
+
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database. Experimental support also for MSSQL and SQLite.
|
12
12
|
|
13
13
|
Main features:
|
14
14
|
- attachment data stored in a binary field (or blob);
|
@@ -26,11 +26,36 @@ Useful also with platforms like Heroku (due to their ephemeral file system).
|
|
26
26
|
- Change Active Storage service in *config/environments/development.rb* to: `config.active_storage.service = :db`
|
27
27
|
- Add to *config/storage.yml*:
|
28
28
|
|
29
|
-
```
|
29
|
+
```yml
|
30
30
|
db:
|
31
31
|
service: DB
|
32
32
|
```
|
33
33
|
|
34
|
+
### Customizations
|
35
|
+
|
36
|
+
To setup a separate database connection for the `ActiveStorageDB` migrations and files data:
|
37
|
+
|
38
|
+
1. Add a different database configuration per environment to `config/database.yml`, e.g:
|
39
|
+
|
40
|
+
```yml
|
41
|
+
attachments:
|
42
|
+
database: attachments
|
43
|
+
migrations_paths: config/attachments_migrate
|
44
|
+
# other connection details ...
|
45
|
+
```
|
46
|
+
|
47
|
+
2. Extend the ActiveStorage base record class providing the `connects_to` options (updating _config/application.rb_ / using an initializer for _ActiveStorageDB_ / overriding the base model like in the [Rails guide](https://guides.rubyonrails.org/engines.html#overriding-models-and-controllers)):
|
48
|
+
|
49
|
+
```rb
|
50
|
+
# e.g. app/overrides/models/active_storage_db/application_record_override.rb
|
51
|
+
ActiveStorageDB::ApplicationRecord.class_eval do
|
52
|
+
connects_to database: { reading: :attachments, writing: :attachments }
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
3. Move the _ActiveStorageDB_ migrations to the specified migrations path
|
57
|
+
4. Execute the _rails db:migrate_ task
|
58
|
+
|
34
59
|
## Misc
|
35
60
|
|
36
61
|
Some utility tasks are available:
|
@@ -50,9 +75,9 @@ If you use this component just star it. A developer is more motivated to improve
|
|
50
75
|
|
51
76
|
Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
|
52
77
|
|
53
|
-
##
|
78
|
+
## Development
|
54
79
|
|
55
|
-
- [Mattia Roccoberton](https://blocknot.es/)
|
80
|
+
- Author: [Mattia Roccoberton](https://blocknot.es/)
|
56
81
|
- Inspired by [activestorage-database-service](https://github.com/TitovDigital/activestorage-database-service) project
|
57
82
|
|
58
83
|
## License
|
@@ -47,7 +47,7 @@ module ActiveStorage
|
|
47
47
|
instrument :download_chunk, key: key, range: range do
|
48
48
|
from = range.begin + 1
|
49
49
|
size = range.size
|
50
|
-
args = adapter_sqlserver? ? "data, #{from}, #{size}" : "data FROM #{from} FOR #{size}"
|
50
|
+
args = adapter_sqlserver? || adapter_sqlite? ? "data, #{from}, #{size}" : "data FROM #{from} FOR #{size}"
|
51
51
|
record = object_for(key, fields: "SUBSTRING(#{args}) AS chunk")
|
52
52
|
raise(ActiveStorage::FileNotFoundError) unless record
|
53
53
|
|
@@ -102,6 +102,10 @@ module ActiveStorage
|
|
102
102
|
|
103
103
|
private
|
104
104
|
|
105
|
+
def adapter_sqlite?
|
106
|
+
@adapter_sqlite ||= ActiveStorageDB::File.connection.adapter_name == 'SQLite'
|
107
|
+
end
|
108
|
+
|
105
109
|
def adapter_sqlserver?
|
106
110
|
@adapter_sqlserver ||= ActiveStorageDB::File.connection.adapter_name == 'SQLServer'
|
107
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_storage_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mattia Roccoberton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.5.22
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: ActiveStorage DB Service
|