active_record-log_deleted 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9803c59ea8139a5646a2979a295568dba8c1235b6647cb2a5bafcb74c4b0f83e
|
4
|
+
data.tar.gz: 2b082ff16bc9743acc0ede7d40bc2996bbfce2b376a08b1ed1c4dd422b04f59f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d7554dbbd905fe085ccbee112b2a5027a0b841ba9e4eacf59cf249fbfb45b80e873247b1ba0da2aa0d1138d10363b933f5e6fcd8756fc0fbaaf99cdb6ac173e
|
7
|
+
data.tar.gz: 9efee34f63b94c1c3f7be395026494f859edd85c9b9671c5d921d0aa41d9c8f6b1b1ab136058bea5a14917b667b850815a2a467684974e782d45b62209dc05fa
|
data/Gemfile.lock
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module LogDeleted
|
3
3
|
class Configuration
|
4
|
-
attr_reader
|
4
|
+
attr_reader(
|
5
|
+
:deleted_rows_table_name,
|
6
|
+
:log_deleted_row_function_name,
|
7
|
+
:log_deleted_row_trigger_name,
|
8
|
+
:support_uuids
|
9
|
+
)
|
5
10
|
|
6
11
|
def initialize
|
7
12
|
@deleted_rows_table_name = :deleted_rows
|
8
13
|
@log_deleted_row_function_name = :log_deleted_row
|
9
14
|
@log_deleted_row_trigger_name = :log_deleted_row_trigger
|
15
|
+
@support_uuids = true
|
10
16
|
end
|
11
17
|
|
12
18
|
def deleted_rows_table_name=(name)
|
@@ -21,6 +27,10 @@ module ActiveRecord
|
|
21
27
|
@log_deleted_row_trigger_name = sanitize(name)
|
22
28
|
end
|
23
29
|
|
30
|
+
def support_uuids=(value)
|
31
|
+
@support_uuids = value
|
32
|
+
end
|
33
|
+
|
24
34
|
private
|
25
35
|
|
26
36
|
def sanitize(value)
|
@@ -4,10 +4,11 @@ module ActiveRecord
|
|
4
4
|
module LogDeleted
|
5
5
|
module PostgreSQLAdapter
|
6
6
|
def create_deleted_rows_table
|
7
|
+
old_primary_key_type = configuration.support_uuids ? :string : :bigint
|
7
8
|
create_table deleted_rows_table_name do |t|
|
8
9
|
t.datetime :created_at, comment: 'The datetime at which the record was created.'
|
9
10
|
t.text :old_row_json, comment: 'JSON with the entire row that was hard deleted.'
|
10
|
-
t.
|
11
|
+
t.send old_primary_key_type, :primary_key, comment: 'The primary key of the row which was hard deleted.'
|
11
12
|
t.string :table_name, limit: 255, comment: 'The table name from which the row was hard deleted.'
|
12
13
|
end
|
13
14
|
end
|
@@ -22,7 +23,7 @@ module ActiveRecord
|
|
22
23
|
BEGIN
|
23
24
|
INSERT INTO
|
24
25
|
deleted_rows(table_name, primary_key, old_row_json, created_at)
|
25
|
-
VALUES (TG_TABLE_NAME, OLD
|
26
|
+
VALUES (TG_TABLE_NAME, #{old_primary_key('OLD')}, ROW_TO_JSON(OLD), now());
|
26
27
|
RETURN OLD;
|
27
28
|
END;
|
28
29
|
$$ LANGUAGE plpgsql;
|
@@ -30,7 +31,9 @@ module ActiveRecord
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def drop_log_deleted_row_function
|
33
|
-
execute
|
34
|
+
execute <<~SQL
|
35
|
+
DROP FUNCTION IF EXISTS #{log_deleted_row_function_name}();
|
36
|
+
SQL
|
34
37
|
end
|
35
38
|
|
36
39
|
def create_deleted_row_trigger(table_name)
|
@@ -47,6 +50,12 @@ module ActiveRecord
|
|
47
50
|
|
48
51
|
private
|
49
52
|
|
53
|
+
def old_primary_key(table)
|
54
|
+
value = "#{table}.id"
|
55
|
+
value += '::varchar' if configuration.support_uuids
|
56
|
+
value
|
57
|
+
end
|
58
|
+
|
50
59
|
def log_deleted_row_trigger_name
|
51
60
|
configuration.log_deleted_row_trigger_name
|
52
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record-log_deleted
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- matthew fong
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|