canvas_sync 0.27.1.beta2 → 0.27.1.beta3

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: 50549b542e0425d35fc1effb9f505ce4a1d75e1517eb1e32b2a8bbffb00ee7de
4
- data.tar.gz: 6442ed0b393e7e234984eb78dced6ef82aa388767ffba09f483de78b411e4ff5
3
+ metadata.gz: 569b75049c7212d44318075a8d2ff1680cbd0d7d68a5446a0b94ec09718eef95
4
+ data.tar.gz: 911fd5399e951f4badf0dd77baf78badb8e930606e6f031bbda67eee79e05e72
5
5
  SHA512:
6
- metadata.gz: 7c5c55806050f7fb686d7331d39b611def2783c0f9db57c6437cea99df30d69038671b3fc9b7b1bc9e4c4065e4a1ce8eb164db92cf4a40399c823e2d1e0f28a7
7
- data.tar.gz: f743ab5316387d8a0519e29d8675e2246ace7cefdb8d9acff9a5d2ed42e3cc0fce55287a2c779105f7b51502331aac3cb75bb900a38096247626b57274c92c47
6
+ metadata.gz: 1fc6af99ed8eb1e3f9c4b5be559beff9e390b9913c966641c5fa0ef4e77714494bc33b96b174d4c0b332bf1e288a566b9346569932e52760a7a501b520e65a57
7
+ data.tar.gz: b2ad6cbeb8b979ea843fab8ee161a4b7acc82b620fee99467284ff79e150e2625913c4797d057d76e253eb576e85c0c8e4368f9028a0660fcc2b80bfb29ec132
@@ -1,13 +1,12 @@
1
1
  module CanvasSync
2
2
  module Jobs::BetaCleanup
3
3
  class DeleteTempTablesJob < CanvasSync::Job
4
-
5
4
  def perform(options = {})
6
5
  tables = options[:models] || []
7
6
  return if tables.empty?
8
7
 
9
8
  tables.each do |table_name|
10
- ActiveRecord::Base.connection.drop_table(table_name, if_exists: true)
9
+ ActiveRecord::Base.connection.drop_table("beta_#{table_name}", if_exists: true)
11
10
  end
12
11
  end
13
12
  end
@@ -1,3 +1,3 @@
1
1
  module CanvasSync
