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

make lod link index conditional on site for sites, solves #375 #376

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 4 additions & 2 deletions app/models/lod_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#
# Indexes
#
# index_lod_links_on_linkable_type_and_linkable_id (linkable_type,linkable_id)
# index_lod_links_on_source_and_external_id (source,external_id) UNIQUE
# index_lod_links_on_linkable_type_and_linkable_id (linkable_type,linkable_id)
# index_lod_links_on_polymorphic_source_and_external_id (linkable_type,linkable_id,source,external_id) UNIQUE
#
class LodLink < ApplicationRecord
include Turbo::Broadcastable
Expand All @@ -26,6 +26,8 @@ class LodLink < ApplicationRecord
validates :external_id, presence: true, numericality: { only_integer: true }
validates :source, presence: true

validates :source, uniqueness: { scope: [:external_id, :linkable_type, :linkable_id] }

enum status: { pending: "pending", approved: "approved"}

belongs_to :linkable, polymorphic: true
Expand Down
7 changes: 5 additions & 2 deletions app/models/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ def self.wikidata_match_candidates_batch(sites)
next unless site

matches.each do |match|
# Find or create the LOD link for this Wikidata match
site.lod_links.find_or_create_by(source: "Wikidata", external_id: match.qid) do |lod_link|
# Find or create the LOD link for this Wikidata match, scoped by linkable_id and linkable_type
lod_link = site.lod_links.find_or_initialize_by(source: "Wikidata", external_id: match.qid, linkable_type: "Site", linkable_id: site.id)

# Only update and save if the record is new or has changes
if lod_link.new_record? || lod_link.data != { label: match.label, description: match.description }
lod_link.data = {
label: match.label,
description: match.description
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class UpdateIndexOnLodLinksToPolymorphic < ActiveRecord::Migration[7.0]
def change
remove_index :lod_links, name: "index_lod_links_on_source_and_external_id"

add_index :lod_links, [:linkable_type, :linkable_id, :source, :external_id],
unique: true, name: "index_lod_links_on_polymorphic_source_and_external_id"
end
end
51 changes: 49 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.2].define(version: 2024_12_15_102659) do
ActiveRecord::Schema[7.2].define(version: 2024_12_19_092101) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
enable_extension "plpgsql"
Expand Down Expand Up @@ -101,6 +101,17 @@
t.index ["type", "c14_age", "c14_error", "c14_curve"], name: "index_cals_on_type_and_c14_age_and_c14_error_and_c14_curve", unique: true
end

create_table "chronologies", force: :cascade do |t|
t.string "name"
t.string "chronology_type"
t.string "method"
t.string "standardizing_method"
t.string "certainty"
t.jsonb "parameters", default: {}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "citations", force: :cascade do |t|
t.bigint "reference_id"
t.string "citing_type"
Expand All @@ -120,6 +131,40 @@
t.index ["site_id"], name: "index_contexts_on_site_id"
end

create_table "dendros", force: :cascade do |t|
t.bigint "sample_id", null: false
t.string "series_code", null: false
t.string "name", null: false
t.text "description"
t.integer "start_year"
t.integer "end_year"
t.boolean "is_anchored", default: false
t.integer "offset"
t.jsonb "measurements", default: [], null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "project_title"
t.text "project_objective"
t.datetime "project_start_date"
t.datetime "project_end_date"
t.string "object_title"
t.string "object_type"
t.text "object_description"
t.jsonb "object_dimensions", default: {}
t.integer "pith_year"
t.integer "death_year"
t.integer "first_year"
t.integer "last_year"
t.jsonb "wood_completeness", default: {}
t.bigint "chronology_id"
t.jsonb "parameters", default: {}
t.boolean "waney_edge"
t.index ["chronology_id"], name: "index_dendros_on_chronology_id"
t.index ["measurements"], name: "index_dendros_on_measurements", using: :gin
t.index ["sample_id"], name: "index_dendros_on_sample_id"
t.index ["series_code"], name: "index_dendros_on_series_code", unique: true
end

create_table "import_tables", force: :cascade do |t|
t.string "file"
t.datetime "imported_at", precision: nil
Expand All @@ -140,8 +185,8 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "status", default: "pending", null: false
t.index ["linkable_type", "linkable_id", "source", "external_id"], name: "index_lod_links_on_polymorphic_source_and_external_id", unique: true
t.index ["linkable_type", "linkable_id"], name: "index_lod_links_on_linkable_type_and_linkable_id"
t.index ["source", "external_id"], name: "index_lod_links_on_source_and_external_id", unique: true
end

create_table "materials", force: :cascade do |t|
Expand Down Expand Up @@ -366,6 +411,8 @@

add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "dendros", "chronologies"
add_foreign_key "dendros", "samples"
add_foreign_key "import_tables", "users"
add_foreign_key "oauth_access_grants", "oauth_applications", column: "application_id"
add_foreign_key "oauth_access_grants", "users", column: "resource_owner_id"
Expand Down
Loading