activerecord-cipherstash-pg-adapter 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/README.md +13 -1
  4. data/activerecord-cipherstash-pg-adapter.gemspec +1 -1
  5. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/column.rb +55 -0
  6. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/database_statements.rb +149 -0
  7. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/array.rb +91 -0
  8. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/date.rb +23 -0
  9. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/date_time.rb +31 -0
  10. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb +72 -0
  11. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/type_map_initializer.rb +113 -0
  12. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/oid.rb +36 -0
  13. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/quoting.rb +205 -0
  14. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb +43 -0
  15. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_creation.rb +80 -0
  16. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_definitions.rb +222 -0
  17. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_dumper.rb +49 -0
  18. data/lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_statements.rb +794 -0
  19. data/lib/active_record/connection_adapters/6.1/postgres_cipherstash_adapter.rb +958 -0
  20. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb +44 -0
  21. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/bit.rb +53 -0
  22. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/bit_varying.rb +15 -0
  23. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/bytea.rb +17 -0
  24. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb +48 -0
  25. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/decimal.rb +15 -0
  26. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/enum.rb +20 -0
  27. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/inet.rb +15 -0
  28. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/interval.rb +49 -0
  29. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/jsonb.rb +15 -0
  30. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb +44 -0
  31. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/macaddr.rb +25 -0
  32. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/money.rb +41 -0
  33. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/oid.rb +15 -0
  34. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/point.rb +64 -0
  35. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/range.rb +115 -0
  36. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/specialized_string.rb +18 -0
  37. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/uuid.rb +35 -0
  38. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/vector.rb +28 -0
  39. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/xml.rb +30 -0
  40. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/oid.rb +38 -0
  41. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/type_metadata.rb +44 -0
  42. data/lib/active_record/connection_adapters/7.0/cipherstash_pg/utils.rb +80 -0
  43. data/lib/active_record/connection_adapters/{cipherstash_pg_adapter.rb → 7.0/postgres_cipherstash_adapter.rb} +16 -48
  44. data/lib/active_record/connection_adapters/cipherstash_pg/database_extensions.rb +3 -1
  45. data/lib/active_record/connection_adapters/cipherstash_pg/database_tasks.rb +4 -2
  46. data/lib/active_record/connection_adapters/postgres_cipherstash_adapter.rb +42 -12
  47. data/lib/activerecord-cipherstash-pg-adapter.rb +17 -23
  48. data/lib/cipherstash_tasks.rake +34 -0
  49. data/lib/version.rb +1 -1
  50. metadata +89 -45
  51. data/lib/active_record/connection_adapters/cipherstash_pg/oid.rb +0 -38
  52. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/explain_pretty_printer.rb +0 -0
  53. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/bit.rb +0 -0
  54. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/bit_varying.rb +0 -0
  55. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/bytea.rb +0 -0
  56. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/cidr.rb +0 -0
  57. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/decimal.rb +0 -0
  58. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/enum.rb +0 -0
  59. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/inet.rb +0 -0
  60. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/interval.rb +0 -0
  61. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/jsonb.rb +0 -0
  62. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/legacy_point.rb +0 -0
  63. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/macaddr.rb +0 -0
  64. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/money.rb +0 -0
  65. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/oid.rb +0 -0
  66. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/point.rb +0 -0
  67. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/range.rb +0 -0
  68. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/specialized_string.rb +0 -0
  69. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/uuid.rb +0 -0
  70. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/vector.rb +0 -0
  71. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/oid/xml.rb +0 -0
  72. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/type_metadata.rb +0 -0
  73. /data/lib/active_record/connection_adapters/{cipherstash_pg → 6.1/cipherstash_pg}/utils.rb +0 -0
  74. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/column.rb +0 -0
  75. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/database_statements.rb +0 -0
  76. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/array.rb +0 -0
  77. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/date.rb +0 -0
  78. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/date_time.rb +0 -0
  79. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/hstore.rb +0 -0
  80. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/timestamp.rb +0 -0
  81. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/timestamp_with_time_zone.rb +0 -0
  82. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/oid/type_map_initializer.rb +0 -0
  83. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/quoting.rb +0 -0
  84. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/referential_integrity.rb +0 -0
  85. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/schema_creation.rb +0 -0
  86. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/schema_definitions.rb +0 -0
  87. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/schema_dumper.rb +0 -0
  88. /data/lib/active_record/connection_adapters/{cipherstash_pg → 7.0/cipherstash_pg}/schema_statements.rb +0 -0
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module CipherStashPG
6
+ module OID # :nodoc:
7
+ class Xml < Type::String # :nodoc:
8
+ def type
9
+ :xml
10
+ end
11
+
12
+ def serialize(value)
13
+ return unless value
14
+ Data.new(super)
15
+ end
16
+
17
+ class Data # :nodoc:
18
+ def initialize(value)
19
+ @value = value
20
+ end
21
+
22
+ def to_s
23
+ @value
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./oid/array"
4
+ require_relative "./oid/bit"
5
+ require_relative "./oid/bit_varying"
6
+ require_relative "./oid/bytea"
7
+ require_relative "./oid/cidr"
8
+ require_relative "./oid/date"
9
+ require_relative "./oid/date_time"
10
+ require_relative "./oid/decimal"
11
+ require_relative "./oid/enum"
12
+ require_relative "./oid/hstore"
13
+ require_relative "./oid/inet"
14
+ require_relative "./oid/interval"
15
+ require_relative "./oid/jsonb"
16
+ require_relative "./oid/macaddr"
17
+ require_relative "./oid/money"
18
+ require_relative "./oid/oid"
19
+ require_relative "./oid/point"
20
+ require_relative "./oid/legacy_point"
21
+ require_relative "./oid/range"
22
+ require_relative "./oid/specialized_string"
23
+ require_relative "./oid/timestamp"
24
+ require_relative "./oid/timestamp_with_time_zone"
25
+ require_relative "./oid/uuid"
26
+ require_relative "./oid/vector"
27
+ require_relative "./oid/xml"
28
+
29
+ require_relative "./oid/type_map_initializer"
30
+
31
+ module ActiveRecord
32
+ module ConnectionAdapters
33
+ module CipherStashPG
34
+ module OID # :nodoc:
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ # :stopdoc:
5
+ module ConnectionAdapters
6
+ module CipherStashPG
7
+ class TypeMetadata < DelegateClass(SqlTypeMetadata)
8
+ undef to_yaml if method_defined?(:to_yaml)
9
+
10
+ include Deduplicable
11
+
12
+ attr_reader :oid, :fmod
13
+
14
+ def initialize(type_metadata, oid: nil, fmod: nil)
15
+ super(type_metadata)
16
+ @oid = oid
17
+ @fmod = fmod
18
+ end
19
+
20
+ def ==(other)
21
+ other.is_a?(TypeMetadata) &&
22
+ __getobj__ == other.__getobj__ &&
23
+ oid == other.oid &&
24
+ fmod == other.fmod
25
+ end
26
+ alias eql? ==
27
+
28
+ def hash
29
+ TypeMetadata.hash ^
30
+ __getobj__.hash ^
31
+ oid.hash ^
32
+ fmod.hash
33
+ end
34
+
35
+ private
36
+ def deduplicated
37
+ __setobj__(__getobj__.deduplicate)
38
+ super
39
+ end
40
+ end
41
+ end
42
+ CipherStashPGTypeMetadata = CipherStashPG::TypeMetadata
43
+ end
44
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module ConnectionAdapters
5
+ module CipherStashPG
6
+ # Value Object to hold a schema qualified name.
7
+ # This is usually the name of a PostgreSQL relation but it can also represent
8
+ # schema qualified type names. +schema+ and +identifier+ are unquoted to prevent
9
+ # double quoting.
10
+ class Name # :nodoc:
11
+ SEPARATOR = "."
12
+ attr_reader :schema, :identifier
13
+
14
+ def initialize(schema, identifier)
15
+ @schema, @identifier = unquote(schema), unquote(identifier)
16
+ end
17
+
18
+ def to_s
19
+ parts.join SEPARATOR
20
+ end
21
+
22
+ def quoted
23
+ if schema
24
+ PG::Connection.quote_ident(schema) << SEPARATOR << PG::Connection.quote_ident(identifier)
25
+ else
26
+ PG::Connection.quote_ident(identifier)
27
+ end
28
+ end
29
+
30
+ def ==(o)
31
+ o.class == self.class && o.parts == parts
32
+ end
33
+ alias_method :eql?, :==
34
+
35
+ def hash
36
+ parts.hash
37
+ end
38
+
39
+ protected
40
+ def parts
41
+ @parts ||= [@schema, @identifier].compact
42
+ end
43
+
44
+ private
45
+ def unquote(part)
46
+ if part && part.start_with?('"')
47
+ part[1..-2]
48
+ else
49
+ part
50
+ end
51
+ end
52
+ end
53
+
54
+ module Utils # :nodoc:
55
+ extend self
56
+
57
+ # Returns an instance of <tt>ActiveRecord::ConnectionAdapters::CipherStashPG::Name</tt>
58
+ # extracted from +string+.
59
+ # +schema+ is +nil+ if not specified in +string+.
60
+ # +schema+ and +identifier+ exclude surrounding quotes (regardless of whether provided in +string+)
61
+ # +string+ supports the range of schema/table references understood by PostgreSQL, for example:
62
+ #
63
+ # * <tt>table_name</tt>
64
+ # * <tt>"table.name"</tt>
65
+ # * <tt>schema_name.table_name</tt>
66
+ # * <tt>schema_name."table.name"</tt>
67
+ # * <tt>"schema_name".table_name</tt>
68
+ # * <tt>"schema.name"."table name"</tt>
69
+ def extract_schema_qualified_name(string)
70
+ schema, table = string.scan(/[^".]+|"[^"]*"/)
71
+ if table.nil?
72
+ table = schema
73
+ schema = nil
74
+ end
75
+ CipherStashPG::Name.new(schema, table)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -1,60 +1,28 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # Why the funky filename
4
- # (lib/active_record/connection_adapters/cipherstash_pg_adapter.rb)
5
- # that doesn't match the gem structure? It's to hook into Rails.
6
- #
7
- # See this chunk from:
8
- # https://github.com/rails/rails/blob/d7d93faacfe0ca3297a47f676772828d7210b9bc/activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb#L325-L330
9
- #
10
- # # Require the adapter itself and give useful feedback about
11
- # # 1. Missing adapter gems and
12
- # # 2. Adapter gems' missing dependencies.
13
- # path_to_adapter = "active_record/connection_adapters/#{db_config.adapter}_adapter"
14
- # begin
15
- # require path_to_adapter
16
- # ...
17
-
18
- # TODO: is this actually required?
19
- #gem "cipherstash-pg", "~> 1.1"
20
-
21
- require "cipherstash-pg"
22
2
 
23
3
  require "active_support/core_ext/object/try"
24
4
  require "active_record/connection_adapters/abstract_adapter"
25
5
  require "active_record/connection_adapters/statement_pool"
26
- require "active_record/connection_adapters/cipherstash_pg/column"
27
- require "active_record/connection_adapters/cipherstash_pg/database_statements"
28
- require "active_record/connection_adapters/cipherstash_pg/explain_pretty_printer"
29
- require "active_record/connection_adapters/cipherstash_pg/oid"
30
- require "active_record/connection_adapters/cipherstash_pg/quoting"
31
- require "active_record/connection_adapters/cipherstash_pg/referential_integrity"
32
- require "active_record/connection_adapters/cipherstash_pg/schema_creation"
33
- require "active_record/connection_adapters/cipherstash_pg/schema_definitions"
34
- require "active_record/connection_adapters/cipherstash_pg/schema_dumper"
35
- require "active_record/connection_adapters/cipherstash_pg/schema_statements"
36
- require "active_record/connection_adapters/cipherstash_pg/type_metadata"
37
- require "active_record/connection_adapters/cipherstash_pg/utils"
6
+
7
+ require_relative "./cipherstash_pg/column"
8
+ require_relative "./cipherstash_pg/database_statements"
9
+ require_relative "./cipherstash_pg/explain_pretty_printer"
10
+ require_relative "./cipherstash_pg/oid"
11
+ require_relative "./cipherstash_pg/quoting"
12
+ require_relative "./cipherstash_pg/referential_integrity"
13
+ require_relative "./cipherstash_pg/schema_creation"
14
+ require_relative "./cipherstash_pg/schema_definitions"
15
+ require_relative "./cipherstash_pg/schema_dumper"
16
+ require_relative "./cipherstash_pg/schema_statements"
17
+ require_relative "./cipherstash_pg/type_metadata"
18
+ require_relative "./cipherstash_pg/utils"
38
19
 
39
20
  module ActiveRecord
40
21
  module ConnectionHandling
41
- # This is the entrypoint that is called when Rails looks for the adapter,
42
- # when you have this in your database.yml config:
43
- #
44
- # adapter: cipherstash_pg
45
- #
46
- # See: https://github.com/rails/rails/blob/d7d93faacfe0ca3297a47f676772828d7210b9bc/activerecord/lib/active_record/database_configurations/database_config.rb#L16-L18
47
- #
48
- # Please note that we now recommend instead having:
49
- #
50
- # adapter: postgres_cipherstash
51
- #
52
- # ... to match the implicit AR naming scheme enforced by "rails dbconsole", eg.
53
- # https://github.com/rails/rails/blob/7-0-stable/railties/lib/rails/commands/dbconsole/dbconsole_command.rb#L46
54
-
55
22
  ###########################################################################
56
23
  # Everything from this point onwards is a copy-paste or inherit from Rails'
57
24
  # activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
25
+ # subtree as of f1aa436d738.
58
26
  #
59
27
  # ... with the exception of adding the ore_64_8_v1 type support on line 635.
60
28
  #
@@ -63,7 +31,7 @@ module ActiveRecord
63
31
  # now] have both 'cipherstash-pg' and 'pg' loaded at the same time.)
64
32
  ###########################################################################
65
33
 
66
- def cipherstash_pg_connection(config)
34
+ def postgres_cipherstash_connection(config)
67
35
  conn_params = config.symbolize_keys.compact
68
36
 
69
37
  # Map ActiveRecords param names to PGs.
@@ -312,7 +280,7 @@ module ActiveRecord
312
280
  end
313
281
 
314
282
  def self.database_exists?(config)
315
- !!ActiveRecord::Base.cipherstash_pg_connection(config)
283
+ !!ActiveRecord::Base.postgres_cipherstash_connection(config)
316
284
  rescue ActiveRecord::NoDatabaseError
317
285
  false
318
286
  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,13 +1,43 @@
1
- require "active_record/connection_adapters/cipherstash_pg_adapter"
2
-
3
- module ActiveRecord
4
- module ConnectionHandling
5
- # This is the entrypoint that is called when Rails looks for the adapter,
6
- # when you have this in your database.yml config:
7
- #
8
- # adapter: postgres_cipherstash
9
- #
10
- # See: https://github.com/rails/rails/blob/d7d93faacfe0ca3297a47f676772828d7210b9bc/activerecord/lib/active_record/database_configurations/database_config.rb#L16-L18
11
- alias_method :postgres_cipherstash_connection, :cipherstash_pg_connection
12
- end
1
+ # frozen_string_literal: true
2
+ #
3
+ # Why the funky filename
4
+ # (lib/active_record/connection_adapters/cipherstash_pg_adapter.rb)
5
+ # that doesn't match the gem structure? It's to hook into Rails.
6
+ #
7
+ # See this chunk from:
8
+ # https://github.com/rails/rails/blob/d7d93faacfe0ca3297a47f676772828d7210b9bc/activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb#L325-L330
9
+ #
10
+ # # Require the adapter itself and give useful feedback about
11
+ # # 1. Missing adapter gems and
12
+ # # 2. Adapter gems' missing dependencies.
13
+ # path_to_adapter = "active_record/connection_adapters/#{db_config.adapter}_adapter"
14
+ # begin
15
+ # require path_to_adapter
16
+ # ...
17
+ # This is the entrypoint that is called when Rails looks for the adapter,
18
+ # when you have this in your database.yml config:
19
+ #
20
+ # adapter: postgres_cipherstash
21
+ #
22
+ # See: https://github.com/rails/rails/blob/d7d93faacfe0ca3297a47f676772828d7210b9bc/activerecord/lib/active_record/database_configurations/database_config.rb#L16-L18
23
+ #
24
+ #
25
+ # ... to match the implicit AR naming scheme enforced by "rails dbconsole", eg.
26
+ # https://github.com/rails/rails/blob/7-0-stable/railties/lib/rails/commands/dbconsole/dbconsole_command.rb#L46
27
+ #
28
+ #
29
+ # Depending on the version of Rails being used, the relevant child postgres_cipherstash_adapter module is required.
30
+
31
+
32
+ require "cipherstash-pg"
33
+
34
+ case Rails::VERSION::MAJOR
35
+ when 7
36
+ require "active_record/connection_adapters/7.0/postgres_cipherstash_adapter"
37
+ when 6
38
+ require "active_record/connection_adapters/6.1/postgres_cipherstash_adapter"
39
+ else
40
+ STDERR.puts "CipherStash only supports Rails versions 6.x and 7.x"
41
+ exit 1
13
42
  end
43
+
@@ -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 "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
@@ -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
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.3.0"
3
3
  end
metadata CHANGED
@@ -1,29 +1,35 @@
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.3.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-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 6.0.0
20
+ - - "<"
18
21
  - !ruby/object:Gem::Version
19
- version: 7.0.3
22
+ version: 8.0.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 6.0.0
30
+ - - "<"
25
31
  - !ruby/object:Gem::Version
26
- version: 7.0.3
32
+ version: 8.0.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: cipherstash-pg
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -53,49 +59,87 @@ files:
53
59
  - README.md
54
60
  - Rakefile
55
61
  - activerecord-cipherstash-pg-adapter.gemspec
56
- - lib/active_record/connection_adapters/cipherstash_pg/column.rb
62
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/column.rb
63
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/database_statements.rb
64
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/explain_pretty_printer.rb
65
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid.rb
66
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/array.rb
67
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/bit.rb
68
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/bit_varying.rb
69
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/bytea.rb
70
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/cidr.rb
71
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/date.rb
72
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/date_time.rb
73
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/decimal.rb
74
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/enum.rb
75
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/hstore.rb
76
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/inet.rb
77
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/interval.rb
78
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/jsonb.rb
79
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/legacy_point.rb
80
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/macaddr.rb
81
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/money.rb
82
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/oid.rb
83
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/point.rb
84
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/range.rb
85
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/specialized_string.rb
86
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/type_map_initializer.rb
87
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/uuid.rb
88
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/vector.rb
89
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/oid/xml.rb
90
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/quoting.rb
91
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/referential_integrity.rb
92
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_creation.rb
93
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_definitions.rb
94
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_dumper.rb
95
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/schema_statements.rb
96
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/type_metadata.rb
97
+ - lib/active_record/connection_adapters/6.1/cipherstash_pg/utils.rb
98
+ - lib/active_record/connection_adapters/6.1/postgres_cipherstash_adapter.rb
99
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/column.rb
100
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/database_statements.rb
101
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/explain_pretty_printer.rb
102
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid.rb
103
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/array.rb
104
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/bit.rb
105
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/bit_varying.rb
106
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/bytea.rb
107
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/cidr.rb
108
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date.rb
109
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/date_time.rb
110
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/decimal.rb
111
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/enum.rb
112
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/hstore.rb
113
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/inet.rb
114
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/interval.rb
115
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/jsonb.rb
116
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/legacy_point.rb
117
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/macaddr.rb
118
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/money.rb
119
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/oid.rb
120
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/point.rb
121
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/range.rb
122
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/specialized_string.rb
123
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/timestamp.rb
124
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/timestamp_with_time_zone.rb
125
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/type_map_initializer.rb
126
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/uuid.rb
127
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/vector.rb
128
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/oid/xml.rb
129
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/quoting.rb
130
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/referential_integrity.rb
131
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/schema_creation.rb
132
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/schema_definitions.rb
133
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/schema_dumper.rb
134
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/schema_statements.rb
135
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/type_metadata.rb
136
+ - lib/active_record/connection_adapters/7.0/cipherstash_pg/utils.rb
137
+ - lib/active_record/connection_adapters/7.0/postgres_cipherstash_adapter.rb
57
138
  - lib/active_record/connection_adapters/cipherstash_pg/database_extensions.rb
58
- - lib/active_record/connection_adapters/cipherstash_pg/database_statements.rb
59
139
  - lib/active_record/connection_adapters/cipherstash_pg/database_tasks.rb
60
- - lib/active_record/connection_adapters/cipherstash_pg/explain_pretty_printer.rb
61
- - lib/active_record/connection_adapters/cipherstash_pg/oid.rb
62
- - lib/active_record/connection_adapters/cipherstash_pg/oid/array.rb
63
- - lib/active_record/connection_adapters/cipherstash_pg/oid/bit.rb
64
- - lib/active_record/connection_adapters/cipherstash_pg/oid/bit_varying.rb
65
- - lib/active_record/connection_adapters/cipherstash_pg/oid/bytea.rb
66
- - lib/active_record/connection_adapters/cipherstash_pg/oid/cidr.rb
67
- - lib/active_record/connection_adapters/cipherstash_pg/oid/date.rb
68
- - lib/active_record/connection_adapters/cipherstash_pg/oid/date_time.rb
69
- - lib/active_record/connection_adapters/cipherstash_pg/oid/decimal.rb
70
- - lib/active_record/connection_adapters/cipherstash_pg/oid/enum.rb
71
- - lib/active_record/connection_adapters/cipherstash_pg/oid/hstore.rb
72
- - lib/active_record/connection_adapters/cipherstash_pg/oid/inet.rb
73
- - lib/active_record/connection_adapters/cipherstash_pg/oid/interval.rb
74
- - lib/active_record/connection_adapters/cipherstash_pg/oid/jsonb.rb
75
- - lib/active_record/connection_adapters/cipherstash_pg/oid/legacy_point.rb
76
- - lib/active_record/connection_adapters/cipherstash_pg/oid/macaddr.rb
77
- - lib/active_record/connection_adapters/cipherstash_pg/oid/money.rb
78
- - lib/active_record/connection_adapters/cipherstash_pg/oid/oid.rb
79
- - lib/active_record/connection_adapters/cipherstash_pg/oid/point.rb
80
- - lib/active_record/connection_adapters/cipherstash_pg/oid/range.rb
81
- - lib/active_record/connection_adapters/cipherstash_pg/oid/specialized_string.rb
82
- - lib/active_record/connection_adapters/cipherstash_pg/oid/timestamp.rb
83
- - lib/active_record/connection_adapters/cipherstash_pg/oid/timestamp_with_time_zone.rb
84
- - lib/active_record/connection_adapters/cipherstash_pg/oid/type_map_initializer.rb
85
- - lib/active_record/connection_adapters/cipherstash_pg/oid/uuid.rb
86
- - lib/active_record/connection_adapters/cipherstash_pg/oid/vector.rb
87
- - lib/active_record/connection_adapters/cipherstash_pg/oid/xml.rb
88
- - lib/active_record/connection_adapters/cipherstash_pg/quoting.rb
89
- - lib/active_record/connection_adapters/cipherstash_pg/referential_integrity.rb
90
- - lib/active_record/connection_adapters/cipherstash_pg/schema_creation.rb
91
- - lib/active_record/connection_adapters/cipherstash_pg/schema_definitions.rb
92
- - lib/active_record/connection_adapters/cipherstash_pg/schema_dumper.rb
93
- - lib/active_record/connection_adapters/cipherstash_pg/schema_statements.rb
94
- - lib/active_record/connection_adapters/cipherstash_pg/type_metadata.rb
95
- - lib/active_record/connection_adapters/cipherstash_pg/utils.rb
96
- - lib/active_record/connection_adapters/cipherstash_pg_adapter.rb
97
140
  - lib/active_record/connection_adapters/postgres_cipherstash_adapter.rb
98
141
  - lib/activerecord-cipherstash-pg-adapter.rb
142
+ - lib/cipherstash_tasks.rake
99
143
  - lib/version.rb
100
144
  homepage: https://github.com/cipherstash/activerecord-cipherstash-pg-adapter
101
145
  licenses: