activerecord_archive 1.0.2 → 1.0.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/activerecord_archive.rb +8 -2
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f053c38eeeae82a50f8d165bf5674f9ecb9b4f91e4dac9783b9819dc5a4dffd4
4
- data.tar.gz: d6b2051f4d9953e2c2c9cc5582a3d3191f4e3aeb60f641b2ab865b4f51e3d4a4
3
+ metadata.gz: ec6caa129b25d19c6f0f399c91509018130b38f4bbed884de7efebf7df1d5137
4
+ data.tar.gz: f02746ec310b8ad11af8a08e2c04a4b5ee023b442e194c7d236be8ae4134bec4
5
5
  SHA512:
6
- metadata.gz: 19bd05bc6cea7616a99ae742ed670d9b7511352be015642f83003bb70426c3f80ea5a56ef6f3a2bbd88df7e6e66963c6f5fcae6e182d191bbb32c96d0c324a43
7
- data.tar.gz: ed1c62bd3905ae5731f6e24ec968af6fa3e260256e43a356553d78844714857452b9a9816d306d8412fa9db4524aa579be322a90ac9b664a639e06308eba3814
6
+ metadata.gz: dcb76d080936e53506cadf4e2d2353d10072ab8472c6d2b8d861fc5829e1a690a1e3e2fdee0b0d67c34cdd9eeab8c01d7ef87b03f98033fdcf7054ba52301a87
7
+ data.tar.gz: 914075c3c87ae28ede48f1500b226cf7d213a355fd836c59a0c9e6962fe50b6ff46d123daa1b4e2934157f27a536012a0939d5deef5507fa0e1243acbf1350d1
@@ -10,6 +10,7 @@ module ArchiveMethods # :nodoc:
10
10
  end
11
11
 
12
12
  raise 'PrefixAndTableNameTooLong - maximum is 64 characters' if "#{options[:prefix]}#{tabname}".size > 64
13
+ raise 'PrimaryKey id expected but not found' unless self.primary_key == 'id'
13
14
 
14
15
  # do a simple query first in case to cause an exception if there is an error in conditions
15
16
  ActiveRecord::Base.connection.execute("
@@ -23,11 +24,13 @@ module ArchiveMethods # :nodoc:
23
24
  LIKE #{tabname}
24
25
  ")
25
26
 
27
+ # use replace into in case of duplicate inserts
26
28
  ActiveRecord::Base.connection.execute("
27
- INSERT INTO #{options[:prefix]}#{tabname}
29
+ REPLACE INTO #{options[:prefix]}#{tabname}
28
30
  SELECT * FROM #{tabname} WHERE #{conditions}
29
31
  ")
30
32
 
33
+ # delete only records in parent table where ids match those in archive table
31
34
  ActiveRecord::Base.connection.execute("
32
35
  DELETE FROM #{tabname}
33
36
  WHERE EXISTS(
@@ -48,6 +51,7 @@ module ArchiveMethods # :nodoc:
48
51
  end
49
52
 
50
53
  raise 'PrefixAndTableNameTooLong - maximum is 64 characters' if "#{options[:prefix]}#{tabname}".size > 64
54
+ raise 'PrimaryKey id expected but not found' unless self.primary_key == 'id'
51
55
 
52
56
  # do a simple query first in case to cause an exception if there is an error in conditions
53
57
  ActiveRecord::Base.connection.execute("
@@ -56,11 +60,13 @@ module ArchiveMethods # :nodoc:
56
60
  WHERE #{conditions}
57
61
  ")
58
62
 
63
+ # use replace into in case of duplicate inserts
59
64
  ActiveRecord::Base.connection.execute("
60
- INSERT INTO #{tabname}
65
+ REPLACE INTO #{tabname}
61
66
  SELECT * FROM #{options[:prefix]}#{tabname} WHERE #{conditions}
62
67
  ")
63
68
 
69
+ # delete only records in archive table where ids match those in parent table
64
70
  ActiveRecord::Base.connection.execute("
65
71
  DELETE FROM #{options[:prefix]}#{tabname}
66
72
  WHERE EXISTS(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_archive
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vic Spanner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-15 00:00:00.000000000 Z
11
+ date: 2022-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple archiving extension for ActiveRecord. Archive old records to
14
14
  improve database performance. Restore old records from archive tables.
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  requirements: []
40
- rubygems_version: 3.1.2
40
+ rubygems_version: 3.0.6
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: ActiveRecord Archiving