Skip to content

Commit

Permalink
up sampled_indivuals_taxa and replacing taxons with taxa
Browse files Browse the repository at this point in the history
  • Loading branch information
oolonek committed Feb 12, 2024
1 parent 816c9e4 commit 281b15f
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- UP MIGRATION
CREATE TABLE samples (
id SERIAL PRIMARY KEY,
taxon_id INTEGER NOT NULL REFERENCES taxons(id) ON DELETE CASCADE,
taxon_id INTEGER NOT NULL REFERENCES taxa(id) ON DELETE CASCADE,
sample_type_id INTEGER NOT NULL REFERENCES sample_types(id) ON DELETE CASCADE,
derived_from INTEGER REFERENCES samples(id) ON DELETE SET NULL,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE IF EXISTS taxons;
DROP TABLE IF EXISTS taxa;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Your SQL goes here
CREATE TABLE taxons (
CREATE TABLE taxa (
id SERIAL PRIMARY KEY,
name VARCHAR(80) NOT NULL,
description VARCHAR(255) NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Your SQL goes here
-- A migration to create the sample_taxa table.
-- This is a N to M relationship between samples and taxa.
-- A sample can be associated to no or more taxa, and a taxon can be found in multiple samples.
--
CREATE TABLE sample_taxa (
sample_id INTEGER NOT NULL REFERENCES samples(id) ON DELETE CASCADE,
taxon_id INTEGER NOT NULL REFERENCES taxa(id) ON DELETE CASCADE,
PRIMARY KEY (sample_id, taxon_id)
);

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Your SQL goes here
-- A migration to create the sampled_individual_taxa table.
-- This is a N to M relationship between sampled_individuals and taxa.
-- An individual can be associated to no or more taxa, and a taxon can be found in multiple individuals.
--
CREATE TABLE sampled_individual_taxa (
sampled_individual_id INTEGER NOT NULL REFERENCES sampled_individuals(id) ON DELETE CASCADE,
taxon_id INTEGER NOT NULL REFERENCES taxa(id) ON DELETE CASCADE,
PRIMARY KEY (sampled_individual_id, taxon_id)
);
```
2 changes: 1 addition & 1 deletion web/backend/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod spectra;
mod spectra_collection;
mod task_type;
mod tasks;
mod taxons;
mod taxa;
mod users;

// models.rs
Expand Down
2 changes: 1 addition & 1 deletion web/backend/src/models/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ diesel::table! {
}

diesel::table! {
taxons (id) {
taxa (id) {
id -> Int4,
name -> Varchar,
description -> Text,
Expand Down
4 changes: 2 additions & 2 deletions web/backend/src/models/taxons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};

// Define the Taxon model
#[derive(Debug, Serialize, Deserialize, Queryable, Identifiable)]
#[diesel(table_name = taxons)]
#[diesel(table_name = taxa)]
pub struct Taxon {
pub id: i32,
pub name: String,
Expand All @@ -16,7 +16,7 @@ pub struct Taxon {

// Define the Taxon model for insert
#[derive(Debug, Insertable)]
#[diesel(table_name = taxons)]
#[diesel(table_name = taxa)]
pub struct NewTaxon<'a> {
pub name: &'a str,
pub description: &'a str,
Expand Down

0 comments on commit 281b15f

Please sign in to comment.