waldit 0.0.7 → 0.0.9

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: f5c8f24220664dba4cbdda331668fff84cfdf94fa0bc12eb0632613cc83e65c0
4
- data.tar.gz: ad904cc5fa30b2a7de5a5b9844242be0a7fb568695106035956996f84e889731
3
+ metadata.gz: af8a3191d1b6471577a8f684b232d3634271624328674d04dc9db07556c1eca3
4
+ data.tar.gz: dbb4b2d69139ae42581d57404d7c88bd95969deb9544fe006c3afe2a5870f8d1
5
5
  SHA512:
6
- metadata.gz: 9fe4ef8b61035be5b3be5a531e3db9f4bf2b12bf419e00655694a378f2020a627a2f98d497ab9c4db79ca48129f23209a6685f0ae2a513c8c97110b81142cb6b
7
- data.tar.gz: 495601d9aed573a7e2bde43f8a1a85d33209aca29485868c540a9b1fe729092fcb2a7a491c7553ef6544a89909fe278ae6e275d48a705a73ed2ed35fc0109389
6
+ metadata.gz: 03d6a7973c6ae02b6c7c0c859d8f02cb3135e0e0d7d0ad59c96247115f0e7db4c873928aebd3e1c0bbcb715f07c20ee7570cf3f02bbf66debf19a435cf511a7b
7
+ data.tar.gz: 1296b36a4a737dfe4f4718dc9eed2010535851e74361818b8cbf999ead2d87290d8f3340503fa6ae1bf3904e59cc6253d531195eb87b0310976c07afa6f61840
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Waldit
4
+ module Migration
5
+ def create_waldit_table(name = "waldit")
6
+ reversible do |dir|
7
+ dir.up { execute "CREATE TYPE waldit_action AS ENUM ('insert', 'update', 'delete')" }
8
+ dir.down { execute "DROP TYPE waldit_action" }
9
+ end
10
+
11
+ create_table name do |t|
12
+ t.column :action, :waldit_action, null: false
13
+ t.string :table_name, null: false
14
+ t.string :primary_key, null: false
15
+ t.bigint :transaction_id, null: false
16
+ t.decimal :lsn, null: false, precision: 20, scale: 0
17
+ t.timestamptz :commited_at
18
+ t.jsonb :context, null: false, default: {}
19
+ t.jsonb :old, null: true
20
+ t.jsonb :new, null: true
21
+ t.jsonb :diff, null: true
22
+ yield t if block_given?
23
+ end
24
+
25
+ add_index name, [:table_name, :primary_key, :transaction_id], unique: true
26
+ add_index name, [:transaction_id, :lsn]
27
+ add_index name, :commited_at
28
+ add_index name, :context, using: :gin, opclass: :jsonb_path_ops
29
+ end
30
+
31
+ def create_waldit_publication
32
+ reversible do |dir|
33
+ dir.up { execute "CREATE PUBLICATION waldit" }
34
+ dir.down { execute "DROP PUBLICATION waldit" }
35
+ end
36
+ end
37
+
38
+ def add_table_to_waldit(table)
39
+ reversible do |dir|
40
+ dir.up do
41
+ execute "ALTER TABLE #{table} REPLICA IDENTITY FULL"
42
+ execute "ALTER PUBLICATION waldit ADD TABLE #{table}"
43
+ end
44
+ dir.down do
45
+ execute "ALTER PUBLICATION waldit DROP TABLE #{table}"
46
+ execute "ALTER TABLE #{table} REPLICA IDENTITY DEFAULT"
47
+ end
48
+ end
49
+ end
50
+
51
+ def remove_table_from_waldit(table)
52
+ reversible do |dir|
53
+ dir.up do
54
+ execute "ALTER PUBLICATION waldit DROP TABLE #{table}"
55
+ execute "ALTER TABLE #{table} REPLICA IDENTITY DEFAULT"
56
+ end
57
+ dir.down do
58
+ execute "ALTER TABLE #{table} REPLICA IDENTITY FULL"
59
+ execute "ALTER PUBLICATION waldit ADD TABLE #{table}"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -5,11 +5,17 @@ require "rails/railtie"
5
5
  module Waldit
6
6
  class Railtie < Rails::Railtie
7
7
  config.before_configuration do
8
- ActiveRecord::ConnectionAdapters.register(
9
- "postgresqlwaldit",
10
- "Waldit::PostgreSQLAdapter",
11
- "waldit/postgresql_adapter",
12
- )
8
+ ["waldit", "postgresqlwaldit"].each do |adapter_name|
9
+ ActiveRecord::ConnectionAdapters.register(
10
+ adapter_name,
11
+ "Waldit::PostgreSQLAdapter",
12
+ "waldit/postgresql_adapter",
13
+ )
14
+ end
15
+
16
+ require_relative "migration"
17
+ ActiveRecord::Migration.include Waldit::Migration
18
+ ActiveRecord::Schema.include Waldit::Migration
13
19
  end
14
20
  end
15
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Waldit
4
- VERSION = "0.0.7"
4
+ VERSION = "0.0.9"
5
5
  end
data/lib/waldit.rb CHANGED
@@ -51,7 +51,7 @@ module Waldit
51
51
 
52
52
  config.watched_tables = -> table { table != "waldit" }
53
53
 
54
- config.store_changes = -> table { %i[old new diff] }
54
+ config.store_changes = -> table { %i[old new] }
55
55
 
56
56
  config.ignored_columns = -> table { %w[created_at updated_at] }
57
57
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: waldit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rodrigo Navarro
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-08-21 00:00:00.000000000 Z
10
+ date: 2025-08-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: wal
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.3
18
+ version: 0.0.8
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.3
25
+ version: 0.0.8
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activerecord
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -64,6 +64,7 @@ files:
64
64
  - Rakefile
65
65
  - lib/waldit.rb
66
66
  - lib/waldit/context.rb
67
+ - lib/waldit/migration.rb
67
68
  - lib/waldit/postgresql_adapter.rb
68
69
  - lib/waldit/railtie.rb
69
70
  - lib/waldit/record.rb