harmonia 0.2.3 → 0.2.4

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: 6855db28daa85553fa8479d6dd6217c43ae5c008be01c0b5f92b3154ce183f9c
4
- data.tar.gz: 9b44c5dd79d2a5626053541bcc0a869025e37ecee53c97018eae853a4004d440
3
+ metadata.gz: ff38a571aee521e8a4fd4018627f507e8926e3a64418c86bd746a62bab592ca1
4
+ data.tar.gz: f6932e0ddcbad20fee54dfa868a964b1048824d97ef55b71a965cb6a9d10e7e9
5
5
  SHA512:
6
- metadata.gz: 03056f3bafcbae9a2b69251fe7de63af424fe8bc216c5f18c228b390f47a6baaef8f041b9f1f66ed51f0f0be8ccf1c6e5653649ff55312be10feca45cf71f0c4
7
- data.tar.gz: bf9bde1fd412e5af7b04a5e583fef2441e12ffb20bd55822d33e41f8bfa9e59afce719e5435d6732ee9885492aca376321e9028224c436d6004af7f726337255
6
+ metadata.gz: 7e7c249cf80c9a00c73120d418f683761fffb4bdbbf78b03e6abe56469ee02bc9ecd9e848f7edaa6bfed3b03396890afe35f2c513df22563ffef8b396dd1b89c
7
+ data.tar.gz: 7babd9a72937dfe80c9b3dfe060672c678ac7008c9236f8193e93c37ea435846c9604dd89745a3d4b842505c7ead25451ed03b01a6a0ec652b68dc2e6a7b7f30
data/README.md CHANGED
@@ -169,14 +169,14 @@ class ProductSyncer
169
169
  @total_create_required = filemaker_records.length
170
170
 
171
171
  existing_ids = Product.pluck(:filemaker_id)
172
- filemaker_records.reject { |record| existing_ids.include?(record.record_id) }
172
+ filemaker_records.reject { |record| existing_ids.include?(record.id) }
173
173
  end
174
174
 
175
175
  def records_to_update
176
176
  filemaker_records = Trophonius::Product.all
177
177
 
178
178
  records_needing_update = filemaker_records.select { |fm_record|
179
- pg_record = Product.find_by(filemaker_id: fm_record.record_id)
179
+ pg_record = Product.find_by(filemaker_id: fm_record.id)
180
180
  pg_record && needs_update?(fm_record, pg_record)
181
181
  }
182
182
 
@@ -185,7 +185,7 @@ class ProductSyncer
185
185
  end
186
186
 
187
187
  def records_to_delete
188
- filemaker_ids = Trophonius::Product.all.map(&:record_id)
188
+ filemaker_ids = Trophonius::Product.all.map(&:id)
189
189
  Product.where.not(filemaker_id: filemaker_ids).pluck(:id)
190
190
  end
191
191
 
@@ -393,7 +393,7 @@ module Trophonius
393
393
  # Converts FileMaker record to PostgreSQL attributes
394
394
  def self.to_pg(record)
