activerecord-cipherstash-pg-adapter 0.1.0 → 0.2.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: 69d44a3c595b29d45352dc10d9db85aa5b9ebf81fec8c661ab8232af34c1571f
4
- data.tar.gz: ddfafb6aadc8acd590ec8eabcf0e1073de6a632fbb8a74df72052cbd4da23b4d
3
+ metadata.gz: 17eaea76f767bfda72f26bd7c9d89a4e8e0333dfc19be95a5390cbb8b0cbfc44
4
+ data.tar.gz: 379044af26990eb20e563e9aaa0bf727fcb5e70ac63ec89afa86e648d8882d3c
5
5
  SHA512:
6
- metadata.gz: f349ce508471576f31638a39b37e3b46762c910cecd41f813422e7738386f5f86b6b3096a65799ac7541221866395ef885c7595d1422960546d25bb6e0145116
7
- data.tar.gz: 70a747c73fef86e50ba4ca96e4ba088c1ca5c9b13b26819b7d56cb7dbecf3a9318388faf953a8e9a14f1b383e95e79dd24feac0dbd2589ce60d11cf541d3673f
6
+ metadata.gz: b25b5b4ef6ad537cb9ec045458553566b743b9739b3c0c863d41d28dc78316e9f557904c55d6145789bcf85b7bb15c9d42f5a81cb8b411471f4516274763e37d
7
+ data.tar.gz: be6d02946c7e8df400dc68d13bc614fd28a3787dea5b9317e8d4e86773097f2a22f7ced6dd5ca3b6fe58f8bfb8fdd041f64fbc0453bae3e9ad2bc89d87a2ffa2
data/README.md CHANGED
@@ -10,6 +10,8 @@ Add this line to your application's Gemfile:
10
10
  gem 'activerecord-cipherstash-pg-adapter'
11
11
  ```
12
12
 
13
+ Remove `gem 'pg'` from your Gemfile.
14
+
13
15
  In `database.yml`, use the following adapter setting:
14
16
 
15
17
  ```yaml
@@ -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 ||= Rails.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(/cipherstash_pg/, ActiveRecord::ConnectionAdapters::CipherStashPG::DatabaseTasks)
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
- if defined?(ActiveSupport.on_load)
5
- ActiveSupport.on_load(:active_record) do
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
- # rubocop:disable Lint/ConstantDefinitionInBlock
9
- module ActiveRecord
10
- module ConnectionAdapters
11
- module CipherStashPG
12
- class Railtie < ::Rails::Railtie
13
- rake_tasks do
14
- load "active_record/connection_adapters/cipherstash_pg/database_tasks.rb"
15
- end
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
- # Method to install CipherStash custom ORE types
19
- def self.install
20
- CipherStashPG::DatabaseExtensions.install
21
- end
16
+ # Method to install CipherStash custom ORE types
17
+ def self.install
18
+ CipherStashPG::DatabaseExtensions.install
19
+ end
22
20
 
23
- # Method to uninstall CipherStash custom ORE types
24
- def self.uninstall
25
- CipherStashPG::DatabaseExtensions.uninstall
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
@@ -1,3 +1,3 @@
1
1
  module ActiveRecord
2
- CIPHERSTASH_PG_ADAPTER_VERSION = "0.1.0"
2
+ CIPHERSTASH_PG_ADAPTER_VERSION = "0.2.0"
3
3
  end
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.1.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-22 00:00:00.000000000 Z
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