active_storage_db 1.1.2 → 1.3.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 +4 -4
- data/README.md +5 -5
- data/lib/active_storage/service/db_service.rb +12 -2
- data/lib/active_storage_db/version.rb +1 -1
- data/lib/tasks/active_storage_db_tasks.rake +9 -9
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9903d366094ded799bb376d3fb568b9195a6bf4390ae7ae16b6ed7b21451d7a
|
4
|
+
data.tar.gz: b18c7ec5b77ce9d5dbf97b8af37d9d2fc9954702772f540b4ef77f8762cf0a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25c3f9aeb95587dd6ecfdc51486f8f53848f6c154a8f4141d6baa63b06b4bafd3fa4bd42a026ecd82c972f775eb86f9de2d91c65380c9ba554866b1c41de5bc1
|
7
|
+
data.tar.gz: 1bffc3ecaaa58f9a082d71a8eafb36d07db806142fae8b399dbcd0cc1b879d278cc4cc8865e76aee3bede4c1bf2457f14b449b069926560260bfa75d3c02efae
|
data/README.md
CHANGED
@@ -5,15 +5,15 @@
|
|
5
5
|
[](https://codeclimate.com/github/blocknotes/active_storage_db/maintainability)
|
6
6
|
|
7
7
|
[](https://github.com/blocknotes/active_storage_db/actions/workflows/linters.yml)
|
8
|
-
[](https://github.com/blocknotes/active_storage_db/actions/workflows/specs_postgres_71.yml)
|
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.
|
11
|
+
An Active Storage service upload/download plugin that stores files in a PostgreSQL or MySQL database. Experimental support also for MSSQL.
|
12
12
|
|
13
13
|
Main features:
|
14
|
-
-
|
14
|
+
- attachment data stored in a binary field (or blob);
|
15
15
|
- all service methods implemented;
|
16
|
-
-
|
16
|
+
- supports Rails _6_ and _7_.
|
17
17
|
|
18
18
|
Useful also with platforms like Heroku (due to their ephemeral file system).
|
19
19
|
|
@@ -8,6 +8,7 @@ module ActiveStorage
|
|
8
8
|
# Wraps a DB table as an Active Storage service. See ActiveStorage::Service
|
9
9
|
# for the generic API documentation that applies to all services.
|
10
10
|
class Service::DBService < Service
|
11
|
+
# :nocov:
|
11
12
|
if Rails::VERSION::MAJOR >= 7
|
12
13
|
include ActiveStorage::DBServiceRails70
|
13
14
|
elsif Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR == 1
|
@@ -15,6 +16,7 @@ module ActiveStorage
|
|
15
16
|
else
|
16
17
|
include ActiveStorage::DBServiceRails60
|
17
18
|
end
|
19
|
+
# :nocov:
|
18
20
|
|
19
21
|
def initialize(public: false, **)
|
20
22
|
@chunk_size = ENV.fetch('ASDB_CHUNK_SIZE') { 1.megabytes }
|
@@ -43,7 +45,10 @@ module ActiveStorage
|
|
43
45
|
|
44
46
|
def download_chunk(key, range)
|
45
47
|
instrument :download_chunk, key: key, range: range do
|
46
|
-
|
48
|
+
from = range.begin + 1
|
49
|
+
size = range.size
|
50
|
+
args = adapter_sqlserver? ? "data, #{from}, #{size}" : "data FROM #{from} FOR #{size}"
|
51
|
+
record = object_for(key, fields: "SUBSTRING(#{args}) AS chunk")
|
47
52
|
raise(ActiveStorage::FileNotFoundError) unless record
|
48
53
|
|
49
54
|
record.chunk
|
@@ -97,6 +102,10 @@ module ActiveStorage
|
|
97
102
|
|
98
103
|
private
|
99
104
|
|
105
|
+
def adapter_sqlserver?
|
106
|
+
@adapter_sqlserver ||= ActiveStorageDB::File.connection.adapter_name == 'SQLServer'
|
107
|
+
end
|
108
|
+
|
100
109
|
def generate_url(key, expires_in:, filename:, content_type:, disposition:)
|
101
110
|
content_disposition = content_disposition_with(type: disposition, filename: filename)
|
102
111
|
verified_key_with_expiration = ActiveStorage.verifier.generate(
|
@@ -142,7 +151,8 @@ module ActiveStorage
|
|
142
151
|
end
|
143
152
|
|
144
153
|
def stream(key)
|
145
|
-
|
154
|
+
data_size = adapter_sqlserver? ? 'DATALENGTH(data)' : 'OCTET_LENGTH(data)'
|
155
|
+
size = object_for(key, fields: "#{data_size} AS size")&.size || raise(ActiveStorage::FileNotFoundError)
|
146
156
|
(size / @chunk_size.to_f).ceil.times.each do |i|
|
147
157
|
range = (i * @chunk_size..((i + 1) * @chunk_size) - 1)
|
148
158
|
yield download_chunk(key, range)
|
@@ -19,12 +19,12 @@ end
|
|
19
19
|
namespace :asdb do
|
20
20
|
desc 'ActiveStorageDB: list attachments ordered by blob id desc'
|
21
21
|
task list: [:environment] do |_t, _args|
|
22
|
-
query =
|
23
|
-
digits =
|
22
|
+
query = ActiveStorage::Blob.order(id: :desc).limit(100)
|
23
|
+
digits = query.ids.inject(0) { |ret, id| size = id.to_s.size; [size, ret].max }
|
24
24
|
|
25
|
-
|
25
|
+
ActiveStorage::Tasks.print_blob_header(digits: digits)
|
26
26
|
query.each do |blob|
|
27
|
-
|
27
|
+
ActiveStorage::Tasks.print_blob(blob, digits: digits)
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -34,7 +34,7 @@ namespace :asdb do
|
|
34
34
|
destination = args[:destination]&.strip || Dir.pwd
|
35
35
|
abort('Required arguments: source blob id, destination path') if blob_id.blank? || destination.blank?
|
36
36
|
|
37
|
-
blob =
|
37
|
+
blob = ActiveStorage::Blob.find_by(id: blob_id)
|
38
38
|
abort('Source file not found') unless blob
|
39
39
|
|
40
40
|
destination = "#{destination}/#{blob.filename}" if Dir.exist?(destination)
|
@@ -50,12 +50,12 @@ namespace :asdb do
|
|
50
50
|
filename = args[:filename]&.strip
|
51
51
|
abort('Required arguments: filename') if filename.blank?
|
52
52
|
|
53
|
-
blobs =
|
53
|
+
blobs = ActiveStorage::Blob.where('filename LIKE ?', "%#{filename}%").order(id: :desc)
|
54
54
|
if blobs.any?
|
55
|
-
digits =
|
56
|
-
|
55
|
+
digits = blobs.ids.inject(0) { |ret, id| size = id.to_s.size; [size, ret].max }
|
56
|
+
ActiveStorage::Tasks.print_blob_header(digits: digits)
|
57
57
|
blobs.each do |blob|
|
58
|
-
|
58
|
+
ActiveStorage::Tasks.print_blob(blob, digits: digits)
|
59
59
|
end
|
60
60
|
else
|
61
61
|
puts 'No results'
|
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.3.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: 2023-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activestorage
|
@@ -105,14 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
105
|
requirements:
|
106
106
|
- - ">="
|
107
107
|
- !ruby/object:Gem::Version
|
108
|
-
version: 2.
|
108
|
+
version: 2.7.0
|
109
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.4.21
|
116
116
|
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: ActiveStorage DB Service
|