Skip to content

Commit

Permalink
add ebi fields to study
Browse files Browse the repository at this point in the history
  • Loading branch information
wendyyang committed Jan 10, 2025
1 parent 76b5559 commit ef8437d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 44 deletions.
7 changes: 7 additions & 0 deletions db/migrate/20250110153629_add_ebi_fields_to_study.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddEbiFieldsToStudy < ActiveRecord::Migration[7.0]
def change
add_column :study, :ebi_library_strategy, :string, default: nil
add_column :study, :ebi_library_source, :string, default: nil
add_column :study, :ebi_library_selection, :string, default: nil
end
end
16 changes: 4 additions & 12 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.0].define(version: 2024_12_11_144506) do
ActiveRecord::Schema[7.0].define(version: 2025_01_10_153629) do
create_table "aliquot", charset: "utf8mb3", collation: "utf8mb3_unicode_ci", force: :cascade do |t|
t.string "id_lims", null: false, comment: "The LIMS system that the aliquot was created in"
t.string "aliquot_uuid", null: false, comment: "The UUID of the aliquot in the LIMS system"
Expand Down Expand Up @@ -465,6 +465,9 @@
t.string "data_deletion_period"
t.string "contaminated_human_data_access_group"
t.string "programme"
t.string "ebi_library_strategy"
t.string "ebi_library_source"
t.string "ebi_library_selection"
t.index ["accession_number"], name: "study_accession_number_index"
t.index ["id_lims", "id_study_lims"], name: "study_id_lims_id_study_lims_index", unique: true
t.index ["id_study_lims"], name: "index_study_on_id_study_lims"
Expand All @@ -482,17 +485,6 @@
t.index ["id_study_tmp"], name: "study_users_study_fk"
end

add_foreign_key "bmap_flowcell", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "fk_bmap_flowcell_to_sample"
add_foreign_key "bmap_flowcell", "study", column: "id_study_tmp", primary_key: "id_study_tmp", name: "fk_bmap_flowcell_to_study"
add_foreign_key "flgen_plate", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "flgen_plate_sample_fk"
add_foreign_key "flgen_plate", "study", column: "id_study_tmp", primary_key: "id_study_tmp", name: "flgen_plate_study_fk"
add_foreign_key "iseq_flowcell", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "iseq_flowcell_sample_fk"
add_foreign_key "iseq_flowcell", "study", column: "id_study_tmp", primary_key: "id_study_tmp", name: "iseq_flowcell_study_fk"
add_foreign_key "oseq_flowcell", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "fk_oseq_flowcell_to_sample"
add_foreign_key "oseq_flowcell", "study", column: "id_study_tmp", primary_key: "id_study_tmp", name: "fk_oseq_flowcell_to_study"
add_foreign_key "pac_bio_run", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "fk_pac_bio_run_to_sample"
add_foreign_key "pac_bio_run", "study", column: "id_study_tmp", primary_key: "id_study_tmp", name: "fk_pac_bio_run_to_study"
add_foreign_key "qc_result", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "fk_qc_result_to_sample"
add_foreign_key "samples_extraction_activity", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp"
add_foreign_key "stock_resource", "sample", column: "id_sample_tmp", primary_key: "id_sample_tmp", name: "fk_stock_resource_to_sample"
add_foreign_key "stock_resource", "study", column: "id_study_tmp", primary_key: "id_study_tmp", name: "fk_stock_resource_to_study"
Expand Down
33 changes: 1 addition & 32 deletions db/views_schema.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1 @@
mlwh_wh_db = Rails.configuration.view_schema_mlwh_db
event_wh_db = Rails.configuration.view_schema_ewh_db

ViewsSchema.update_view(
'cherrypicked_samples',
<<~SQL.squish
SELECT mlwh_sample.description AS 'root_sample_id', mlwh_stock_resource.labware_human_barcode AS 'plate_barcode',
mlwh_sample.phenotype AS 'phenotype', mlwh_stock_resource.labware_coordinate AS 'coordinate',
mlwh_sample.created AS 'created', 'Tecan' as 'robot_type'
FROM #{mlwh_wh_db}.`sample` AS mlwh_sample
JOIN #{mlwh_wh_db}.stock_resource AS mlwh_stock_resource ON (mlwh_sample.id_sample_tmp = mlwh_stock_resource.id_sample_tmp)
JOIN #{event_wh_db}.subjects mlwh_events_subjects ON (mlwh_events_subjects.friendly_name = mlwh_sample.sanger_sample_id)
JOIN #{event_wh_db}.roles mlwh_events_roles ON (mlwh_events_roles.subject_id = mlwh_events_subjects.id)
JOIN #{event_wh_db}.events mlwh_events_events ON (mlwh_events_roles.event_id = mlwh_events_events.id)
JOIN #{event_wh_db}.event_types mlwh_events_event_types ON (mlwh_events_events.event_type_id = mlwh_events_event_types.id)
WHERE mlwh_events_event_types.key = 'cherrypick_layout_set'
UNION
SELECT mlwh_sample.description AS 'root_sample_id', mlwh_lh_sample.plate_barcode AS 'plate_barcode',
mlwh_sample.phenotype AS 'phenotype', mlwh_lh_sample.coordinate AS 'coordinate', mlwh_sample.created AS 'created',
IF(mlwh_events_event_types.key="lh_beckman_cp_destination_created","Beckman","Biosero") AS 'robot_type'
FROM #{mlwh_wh_db}.sample as mlwh_sample
JOIN #{mlwh_wh_db}.lighthouse_sample AS mlwh_lh_sample ON (mlwh_sample.uuid_sample_lims = mlwh_lh_sample.lh_sample_uuid)
JOIN #{event_wh_db}.subjects AS mlwh_events_subjects ON (mlwh_events_subjects.uuid = UNHEX(REPLACE(mlwh_lh_sample.lh_sample_uuid, '-', '')))
JOIN #{event_wh_db}.roles AS mlwh_events_roles ON (mlwh_events_roles.subject_id = mlwh_events_subjects.id)
JOIN #{event_wh_db}.events AS mlwh_events_events ON (mlwh_events_events.id = mlwh_events_roles.event_id)
JOIN #{event_wh_db}.event_types AS mlwh_events_event_types ON (mlwh_events_event_types.id = mlwh_events_events.event_type_id)
WHERE mlwh_events_event_types.key IN (
'lh_beckman_cp_destination_created', 'lh_biosero_cp_destination_plate_completed', 'lh_biosero_cp_destination_plate_partial_completed',
'lh_biosero_cp_error_recovered_destination_plate_completed','lh_biosero_cp_error_recovered_destination_plate_partial_completed'
)
SQL
)
# This is an automatically generated file by rake:db:views:dump_schema

0 comments on commit ef8437d

Please sign in to comment.