# frozen_string_literal: true

# Table to hold information from the Lighthouse plate maps. Populated by the Lighthouse app.
# The primary database which it exposes information from is the Lighthouse MongoDB database.
class CreateLighthouseSample < ActiveRecord::Migration
  def change
    create_table :lighthouse_sample do |t|
      t.string :mongodb_id, comment: 'Auto-generated id from MongoDB'
      t.string :root_sample_id, null: false, comment: 'Id for this sample provided by the Lighthouse lab'
      t.string :cog_uk_id, comment: 'Consortium-wide id, generated by Sanger on import to LIMS'
      t.string :rna_id, null: false, comment: 'Lighthouse lab-provided id made up of plate barcode and well'
      t.string :plate_barcode, comment: 'Barcode of plate sample arrived in, from rna_id'
      t.string :coordinate, comment: 'Well position from plate sample arrived in, from rna_id'
      t.string :result, null: false, comment: 'Covid-19 test result from the Lighthouse lab'
      t.string :date_tested_string, comment: 'When the covid-19 test was carried out by the Lighthouse lab'
      t.datetime :date_tested, comment: 'date_tested_string in date format'
      t.string :source, comment: 'Lighthouse centre that the sample came from'
      t.string :lab_id, comment: 'Id of the lab, within the Lighthouse centre'
      t.datetime :created_at, comment: 'When this record was inserted'
      t.datetime :updated_at, comment: 'When this record was last updated'

      t.index %i[root_sample_id rna_id result], unique: true # same uniqueness criteria as in MongoDB
      t.index :mongodb_id, unique: true
      t.index :date_tested # reporting will often be by date tested, so index for faster queries
    end
  end
end
