Skip to content

Commit

Permalink
Add required constraint to uuid_sample_lims and improve sample indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
stevieing committed Dec 3, 2024
1 parent 268a008 commit be1a7a4
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 37 deletions.
11 changes: 11 additions & 0 deletions db/migrate/20241203115427_add_indexes_to_sample.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddIndexesToSample < ActiveRecord::Migration[7.0]

def change
#id_lims and id_sample_lims should be unique together
add_index :sample, [:id_lims, :id_sample_lims], unique: true

#improve search performance
add_index :sample, :id_lims, unique: false
add_index :sample, :id_sample_lims, unique: false
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddRequiredToUuidSampleLimsToSample < ActiveRecord::Migration[7.0]
def up
# uuid_sample_lims should be required
change_column_null(:sample, :uuid_sample_lims, false)
end

def down
change_column_null(:sample, :uuid_sample_lims, true)
end
end
7 changes: 5 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.0].define(version: 2024_09_19_134424) do
ActiveRecord::Schema[7.0].define(version: 2024_12_03_134455) 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 @@ -304,7 +304,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 "uuid_sample_lims", limit: 36, null: false, comment: "LIMS-specific sample uuid"
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"
Expand Down Expand Up @@ -367,7 +367,10 @@
t.string "dna_source"
t.string "priority_level", comment: "Priority level eg Medium, High etc"
t.index ["accession_number"], name: "sample_accession_number_index"
t.index ["id_lims", "id_sample_lims"], name: "index_sample_on_id_lims_and_id_sample_lims", unique: true
t.index ["id_lims"], name: "index_sample_on_id_lims"
t.index ["id_sample_lims", "id_lims"], name: "index_sample_on_id_sample_lims_and_id_lims", unique: true
t.index ["id_sample_lims"], name: "index_sample_on_id_sample_lims"
t.index ["name"], name: "sample_name_index"
t.index ["sanger_sample_id"], name: "index_sample_on_sanger_sample_id"
t.index ["supplier_name"], name: "index_sample_on_supplier_name"
Expand Down
74 changes: 39 additions & 35 deletions spec/models/sample_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,46 @@
end

context 'without uuid' do
it_behaves_like 'a sample resource'

let(:json) do
{
'id' => '1' * 255.to_i,
'name' => 'name',
'reference_genome' => 'reference genome',
'organism' => 'organism',
'consent_withdrawn' => true,
'accession_number' => 'accession number',
'common_name' => 'common name',
'description' => 'description',
'taxon_id' => 'taxon id',
'father' => 'father',
'mother' => 'mother',
'replicate' => 'replicate',
'ethnicity' => 'ethnicity',
'gender' => 'gender',
'cohort' => 'cohort',
'country_of_origin' => 'country of origin',
'geographical_region' => 'geographical region',
'updated_at' => '2012-03-11 10:22:42',
'created_at' => '2012-03-11 10:22:42',
'sanger_sample_id' => 'sanger sample id',
'control' => true,
'empty_supplier_sample_name' => true,
'supplier_name' => 'supplier name',
'public_name' => 'public name',
'sample_visibility' => 'sample visibility',
'strain' => 'strain',
'updated_by_manifest' => true,
'donor_id' => '11111111-2222-3333-4444-555555555556',
'developmental_stage' => 'Larval: Day 5 ZFS:0000037',
'control_type' => 'positive'
}
it 'should raiser an error if uuid is null' do
expect { create(:sample, uuid_sample_lims: nil) }.to raise_error ActiveRecord::NotNullViolation
end

# it_behaves_like 'a sample resource'

# let(:json) do
# {
# 'id' => '1' * 255.to_i,
# 'name' => 'name',
# 'reference_genome' => 'reference genome',
# 'organism' => 'organism',
# 'consent_withdrawn' => true,
# 'accession_number' => 'accession number',
# 'common_name' => 'common name',
# 'description' => 'description',
# 'taxon_id' => 'taxon id',
# 'father' => 'father',
# 'mother' => 'mother',
# 'replicate' => 'replicate',
# 'ethnicity' => 'ethnicity',
# 'gender' => 'gender',
# 'cohort' => 'cohort',
# 'country_of_origin' => 'country of origin',
# 'geographical_region' => 'geographical region',
# 'updated_at' => '2012-03-11 10:22:42',
# 'created_at' => '2012-03-11 10:22:42',
# 'sanger_sample_id' => 'sanger sample id',
# 'control' => true,
# 'empty_supplier_sample_name' => true,
# 'supplier_name' => 'supplier name',
# 'public_name' => 'public name',
# 'sample_visibility' => 'sample visibility',
# 'strain' => 'strain',
# 'updated_by_manifest' => true,
# 'donor_id' => '11111111-2222-3333-4444-555555555556',
# 'developmental_stage' => 'Larval: Day 5 ZFS:0000037',
# 'control_type' => 'positive'
# }
# end
end

context 'compound samples via JSON' do
Expand Down

0 comments on commit be1a7a4

Please sign in to comment.