-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/observation-multiple-evidences' into staging
- Loading branch information
Showing
23 changed files
with
289 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Purpose to use with paper_trail history, to get the previous version of some attributes | ||
module ObservationOldAttributes | ||
extend ActiveSupport::Concern | ||
|
||
EVIDENCE_TYPE_V0 = { | ||
"Government Documents" => 0, "Company Documents" => 1, "Photos" => 2, | ||
"Testimony from local communities" => 3, "Other" => 4, "Evidence presented in the report" => 5, | ||
"Maps" => 6 | ||
}.freeze | ||
|
||
included do | ||
attr_accessor :evidence_type_v0 | ||
end | ||
|
||
def evidence_type | ||
return EVIDENCE_TYPE_V0.key(evidence_type_v0) if evidence_type_v0.present? | ||
|
||
super | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
db/migrate/20231222154005_create_observation_document_observations.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class CreateObservationDocumentObservations < ActiveRecord::Migration[7.0] | ||
def up | ||
create_table :observation_documents_observations do |t| | ||
t.belongs_to :observation_document, foreign_key: {on_delete: :cascade}, index: {name: "observation_documents_observations_doc_index"}, null: false | ||
t.belongs_to :observation, foreign_key: {on_delete: :cascade}, index: {name: "observation_documents_observations_obs_index"}, null: false | ||
t.index [:observation_document_id, :observation_id], unique: true, name: "observation_documents_observations_double_index" | ||
t.timestamps | ||
end | ||
|
||
query = <<-SQL | ||
INSERT INTO observation_documents_observations (observation_document_id, observation_id, created_at, updated_at) | ||
SELECT | ||
od.id, o.id, NOW(), NOW() | ||
FROM | ||
observation_documents od JOIN observations o ON od.observation_id = o.id | ||
SQL | ||
execute(query) | ||
|
||
remove_reference :observation_documents, :observation | ||
end | ||
|
||
def down | ||
add_reference :observation_documents, :observation, foreign_key: true, index: true | ||
|
||
query = <<-SQL | ||
UPDATE observation_documents SET observation_id = odo.observation_id | ||
FROM (SELECT DISTINCT ON (observation_document_id) observation_document_id, observation_id FROM observation_documents_observations) odo | ||
WHERE observation_documents.id = odo.observation_document_id | ||
SQL | ||
execute(query) | ||
|
||
drop_table :observation_documents_observations | ||
end | ||
end |
Oops, something went wrong.