2
- VERSION = "0.27.1.beta2".freeze
2
+ VERSION = "0.27.1.beta3".freeze
3
3
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CanvasSync::Jobs::BetaCleanup::CreateTempTablesJob do
4
+ describe "#perform" do
5
+ it "creates a beta_<table> for each model with the records with an updated_at after the updated_after param " do
6
+ MODELS_TO_SYNC = %w[accounts courses enrollments users]
7
+
8
+ MODELS_TO_SYNC.each do |table_name|
9
+ model = table_name.singularize.to_sym
10
+ FactoryBot.create_list(model, 3, updated_at: 4.weeks.ago)
11
+ FactoryBot.create_list(model, 2, updated_at: 1.week.ago)
12
+ end
13
+
14
+ described_class.new.perform({ models: MODELS_TO_SYNC, updated_after: 2.weeks.ago })
15
+ beta_tables = MODELS_TO_SYNC.map { |table_name| "beta_#{table_name}" }
16
+ expect(ActiveRecord::Base.connection.tables & beta_tables).to match_array(beta_tables)
17
+ expect(beta_tables.all? { |table_name| ActiveRecord::Base.connection.exec_query("SELECT COUNT(*) FROM #{table_name}").rows.flatten.first == 2 }).to be true
18
+ # original tables should no longer have the records that were moved to the beta tables
19
+ expect(MODELS_TO_SYNC.all? { |table_name| ActiveRecord::Base.connection.exec_query("SELECT COUNT(*) FROM #{table_name}").rows.flatten.first == 3 }).to be true
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CanvasSync::Jobs::BetaCleanup::DeleteRelatedRecordsJob do
4
+ describe "#perform" do
5
+ let(:models_to_sync) { %w[accounts] }
6
+ let(:conn) { ActiveRecord::Base.connection }
7
+
8
+ before(:each) do
9
+ @accounts = FactoryBot.create_list(:account, 3, updated_at: 1.week.ago)
10
+ @records_to_readd = @accounts[0..1]
11
+ CanvasSync::Jobs::BetaCleanup::CreateTempTablesJob.new.perform({ models: models_to_sync, updated_after: 2.weeks.ago })
12
+ # we pretend a sync happens, which re-adds 2/3 of the previous records
13
+ Account.create!(@records_to_readd.map(&:attributes))
14
+ # This means that records[2] should have its association deleted in any LTI specific tables via its foreign key
15
+ end
16
+
17
+ it "deletes records in associated tables via their foreign key" do
18
+ conn.exec_query(<<~SQL)
19
+ CREATE TABLE purchases (
20
+ id SERIAL PRIMARY KEY,
21
+ canvas_account_id INTEGER
22
+ )
23
+ SQL
24
+ conn.exec_query(<<~SQL)
25
+ INSERT INTO purchases (canvas_account_id) VALUES (#{@accounts[0].canvas_id}), (#{@accounts[1].canvas_id}), (#{@accounts[2].canvas_id});
26
+ SQL
27
+ # the record in this table with canvas_account_id = 3 should be deleted (records[2])
28
+ described_class.new.perform({ models: models_to_sync })
29
+ expect(conn.exec_query("SELECT canvas_account_id FROM purchases").rows.flatten).to match_array(@records_to_readd.map(&:canvas_id))
30
+ end
31
+
32
+ # BACKWARD COMPABILITY WITH THE ID COLUMN
33
+ # In newer versions of CanvasSync, tables no longer have the "id" primary key and only have the "canvas_id" column
34
+ # Older apps may still have tables with an "id" primary key
35
+ context "when the table has an 'id' column as a primary key instead of 'canvas_id'" do
36
+ it "deletes the records via the 'account_id' foreign key" do
37
+ conn.execute(<<~SQL)
38
+ ALTER TABLE accounts ADD COLUMN id SERIAL PRIMARY KEY;
39
+ ALTER TABLE beta_accounts ADD COLUMN id SERIAL PRIMARY KEY;
40
+ SQL
41
+ conn.exec_query(<<~SQL)
42
+ CREATE TABLE customers (
43
+ id SERIAL PRIMARY KEY,
44
+ account_id INTEGER
45
+ )
46
+ SQL
47
+ conn.exec_query(<<~SQL)
48
+ INSERT INTO customers (account_id) VALUES (1), (2), (3);
49
+ SQL
50
+ described_class.new.perform({ models: models_to_sync })
51
+ expect(conn.exec_query("SELECT account_id FROM customers").rows.flatten).to match_array([1, 2])
52
+ end
53
+ end
54
+ end
55
+
56
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CanvasSync::Jobs::BetaCleanup::DeleteTempTablesJob do
4
+ describe '#perform' do
5
+ let(:conn) { ActiveRecord::Base.connection }
6
+ let(:models_to_sync) { %w[accounts courses]}
7
+
8
+ before do
9
+ CanvasSync::Jobs::BetaCleanup::CreateTempTablesJob.new.perform({ models: models_to_sync })
10
+ end
11
+
12
+ it 'deletes the specified tables' do
13
+ expect(models_to_sync.all? { |table_name| conn.data_source_exists?("beta_#{table_name}") }).to be true
14
+ described_class.new.perform({ models: models_to_sync })
15
+ expect(models_to_sync.all? { |table_name| conn.data_source_exists?("beta_#{table_name}") }).to be false
16
+ expect(models_to_sync.all? { |table_name| conn.data_source_exists?(table_name) }).to be true
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canvas_sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.1.beta2
4
+ version: 0.27.1.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Instructure CustomDev
@@ -570,6 +570,9 @@ files:
570
570
  - lib/canvas_sync/sidekiq_job.rb
571
571
  - lib/canvas_sync/version.rb
572
572
  - spec/canvas_sync/canvas_sync_spec.rb
573
+ - spec/canvas_sync/jobs/beta_cleanup/create_temp_tables_spec.rb
574
+ - spec/canvas_sync/jobs/beta_cleanup/delete_related_records_spec.rb
575
+ - spec/canvas_sync/jobs/beta_cleanup/delete_temp_tables_spec.rb
573
576
  - spec/canvas_sync/jobs/canvas_process_waiter_spec.rb
574
577
  - spec/canvas_sync/jobs/job_spec.rb
575
578
  - spec/canvas_sync/jobs/report_starter_spec.rb
@@ -763,6 +766,9 @@ specification_version: 4
763
766
  summary: Gem for generating Canvas models and migrations and syncing data from Canvas
764
767
  test_files:
765
768
  - spec/canvas_sync/canvas_sync_spec.rb
769
+ - spec/canvas_sync/jobs/beta_cleanup/create_temp_tables_spec.rb
770
+ - spec/canvas_sync/jobs/beta_cleanup/delete_related_records_spec.rb
771
+ - spec/canvas_sync/jobs/beta_cleanup/delete_temp_tables_spec.rb
766
772
  - spec/canvas_sync/jobs/canvas_process_waiter_spec.rb
767
773
  - spec/canvas_sync/jobs/job_spec.rb
768
774
  - spec/canvas_sync/jobs/report_starter_spec.rb