395
395
  {
396
- filemaker_id: record.record_id,
396
+ filemaker_id: record.id,
397
397
  name: record.field_data['ProductName'],
398
398
  price: record.field_data['Price'].to_f,
399
399
  # ... map other fields
@@ -432,8 +432,8 @@ add_index :products, :filemaker_id, unique: true
432
432
 
433
433
  This column serves as the bridge between your ActiveRecord records and FileMaker records:
434
434
 
435
- - **FileMaker to ActiveRecord**: Stores the FileMaker `record_id` to identify which FileMaker record corresponds to each Rails record
436
- - **ActiveRecord to FileMaker**: Can store the FileMaker `record_id` after creation, or you can use a separate field in FileMaker (like `PostgreSQLID`) to maintain the relationship
435
+ - **FileMaker to ActiveRecord**: Stores the FileMaker `id` to identify which FileMaker record corresponds to each Rails record
436
+ - **ActiveRecord to FileMaker**: Can store the FileMaker `id` after creation, or you can use a separate field in FileMaker (like `PostgreSQLID`) to maintain the relationship
437
437
 
438
438
  **Important Notes**:
439
439
  - The column is indexed with a unique constraint for performance and data integrity
@@ -601,15 +601,15 @@ RSpec.describe ProductSyncer do
601
601
  it 'returns records not in PostgreSQL' do
602
602
  # Mock FileMaker records
603
603
  allow(Trophonius::Product).to receive(:all).and_return([
604
- double(record_id: 1),
605
- double(record_id: 2)
604
+ double(id: 1),
605
+ double(id: 2)
606
606
  ])
607
607
 
608
608
  # Mock existing PostgreSQL records
609
609
  allow(Product).to receive(:pluck).with(:filemaker_id).and_return([1])
610
610
 
611
611
  result = syncer.send(:records_to_create)
612
- expect(result.map(&:record_id)).to eq([2])
612
+ expect(result.map(&:id)).to eq([2])
613
613
  end
614
614
  end
615
615
  end
@@ -81,7 +81,7 @@ class <%= class_name %>ToFileMakerSyncer
81
81
  # pg_ids = <%= class_name %>.pluck(:id).map(&:to_s)
82
82
  # YourTrophoniusModel.all.select { |fm_record|
83
83
  # !pg_ids.include?(fm_record.field_data['PostgreSQLID'])
84
- # }.map(&:record_id)
84
+ # }.map(&:id)
85
85
  []
86
86
  end
87
87
 
@@ -115,11 +115,11 @@ class <%= class_name %>ToFileMakerSyncer
115
115
  end
116
116
 
117
117
  def delete_records
118
- record_ids = records_to_delete
119
- return if record_ids.empty?
118
+ ids = records_to_delete
119
+ return if ids.empty?
120
120
 
121
- record_ids.each do |record_id|
122
- fm_record = YourTrophoniusModel.find(record_id)
121
+ ids.each do |id|
122
+ fm_record = YourTrophoniusModel.find(id)
123
123
  fm_record.destroy
124
124
  rescue Trophonius::RecordNotFoundError
125
125
  # Record already deleted, skip
@@ -3,9 +3,14 @@
3
3
  class <%= class_name %>Syncer
4
4
  attr_accessor :database_connector
5
5
 
6
- def initialize(database_connector)
6
+ def initialize(database_connector, update_only: false)
7
7
  @database_connector = database_connector
8
- @last_synced_on = Harmonia::Sync.last_sync_for('<%= table_name %>', 'FileMaker to ActiveRecord')&.ran_on || (Time.now - 15.year)
8
+ @last_synced_on = if update_only
9
+ Time.now - 100.year
10
+ else
11
+ Harmonia::Sync.last_sync_for('<%= table_name %>', 'FileMaker to ActiveRecord')&.ran_on || (Time.now - 15.year)
12
+ end
13
+ @update_only = update_only
9
14
  @failed_fm_ids = {}
10
15
  @failed_pg_ids = {}
11
16
  end
@@ -30,8 +35,8 @@ class <%= class_name %>Syncer
30
35
 
31
36
  def sync_records(sync_record)
32
37
  updated_count = update_records
33
- created_count = create_records
34
- delete_records
38
+ created_count = @update_only ? 0 : create_records
39
+ delete_records unless @update_only
35
40
 
36
41
  total_synced = created_count + updated_count
37
42
  total_required = (@total_create_required || 0) + (@total_update_required || 0)
@@ -51,7 +56,7 @@ class <%= class_name %>Syncer
51
56
  def records_to_create
52
57
  # TODO: Implement logic to fetch records from FileMaker that need to be created in PostgreSQL
53
58
  # Example:
54
- filemaker_records = FileMaker::<%= class_name %>.where(creation_timestamp: ">= #{@last_synced_on.to_fm}").not
59
+ filemaker_records = FileMaker::<%= class_name %>.where(creation_timestamp: ">= #{@last_synced_on.to_fm}")
55
60
  @total_create_required = filemaker_records.length
56
61
  existing_ids = <%= class_name %>.pluck(:filemaker_id)
57
62
  filemaker_records.reject { |record| existing_ids.include?(record.id) }
@@ -66,7 +71,7 @@ class <%= class_name %>Syncer
66
71
  # Example:
67
72
  filemaker_records = FileMaker::<%= class_name %>.where(modification_timestamp: ">= #{@last_synced_on.to_fm}")
68
73
  records_needing_update = filemaker_records.select { |fm_record|
69
- pg_record = <%= class_name %>.find_by(filemaker_id: fm_record.record_id)
74
+ pg_record = <%= class_name %>.find_by(filemaker_id: fm_record.id)
70
75
  pg_record && needs_update?(fm_record, pg_record)
71
76
  }
72
77
  @total_update_required = records_needing_update.length
@@ -78,7 +83,7 @@ class <%= class_name %>Syncer
78
83
  def records_to_delete
79
84
  # Get all modified FileMaker record IDs
80
85
  filemaker_records = FileMaker::<%= class_name %>.where(modification_timestamp: ">= #{@last_synced_on.to_fm}")
81
- fm_ids = filemaker_records.map(&:record_id)
86
+ fm_ids = filemaker_records.map(&:id)
82
87
 
83
88
  # Find PostgreSQL records whose FileMaker IDs aren't in the modified set
84
89
  # These might have been deleted in FileMaker
@@ -86,13 +91,13 @@ class <%= class_name %>Syncer
86
91
  return [] if fm_ids_no_update_needed.empty?
87
92
 
88
93
  # Query FileMaker to check if these records still exist
89
- possibly_deleted_query = FileMaker::<%= class_name %>.where(record_id: fm_ids_no_update_needed.first)
94
+ possibly_deleted_query = FileMaker::<%= class_name %>.where(id: fm_ids_no_update_needed.first)
90
95
  fm_ids_no_update_needed.count > 1 && fm_ids_no_update_needed[1..].each do |fm_id|
91
- possibly_deleted_query.or(record_id: fm_id)
96
+ possibly_deleted_query.or(id: fm_id)
92
97
  end
93
98
 
94
99
  # Find IDs that exist in PostgreSQL but not in FileMaker (truly deleted)
95
- deleted_fm_ids = fm_ids_no_update_needed - possibly_deleted_query.map(&:record_id)
100
+ deleted_fm_ids = fm_ids_no_update_needed - possibly_deleted_query.map(&:id)
96
101
 
97
102
  # Return PostgreSQL IDs for records with these FileMaker IDs
98
103
  <%= class_name %>.where(filemaker_id: deleted_fm_ids).pluck(:id)
@@ -119,8 +124,8 @@ class <%= class_name %>Syncer
119
124
  <%= class_name %>.create!(attributes)
120
125
  success_count += 1
121
126
  rescue StandardError => e
122
- @failed_fm_ids[trophonius_record.record_id.to_s] = e.message
123
- Rails.logger.error("Failed to create record from FileMaker ID #{trophonius_record.record_id}: #{e.message}")
127
+ @failed_fm_ids[trophonius_record.id.to_s] = e.message
128
+ Rails.logger.error("Failed to create record from FileMaker ID #{trophonius_record.id}: #{e.message}")
124
129
  end
125
130
  end
126
131
 
@@ -137,13 +142,13 @@ class <%= class_name %>Syncer
137
142
  begin
138
143
  pg_attributes = FileMaker::<%= class_name %>.to_pg(trophonius_record)
139
144
 
140
- <%= class_name %>.where(filemaker_id: trophonius_record.record_id).update_all(
145
+ <%= class_name %>.where(filemaker_id: trophonius_record.id).update_all(
141
146
  pg_attributes.merge(updated_at: Time.current)
142
147
  )
143
148
  success_count += 1
144
149
  rescue StandardError => e
145
- @failed_fm_ids[trophonius_record.record_id.to_s] = e.message
146
- Rails.logger.error("Failed to update record from FileMaker ID #{trophonius_record.record_id}: #{e.message}")
150
+ @failed_fm_ids[trophonius_record.id.to_s] = e.message
151
+ Rails.logger.error("Failed to update record from FileMaker ID #{trophonius_record.id}: #{e.message}")
147
152
  end
148
153
  end
149
154
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: harmonia
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kempen Automatisering
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-17 00:00:00.000000000 Z
11
+ date: 2026-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trophonius