From 7acfe6a5841181cda87135e641f3f0096f5517e3 Mon Sep 17 00:00:00 2001 From: Stephen <519327+stevieing@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:07:52 +0100 Subject: [PATCH 1/2] Increase size of id_sample_lims column in sample table --- ...size_of_id_sample_lims_column_in_sample.rb | 9 +++++ db/schema.rb | 6 ++-- db/views_schema.rb | 33 +------------------ spec/models/sample_spec.rb | 2 +- 4 files changed, 14 insertions(+), 36 deletions(-) create mode 100644 db/migrate/20240919134424_increase_size_of_id_sample_lims_column_in_sample.rb diff --git a/db/migrate/20240919134424_increase_size_of_id_sample_lims_column_in_sample.rb b/db/migrate/20240919134424_increase_size_of_id_sample_lims_column_in_sample.rb new file mode 100644 index 00000000..db52756f --- /dev/null +++ b/db/migrate/20240919134424_increase_size_of_id_sample_lims_column_in_sample.rb @@ -0,0 +1,9 @@ +class IncreaseSizeOfIdSampleLimsColumnInSample < ActiveRecord::Migration[7.0] + def up + change_column :sample, :id_sample_lims, :string, limit: 255 + end + + def down + change_column :sample, :id_sample_lims, :string, limit: 20 + end +end diff --git a/db/schema.rb b/db/schema.rb index 946daac8..c1190ee9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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_08_14_125331) do +ActiveRecord::Schema[7.0].define(version: 2024_09_19_134424) 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" @@ -305,7 +305,7 @@ create_table "sample", primary_key: "id_sample_tmp", id: { type: :integer, unsigned: true }, charset: "utf8mb3", collation: "utf8mb3_unicode_ci", force: :cascade do |t| t.string "id_lims", limit: 10, null: false, comment: "LIM system identifier, e.g. CLARITY-GCLP, SEQSCAPE" t.string "uuid_sample_lims", limit: 36, comment: "LIMS-specific sample uuid" - t.string "id_sample_lims", limit: 20, null: false, comment: "LIMS-specific sample identifier" + t.string "id_sample_lims", null: false, comment: "LIMS-specific sample identifier" t.datetime "last_updated", precision: nil, null: false, comment: "Timestamp of last update" t.datetime "recorded_at", precision: nil, null: false, comment: "Timestamp of warehouse update" t.datetime "deleted_at", precision: nil, comment: "Timestamp of sample deletion" @@ -463,7 +463,7 @@ t.string "programme" 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", unique: false + t.index ["id_study_lims"], name: "index_study_on_id_study_lims" t.index ["name"], name: "study_name_index" t.index ["uuid_study_lims"], name: "study_uuid_study_lims_index", unique: true end diff --git a/db/views_schema.rb b/db/views_schema.rb index 45349fdd..28a7ac3d 100644 --- a/db/views_schema.rb +++ b/db/views_schema.rb @@ -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 diff --git a/spec/models/sample_spec.rb b/spec/models/sample_spec.rb index 0ce9a50d..33c66c9e 100644 --- a/spec/models/sample_spec.rb +++ b/spec/models/sample_spec.rb @@ -28,7 +28,7 @@ let(:json) do { - 'id' => 1, + 'id' => '1' * 255.to_i, 'name' => 'name', 'reference_genome' => 'reference genome', 'organism' => 'organism', From f3374a4aa4699661f0de845deda84e0da3c39c12 Mon Sep 17 00:00:00 2001 From: Stephen <519327+stevieing@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:53:05 +0100 Subject: [PATCH 2/2] Reverted views schema --- db/views_schema.rb | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/db/views_schema.rb b/db/views_schema.rb index 28a7ac3d..d5db34f0 100644 --- a/db/views_schema.rb +++ b/db/views_schema.rb @@ -1 +1,32 @@ -# This is an automatically generated file by rake:db:views:dump_schema +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 +) \ No newline at end of file