Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove AirTable code #104

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/models/agreement.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Agreement < DataTable
self.air_table_name = "Information Sharing Agreements"
self.rapid_table_name = :agreements
self.rapid_name_field = :agreement_name

Expand Down
11 changes: 1 addition & 10 deletions app/models/agreement_control_person.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ class << self
def populate
delete_all # Simplest way to ensure records deleted from Airtable do not persist in local database

air_table_data_source? ? populate_from_airtable : populate_from_rapid
end

def populate_from_airtable
Agreement.find_each do |agreement|
(agreement.fields["controllers"] || []).each do |control_person_id|
control_person = ControlPerson.find_by(record_id: control_person_id)
find_or_create_by!(agreement:, control_person:) if control_person.present?
end
end
populate_from_rapid
end

def populate_from_rapid
Expand Down
11 changes: 1 addition & 10 deletions app/models/agreement_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ class << self
def populate
delete_all # Simplest way to ensure records deleted from Airtable do not persist in local database

air_table_data_source? ? populate_from_airtable : populate_from_rapid
end

def populate_from_airtable
Agreement.find_each do |agreement|
(agreement.fields["processors"] || []).each do |processor_id|
processor = Processor.find_by(record_id: processor_id)
find_or_create_by!(agreement:, processor:) if processor.present?
end
end
populate_from_rapid
end

def populate_from_rapid
Expand Down
25 changes: 0 additions & 25 deletions app/models/air_table_base.rb

This file was deleted.

19 changes: 0 additions & 19 deletions app/models/air_table_table.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@

class ApplicationRecord < ActiveRecord::Base
primary_abstract_class

def self.air_table_data_source?
Rails.configuration.data_source == :airtable
end
end
41 changes: 0 additions & 41 deletions app/models/concerns/airtable_data_source.rb

This file was deleted.

4 changes: 0 additions & 4 deletions app/models/control_person.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class ControlPerson < DataTable
self.air_table_name = "Controllers"
self.rapid_table_name = :controllers
self.rapid_name_field = :controller_name

has_many :power_control_people, dependent: :delete_all
has_many :powers, through: :power_control_people

has_many :agreement_control_people, dependent: :delete_all
has_many :agreements, through: :agreement_control_people
end
13 changes: 6 additions & 7 deletions app/models/data_table.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# Classes that inherit from this one store data for each of the main data tables

# For data held in Airtable, the table name used in Airtable will need to be defined
# in the sub-classes. For example, if you want to store the data for an Airtable "Foo bar"
# you can:
# Subclasses of DataTable need to specify the name of the rAPId table the data
# will be pulled from and which field contains the instance name:
# ```
# class FooBar < DataTable
# self.air_table_name = 'Foo bar'
# self.rapid_table_name = :my_model
# self.rapid_name_field = :my_model_name
# end
# ```
#
# With that in place, `FooBar.populate` will pull each of the records from the data source
# and store them in the data_tables table with the type 'FooBar'.
class DataTable < ApplicationRecord
extend AirtableDataSource
extend RapidDataSource

include PgSearch::Model
Expand All @@ -23,7 +22,7 @@ class DataTable < ApplicationRecord
}

class << self
attr_accessor :air_table_name, :rapid_table_name, :rapid_name_field
attr_accessor :rapid_table_name, :rapid_name_field

def populate
raise "Cannot run on root class - DataTable" if self == DataTable
Expand Down Expand Up @@ -55,7 +54,7 @@ def before_populate_save(instance)
end

def data_from_source
air_table_data_source? ? data_from_air_table : data_from_rapid
data_from_rapid
end

private
Expand Down
4 changes: 0 additions & 4 deletions app/models/power.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
class Power < DataTable
self.air_table_name = "Power Disclosure"
self.rapid_table_name = :dea_upload_powers
self.rapid_name_field = :name

has_many :power_agreements
has_many :agreements, through: :power_agreements

has_many :power_control_people
has_many :control_people, through: :power_control_people
end
11 changes: 1 addition & 10 deletions app/models/power_agreement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ class << self
def populate
delete_all # Simplest way to ensure records deleted from Airtable do not persist in local database

air_table_data_source? ? populate_from_airtable : populate_from_rapid
end

def populate_from_airtable
Agreement.find_each do |agreement|
(agreement.fields["Power Disclosure"] || []).each do |power_id|
power = Power.find_by(record_id: power_id)
find_or_create_by!(power:, agreement:) if power.present?
end
end
populate_from_rapid
end

def populate_from_rapid
Expand Down
15 changes: 0 additions & 15 deletions app/models/power_control_person.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/models/processor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Processor < DataTable
self.air_table_name = "Processors"
self.rapid_table_name = :processors
self.rapid_name_field = :processor_name

Expand Down
44 changes: 0 additions & 44 deletions app/services/air_table_api.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/services/update_data_from_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def self.call
Processor,
Power,
PowerAgreement,
PowerControlPerson,
AgreementControlPerson,
AgreementProcessor,
]
Expand Down
2 changes: 1 addition & 1 deletion app/views/control_people/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

<p class="govuk-body"><%= @control_person.fields['description'] %><p>

<%= render 'shared/associations', associations: { agreements: @control_person.agreements, powers: @control_person.powers } %>
<%= render 'shared/associations', associations: { agreements: @control_person.agreements } %>
2 changes: 1 addition & 1 deletion app/views/powers/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
<p class="govuk-body"><%= @power.fields['description'] %></p>


<%= render 'shared/associations', associations: { agreements: @power.agreements, controllers: @power.control_people } %>
<%= render 'shared/associations', associations: { agreements: @power.agreements } %>
3 changes: 0 additions & 3 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class Application < Rails::Application
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

# Data source options are :airtable and :rapid
config.data_source = ENV.fetch("DATA_SOURCE", :rapid).to_sym

config.active_job.queue_adapter = :delayed_job
end
end
18 changes: 18 additions & 0 deletions db/migrate/20250108132452_remove_air_table_specific_models.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class RemoveAirTableSpecificModels < ActiveRecord::Migration[7.0]
def change
drop_table :air_table_bases do |t|
t.string :name
t.string :permission_level
t.string :base_id

t.timestamps
end

drop_table :air_table_tables do |t|
t.string :name
t.string :record_id

t.timestamps
end
end
end
17 changes: 1 addition & 16 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

# rubocop:disable Rails/Output
starting = "Seeding data from #{Rails.configuration.data_source}"
starting = "Seeding data from source"
puts starting # This is sent to STOUT to provide feedback when seeding run at console
Rails.logger.debug starting

Expand Down
7 changes: 0 additions & 7 deletions spec/factories/air_table_bases.rb

This file was deleted.

6 changes: 0 additions & 6 deletions spec/factories/air_table_tables.rb

This file was deleted.

Loading
Loading