activerecord-cipherstash-pg-adapter 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/active_record/connection_adapters/cipherstash_pg/cipherstash_tasks.rake +34 -0
- data/lib/active_record/connection_adapters/cipherstash_pg/database_extensions.rb +3 -1
- data/lib/active_record/connection_adapters/cipherstash_pg/database_tasks.rb +4 -2
- data/lib/activerecord-cipherstash-pg-adapter.rb +17 -23
- data/lib/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 17eaea76f767bfda72f26bd7c9d89a4e8e0333dfc19be95a5390cbb8b0cbfc44
|
4
|
+
data.tar.gz: 379044af26990eb20e563e9aaa0bf727fcb5e70ac63ec89afa86e648d8882d3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b25b5b4ef6ad537cb9ec045458553566b743b9739b3c0c863d41d28dc78316e9f557904c55d6145789bcf85b7bb15c9d42f5a81cb8b411471f4516274763e37d
|
7
|
+
data.tar.gz: be6d02946c7e8df400dc68d13bc614fd28a3787dea5b9317e8d4e86773097f2a22f7ced6dd5ca3b6fe58f8bfb8fdd041f64fbc0453bae3e9ad2bc89d87a2ffa2
|
data/README.md
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "logger"
|
3
|
+
|
4
|
+
namespace :cipherstash do
|
5
|
+
desc "Re-saves a model to migrate it when its config is set to encrypted-duplicate."
|
6
|
+
task :migrate, [:model_name, :batch_size] => "db:load_config" do |_task, args|
|
7
|
+
model_name = args[:model_name]
|
8
|
+
batch_size = args[:batch_size] || 1000
|
9
|
+
|
10
|
+
if model_name.nil?
|
11
|
+
abort "Please provide a model name, eg. rake cipherstash:migrate[User]"
|
12
|
+
end
|
13
|
+
model = Object.const_get(model_name) # raises NameError on failure
|
14
|
+
|
15
|
+
unless model < ActiveRecord::Base
|
16
|
+
abort "Not an ActiveRecord model: #{model_name}"
|
17
|
+
end
|
18
|
+
|
19
|
+
logger = Logger.new(STDOUT)
|
20
|
+
logger.info "Migrating #{model_name} in batches of #{batch_size}."
|
21
|
+
|
22
|
+
primary_keys = Array(model.primary_key)
|
23
|
+
model.find_each(:batch_size => batch_size) do |record|
|
24
|
+
id_info = primary_keys.map { |key| record.public_send(key) }.join(", ")
|
25
|
+
logger.info "Processing record with ID #{id_info} ..."
|
26
|
+
|
27
|
+
record.update_columns(
|
28
|
+
record.attributes.filter { |attr| !attr.starts_with?("__") }
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
logger.info "Done."
|
33
|
+
end
|
34
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
1
3
|
module ActiveRecord
|
2
4
|
module ConnectionAdapters
|
3
5
|
module CipherStashPG
|
@@ -23,7 +25,7 @@ module ActiveRecord
|
|
23
25
|
end
|
24
26
|
|
25
27
|
private_class_method def self.logger
|
26
|
-
@logger ||=
|
28
|
+
@logger ||= Logger.new(STDOUT)
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require "active_record/base"
|
2
|
-
|
3
2
|
require "active_record/tasks/postgresql_database_tasks"
|
4
3
|
|
5
4
|
module ActiveRecord
|
@@ -12,4 +11,7 @@ module ActiveRecord
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
15
|
-
ActiveRecord::Tasks::DatabaseTasks.register_task(
|
14
|
+
ActiveRecord::Tasks::DatabaseTasks.register_task(
|
15
|
+
/postgres_cipherstash/,
|
16
|
+
ActiveRecord::ConnectionAdapters::CipherStashPG::DatabaseTasks
|
17
|
+
)
|
@@ -1,33 +1,27 @@
|
|
1
1
|
require "active_support"
|
2
2
|
require "active_record"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
require "active_record/connection_adapters/cipherstash_pg/database_extensions"
|
4
|
+
require "active_record/connection_adapters/cipherstash_pg/database_extensions"
|
5
|
+
require "active_record/connection_adapters/cipherstash_pg/database_tasks"
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
7
|
+
module ActiveRecord
|
8
|
+
module ConnectionAdapters
|
9
|
+
module CipherStashPG
|
10
|
+
class Railtie < ::Rails::Railtie
|
11
|
+
rake_tasks do
|
12
|
+
load "active_record/connection_adapters/cipherstash_pg/cipherstash_tasks.rake"
|
13
|
+
end
|
14
|
+
end
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
16
|
+
# Method to install CipherStash custom ORE types
|
17
|
+
def self.install
|
18
|
+
CipherStashPG::DatabaseExtensions.install
|
19
|
+
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
end
|
21
|
+
# Method to uninstall CipherStash custom ORE types
|
22
|
+
def self.uninstall
|
23
|
+
CipherStashPG::DatabaseExtensions.uninstall
|
28
24
|
end
|
29
25
|
end
|
30
|
-
# rubocop:enable Lint/ConstantDefinitionInBlock
|
31
|
-
|
32
26
|
end
|
33
27
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-cipherstash-pg-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robin Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-03-
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- README.md
|
54
54
|
- Rakefile
|
55
55
|
- activerecord-cipherstash-pg-adapter.gemspec
|
56
|
+
- lib/active_record/connection_adapters/cipherstash_pg/cipherstash_tasks.rake
|
56
57
|
- lib/active_record/connection_adapters/cipherstash_pg/column.rb
|
57
58
|
- lib/active_record/connection_adapters/cipherstash_pg/database_extensions.rb
|
58
59
|
- lib/active_record/connection_adapters/cipherstash_pg/database_statements.rb
|