activerecord_archive 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/activerecord_archive.rb +8 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec6caa129b25d19c6f0f399c91509018130b38f4bbed884de7efebf7df1d5137
|
4
|
+
data.tar.gz: f02746ec310b8ad11af8a08e2c04a4b5ee023b442e194c7d236be8ae4134bec4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dcb76d080936e53506cadf4e2d2353d10072ab8472c6d2b8d861fc5829e1a690a1e3e2fdee0b0d67c34cdd9eeab8c01d7ef87b03f98033fdcf7054ba52301a87
|
7
|
+
data.tar.gz: 914075c3c87ae28ede48f1500b226cf7d213a355fd836c59a0c9e6962fe50b6ff46d123daa1b4e2934157f27a536012a0939d5deef5507fa0e1243acbf1350d1
|
data/lib/activerecord_archive.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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.
|
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:
|
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.
|
40
|
+
rubygems_version: 3.0.6
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
43
|
summary: ActiveRecord Archiving
|