paquito 0.11.3 → 1.0.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: 5ede4c0254b56d0c34d1d664903ffcd51db1ce717723a82858973c76d41231bb
4
- data.tar.gz: 97d7ac64e05043df851dd6ef49cec163991c91afc6b25e98e1b4649a5a808eb8
3
+ metadata.gz: 6b6c5c9838f1a54d3ffce2095ac8b46b423b54eaea4704ace9e7a33ad011316d
4
+ data.tar.gz: e3b26fc6ecdc8ad279b2f9157089536d69e942fe011458b521da0daf2b8e423d
5
5
  SHA512:
6
- metadata.gz: 650bc85b15bbf5c2516941222d3de02e6c7b622a0998e9ccd2db2adf439964d5edc877227b750fad06903c0d00f58a61004e3e6271b37bf6d67f8a1aeb45dcfc
7
- data.tar.gz: b2b03a2c958c622e68b8f1cf3745d89b4cefc9ac4070875d85174ed3c5943c27a31df049f44b677d9fd6c33e958c8ddc9b834f4d8870ed8a547fe7b30b1df8ba
6
+ metadata.gz: 513b52e62ba30a9f3f94f63b19b467f9c9dbed9ec3a65d41dd9efe8a50a97bbf580c8c3c29a6dd15a2f4ace5e4f692728377757983d6500ef3b531db83c955e8
7
+ data.tar.gz: 90b2dffe3fe1569ee79927e7aecead29731665908b03772c300e95bab2e62844fc2a247b4b54da5ab1999c0608fa8bb7606990b1d18777779bf651ada1fd14eb
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # 1.0.0
2
+
3
+ Both changes in this release require applications to be fully updated to the latest patch version of the gem before
4
+ bumping to this version.
5
+
6
+ * Store md5 digest of columns + sql types along with records (#51)
7
+ *IMPORTANT*: if you are storing Active Record objects in the cache, ensure you have updated and deployed 0.11.3 before
8
+ upgrading, and ensure you are handling either all `ActiveRecordCoder::Error` errors, or that you explicitly add
9
+ `ActiveRecordCoder::ColumnsDigestMismatch` to your error handling.
10
+ * Bump `Paquito.format_version` to `1` by default.
11
+ *IMPORTANT*: if you are upgrading from a previous version, you MUST first fully deploy the gem up to at least version 0.10.0
12
+ and release before enabling it. If you don't, you may notice some `UnpackError` during the code rollout, which may be fine
13
+ if you only use Paquito for ephemeral cache data. See release notes for v0.10.0.
14
+
1
15
  # 0.11.3
2
16
 
3
17
  * Deserialize records with extra unused array elements in payload (#52)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- paquito (0.11.3)
4
+ paquito (1.0.0)
5
5
  msgpack (>= 1.5.2)
6
6
 
7
7
  GEM
@@ -88,9 +88,12 @@ module Paquito
88
88
  end
89
89
 
90
90
  def serialize_record(record)
91
- arguments = [record.class.name, attributes_for_database(record)]
92
- arguments << true if record.new_record?
93
- arguments
91
+ [
92
+ record.class.name,
93
+ attributes_for_database(record),
94
+ record.new_record?,
95
+ columns_digest(record.class),
96
+ ]
94
97
  end
95
98
 
96
99
  def attributes_for_database(record)
@@ -99,18 +102,28 @@ module Paquito
99
102
  attributes
100
103
  end
101
104
 
102
- def deserialize_record(class_name, attributes_from_database, new_record = false, *)
105
+ def deserialize_record(class_name, attributes_from_database, new_record = false, hash = nil, *)
103
106
  begin
104
107
  klass = Object.const_get(class_name)
105
108
  rescue NameError
106
109
  raise ClassMissingError, "undefined class: #{class_name}"
107
110
  end
108
111
 
112
+ if hash && (hash != (expected_digest = columns_digest(klass)))
113
+ raise ColumnsDigestMismatch,
114
+ "\"#{hash}\" does not match the expected digest of \"#{expected_digest}\""
115
+ end
116
+
109
117
  # Ideally we'd like to call `klass.instantiate`, however it doesn't allow to pass
110
118
  # wether the record was persisted or not.
111
119
  attributes = klass.attributes_builder.build_from_database(attributes_from_database, EMPTY_HASH)
112
120
  klass.allocate.init_with_attributes(attributes, new_record)
113
121
  end
122
+
123
+ def columns_digest(klass)
124
+ str = klass.columns_hash.map { |name, column| [name, column.sql_type].join(":") }.join(",")
125
+ ::Digest::MD5.digest(str).unpack1("s")
126
+ end
114
127
  end
115
128
 
116
129
  class Error < ::Paquito::Error
@@ -122,6 +135,9 @@ module Paquito
122
135
  class AssociationMissingError < Error
123
136
  end
124
137
 
138
+ class ColumnsDigestMismatch < Error
139
+ end
140
+
125
141
  class InstanceTracker
126
142
  def initialize
127
143
  @instances = []
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Paquito
4
- VERSION = "0.11.3"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/paquito.rb CHANGED
@@ -29,7 +29,7 @@ module Paquito
29
29
  autoload :FlatCacheEntryCoder, "paquito/flat_cache_entry_coder"
30
30
  autoload :ActiveRecordCoder, "paquito/active_record_coder"
31
31
 
32
- DEFAULT_FORMAT_VERSION = 0
32
+ DEFAULT_FORMAT_VERSION = 1
33
33
  @format_version = DEFAULT_FORMAT_VERSION
34
34
 
35
35
  class << self
data/paquito.gemspec CHANGED
@@ -19,6 +19,14 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata["homepage_uri"] = spec.homepage
20
20
  spec.metadata["source_code_uri"] = "https://github.com/Shopify/paquito"
21
21
 
22
+ spec.post_install_message = <<~POST_INSTALL_MSG
23
+ Warning: Paquito 1.0 includes potentially breaking changes to ActiveRecordCoder.
24
+ Before upgrading to 1.0 from an earlier version, ensure you have first upgraded
25
+ to 0.11.3 and deployed your application before upgrading to 1.0. Also ensure you
26
+ rescue either all `ActiveRecordCoder::Error` errors, or that you explicitly
27
+ rescue the new `ActiveRecord::ColumnsDigestError`.
28
+ POST_INSTALL_MSG
29
+
22
30
  # Specify which files should be added to the gem when it is released.
23
31
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
32
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paquito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-02-06 00:00:00.000000000 Z
10
+ date: 2025-02-25 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: msgpack
@@ -82,6 +82,12 @@ metadata:
82
82
  allowed_push_host: https://rubygems.org
83
83
  homepage_uri: https://github.com/Shopify/paquito
84
84
  source_code_uri: https://github.com/Shopify/paquito
85
+ post_install_message: |
86
+ Warning: Paquito 1.0 includes potentially breaking changes to ActiveRecordCoder.
87
+ Before upgrading to 1.0 from an earlier version, ensure you have first upgraded
88
+ to 0.11.3 and deployed your application before upgrading to 1.0. Also ensure you
89
+ rescue either all `ActiveRecordCoder::Error` errors, or that you explicitly
90
+ rescue the new `ActiveRecord::ColumnsDigestError`.
85
91
  rdoc_options: []
86
92
  require_paths:
87
93
  - lib