From 4332597792fec8658723c661cd638d3856313d81 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Thu, 7 May 2015 08:30:42 -0700 Subject: [PATCH 1/5] DBSchema changes and initial layour of the patch --- qiita_db/support_files/patches/24.sql | 30 + qiita_db/support_files/qiita-db.dbs | 64 +- qiita_db/support_files/qiita-db.html | 1140 +++++++++++++------------ 3 files changed, 634 insertions(+), 600 deletions(-) create mode 100644 qiita_db/support_files/patches/24.sql diff --git a/qiita_db/support_files/patches/24.sql b/qiita_db/support_files/patches/24.sql new file mode 100644 index 000000000..21972c077 --- /dev/null +++ b/qiita_db/support_files/patches/24.sql @@ -0,0 +1,30 @@ +-- May 6, 2015 +-- We attach the prep template directly to the study. The raw data is no longer +-- attached to the study directly, the prep template point to them. This will +-- make the RawData to be effectively just a container for the raw files, +-- which is how it was acting previously. + +CREATE TABLE qiita.study_prep_template ( + study_id bigint NOT NULL, + prep_template_id bigint NOT NULL, + CONSTRAINT idx_study_raw_data PRIMARY KEY ( study_id, prep_template_id ) + ) ; + +CREATE INDEX idx_study_prep_template_0 ON qiita.study_prep_template ( study_id ) ; + +CREATE INDEX idx_study_prep_template_1 ON qiita.study_prep_template ( prep_template_id ) ; + +COMMENT ON TABLE qiita.study_prep_template IS 'links study to its prep templates'; + +ALTER TABLE qiita.study_prep_template ADD CONSTRAINT fk_study_prep_template_study FOREIGN KEY ( study_id ) REFERENCES qiita.study( study_id ) ; + +ALTER TABLE qiita.study_prep_template ADD CONSTRAINT fk_study_prep_template_pt FOREIGN KEY ( prep_template_id ) REFERENCES qiita.prep_template( prep_template_id ) ; + +-- Connect the existing prep templates in the system with their studies +WITH pt_st AS (SELECT prep_template_id, study_id + FROM qiita.prep_template + JOIN qiita.study_raw_data USING (raw_data_id)) + + +DROP TABLE qiita.study_raw_data; + diff --git a/qiita_db/support_files/qiita-db.dbs b/qiita_db/support_files/qiita-db.dbs index 835b5a32f..3529e941d 100644 --- a/qiita_db/support_files/qiita-db.dbs +++ b/qiita_db/support_files/qiita-db.dbs @@ -747,9 +747,6 @@ - - - @@ -1340,6 +1337,27 @@ Controlled Vocabulary]]> + + links study to its prep templates + + + + + + + + + + + + + + + + + + +
@@ -1380,24 +1398,6 @@ Controlled Vocabulary]]>
- - links study to its raw data - - - - - - - - - - - - - - - -
Required info for each sample. One row is one sample. @@ -1522,7 +1522,6 @@ Controlled Vocabulary]]> - @@ -1540,17 +1539,12 @@ Controlled Vocabulary]]> - - - - - @@ -1558,9 +1552,7 @@ Controlled Vocabulary]]> - - @@ -1582,8 +1574,16 @@ Controlled Vocabulary]]> - - + + + + + + + + + + analysis tables @@ -1610,7 +1610,7 @@ Controlled Vocabulary]]> - + diff --git a/qiita_db/support_files/qiita-db.html b/qiita_db/support_files/qiita-db.html index 57620ee08..f1c54f209 100644 --- a/qiita_db/support_files/qiita-db.html +++ b/qiita_db/support_files/qiita-db.html @@ -268,9 +268,9 @@ - -Group_study - + +Group_study + @@ -362,7 +362,7 @@ analysis_users references qiita_user ( email ) email + analysis_users references qiita_user ( email )' style='fill:#a1a0a0;'>email Foreign Key fk_study_preprocessed_data study_preprocessed_data references study ( study_id ) @@ -382,17 +382,7 @@ study_users references qiita_user ( email ) email - Foreign Key fk_study_raw_data_study - study_raw_data references study ( study_id ) - -study_id - Foreign Key fk_study_raw_data_raw_data - study_raw_data references raw_data ( raw_data_id ) - -raw_data_id + study_users references qiita_user ( email )' style='fill:#a1a0a0;'>email Foreign Key fk_processed_data_filepath processed_filepath references processed_data ( processed_data_id ) @@ -407,11 +397,11 @@ logging references severity ( severity_id ) severity_id + logging references severity ( severity_id )' style='fill:#a1a0a0;'>severity_id Foreign Key fk_study_processed_data study_processed_data references study ( study_id ) -study_id Foreign Key fk_study_processed_data_0 study_processed_data references processed_data ( processed_data_id ) @@ -432,11 +422,11 @@ preprocessed_filepath references preprocessed_data ( preprocessed_data_id ) preprocessed_data_id + preprocessed_filepath references preprocessed_data ( preprocessed_data_id )' style='fill:#a1a0a0;'>preprocessed_data_id Foreign Key fk_preprocessed_filepath_0 preprocessed_filepath references filepath ( filepath_id ) -filepath_id Foreign Key fk_analysis_filepath analysis_filepath references analysis ( analysis_id ) @@ -482,37 +472,7 @@ qiita_user references user_level ( user_level_id ) user_level_id - Foreign Key fk_prep_columns_prep_template - prep_columns references prep_template ( prep_template_id ) - -prep_template_id - Foreign Key fk_raw_filepath - raw_filepath references filepath ( filepath_id ) - -filepath_id - Foreign Key fk_raw_filepath_0 - raw_filepath references raw_data ( raw_data_id ) - -raw_data_id - Foreign Key fk_prep_template_data_type - prep_template references data_type ( data_type_id ) - -data_type_id - Foreign Key fk_prep_template_raw_data - prep_template references raw_data ( raw_data_id ) - -raw_data_id - Foreign Key fk_raw_data_filetype - raw_data references filetype ( filetype_id ) - -filetype_id + qiita_user references user_level ( user_level_id )' style='fill:#a1a0a0;'>user_level_id Foreign Key fk_job_function job references command ( command_id ) @@ -562,17 +522,7 @@ study_environmental_package references environmental_package ( environmental_package_name ) environmental_package_name - Foreign Key fk_filepath_id - prep_template_filepath references filepath ( filepath_id ) - -filepath_id - Foreign Key fk_prep_template_id - prep_template_filepath references prep_template ( prep_template_id ) - -prep_template_id + study_environmental_package references environmental_package ( environmental_package_name )' style='fill:#a1a0a0;'>environmental_package_name Foreign Key fk_study_id sample_template_filepath references study ( study_id ) @@ -582,22 +532,22 @@ sample_template_filepath references filepath ( filepath_id ) filepath_id - Foreign Key fk_prep_template_id - prep_template_preprocessed_data references prep_template ( prep_template_id ) + sample_template_filepath references filepath ( filepath_id )' style='fill:#a1a0a0;'>filepath_id + Foreign Key fk_preprocessed_data + preprocessed_data references data_type ( data_type_id ) -prep_template_id - Foreign Key fk_prep_template_preprocessed_data - prep_template_preprocessed_data references preprocessed_data ( preprocessed_data_id ) - -preprocessed_data_id +data_type_id Foreign Key fk_reference_sequence_filepath reference references filepath ( sequence_filepath -> filepath_id ) sequence_filepath + reference references filepath ( sequence_filepath -> filepath_id )' style='fill:#a1a0a0;'>sequence_filepath + Foreign Key fk_reference_taxonomy_filepath + reference references filepath ( taxonomy_filepath -> filepath_id ) + +taxonomy_filepath Foreign Key fk_processed_params_sortmerna processed_params_sortmerna references reference ( reference_id ) @@ -667,7 +617,7 @@ study_pmid references study ( study_id ) study_id + study_pmid references study ( study_id )' style='fill:#a1a0a0;'>study_id Foreign Key fk_study_user study references qiita_user ( email ) @@ -687,11 +637,11 @@ study references study_person ( principal_investigator_id -> study_person_id ) principal_investigator_id + study references study_person ( principal_investigator_id -> study_person_id )' style='fill:#a1a0a0;'>principal_investigator_id Foreign Key fk_study_timeseries_type study references timeseries_type ( timeseries_type_id ) -timeseries_type_id Foreign Key fk_study study references portal_type ( portal_type_id ) @@ -722,26 +672,81 @@ analysis_sample references processed_data ( processed_data_id ) processed_data_id + analysis_sample references processed_data ( processed_data_id )' style='fill:#a1a0a0;'>processed_data_id Foreign Key fk_analysis_sample analysis_sample references study_sample ( sample_id ) sample_id + analysis_sample references study_sample ( sample_id )' style='fill:#a1a0a0;'>sample_id Foreign Key fk_required_sample_info_study study_sample references study ( study_id ) -study_id - Foreign Key fk_common_prep_info - prep_template_sample references study_sample ( sample_id ) +study_id + Foreign Key fk_raw_data_filetype + raw_data references filetype ( filetype_id ) + +filetype_id + Foreign Key fk_prep_template_id + prep_template_preprocessed_data references prep_template ( prep_template_id ) + +prep_template_id + Foreign Key fk_prep_template_preprocessed_data + prep_template_preprocessed_data references preprocessed_data ( preprocessed_data_id ) + +preprocessed_data_id + Foreign Key fk_prep_template_data_type + prep_template references data_type ( data_type_id ) + +data_type_id + Foreign Key fk_prep_template_raw_data + prep_template references raw_data ( raw_data_id ) + +raw_data_id + Foreign Key fk_raw_filepath + raw_filepath references filepath ( filepath_id ) + +filepath_id + Foreign Key fk_raw_filepath_0 + raw_filepath references raw_data ( raw_data_id ) + +raw_data_id + Foreign Key fk_filepath_id + prep_template_filepath references filepath ( filepath_id ) + +filepath_id + Foreign Key fk_prep_template_id + prep_template_filepath references prep_template ( prep_template_id ) + +prep_template_id + Foreign Key fk_study_prep_template_study + study_prep_template references study ( study_id ) + +study_id + Foreign Key fk_study_prep_template_pt + study_prep_template references prep_template ( prep_template_id ) -sample_id +prep_template_id + Foreign Key fk_prep_columns_prep_template + prep_columns references prep_template ( prep_template_id ) + +prep_template_id Foreign Key fk_prep_template prep_template_sample references prep_template ( prep_template_id ) -prep_template_id @@ -876,18 +881,6 @@ other_mapping_columnsother_mapping_columns varchar Represents whatever other columns go with this study - - - -study_raw_dataTable qiita.study_raw_data -links study to its raw data - Index ( study_id ) Primary Key ( study_id, raw_data_id ) -study_idstudy_id bigint not null -References study ( study_id ) - Primary Key ( study_id, raw_data_id ) -raw_data_idraw_data_id bigint not null -References raw_data ( raw_data_id ) - @@ -1129,40 +1122,6 @@ datadata bigint STUFFFFF - - - -prep_columnsTable qiita.prep_columns - Primary Key ( prep_template_id, column_name, column_type ) Index ( prep_template_id ) -prep_template_idprep_template_id bigint not null -References prep_template ( prep_template_id ) - Primary Key ( prep_template_id, column_name, column_type ) -column_namecolumn_name varchar not null - Primary Key ( prep_template_id, column_name, column_type ) -column_typecolumn_type varchar not null - - - - -raw_filepathTable qiita.raw_filepath - Primary Key ( raw_data_id, filepath_id ) Index ( raw_data_id ) -raw_data_idraw_data_id bigint not null -References raw_data ( raw_data_id ) - Primary Key ( raw_data_id, filepath_id ) Index ( filepath_id ) -filepath_idfilepath_id bigint not null -References filepath ( filepath_id ) - - - - -filetypeTable qiita.filetype -Type of file (FASTA, FASTQ, SPECTRA, etc) - Primary Key ( filetype_id ) -filetype_idfiletype_id bigserial not null -Referred by raw_data ( filetype_id ) - Unique Index ( type ) -typetype varchar not null - @@ -1232,40 +1191,6 @@ Unique Index ( severity ) severityseverity varchar not null - - - -prep_templateTable qiita.prep_template - Primary Key ( prep_template_id ) -prep_template_idprep_template_id bigserial not null -Referred by prep_template_sample ( prep_template_id ) -Referred by prep_columns ( prep_template_id ) -Referred by prep_template_filepath ( prep_template_id ) -Referred by prep_template_preprocessed_data ( prep_template_id ) - Index ( data_type_id ) -data_type_iddata_type_id bigint not null -References data_type ( data_type_id ) - Index ( raw_data_id ) -raw_data_idraw_data_id bigint not null -References raw_data ( raw_data_id ) - preprocessing_statuspreprocessing_status varchar not null default 'not_preprocessed' - investigation_typeinvestigation_type varchar -The investigation type (e.g., one of the values from EBI's set of known types) - - - - -raw_dataTable qiita.raw_data - Unique Index ( raw_data_id ) Primary Key ( raw_data_id ) -raw_data_idraw_data_id bigserial not null -Referred by prep_template ( raw_data_id ) -Referred by raw_filepath ( raw_data_id ) -Referred by study_raw_data ( raw_data_id ) - Index ( filetype_id ) -filetype_idfiletype_id bigint not null -References filetype ( filetype_id ) - link_filepaths_statuslink_filepaths_status varchar not null default 'idle' - @@ -1389,17 +1314,6 @@ Unique Index ( timeseries_type, intervention_type ) intervention_typeintervention_type varchar not null default 'None' - - - -prep_template_filepathTable qiita.prep_template_filepath - Primary Key ( prep_template_id, filepath_id ) Index ( prep_template_id ) -prep_template_idprep_template_id bigint not null -References prep_template ( prep_template_id ) - Primary Key ( prep_template_id, filepath_id ) Index ( filepath_id ) -filepath_idfilepath_id bigint not null -References filepath ( filepath_id ) - @@ -1411,17 +1325,6 @@ filepath_idfilepath_id bigint not null References filepath ( filepath_id ) - - - -prep_template_preprocessed_dataTable qiita.prep_template_preprocessed_data - Primary Key ( prep_template_id, preprocessed_data_id ) Index ( prep_template_id ) -prep_template_idprep_template_id bigint not null -References prep_template ( prep_template_id ) - Primary Key ( prep_template_id, preprocessed_data_id ) Index ( preprocessed_data_id ) -preprocessed_data_idpreprocessed_data_id bigint not null -References preprocessed_data ( preprocessed_data_id ) - @@ -1691,16 +1594,17 @@ study_idstudy_id bigserial not null Unique name for study Referred by investigation_study ( study_id ) -Referred by study_sample ( study_id ) Referred by sample_template_filepath ( study_id ) Referred by study_environmental_package ( study_id ) Referred by study_experimental_factor ( study_id ) Referred by study_pmid ( study_id ) Referred by study_preprocessed_data ( study_id ) Referred by study_processed_data ( study_id ) -Referred by study_raw_data ( study_id ) +Referred by study_sample ( study_id ) Referred by study_sample_columns ( study_id ) -Referred by study_users ( study_id ) +Referred by study_users ( study_id ) +Referred by study_prep_template ( study_id ) +Referred by study_prep_template ( study_id ) Index ( email ) emailemail varchar not null Email of study owner @@ -1813,29 +1717,130 @@ References study_sample ( sample_id ) - - -study_sampleTable qiita.study_sample +<rect class='table' x='1515' y='98' width='90' height='75' rx='7' ry='7' /> +<path d='M 1515.50 124.50 L 1515.50 105.50 Q 1515.50 98.50 1522.50 98.50 L 1597.50 98.50 Q 1604.50 98.50 1604.50 105.50 L 1604.50 124.50 L1515.50 124.50 ' style='fill:url(#tableHeaderGradient0); stroke:none;' /> +<a xlink:href='#study_sample'><text x='1523' y='112' class='tableTitle'>study_sample</text><title>Table qiita.study_sample Required info for each sample. One row is one sample. - Primary Key ( sample_id ) -sample_idsample_id varchar not null -Referred by analysis_sample ( sample_id ) -Referred by prep_template_sample ( sample_id ) - Index ( study_id ) -study_idstudy_id bigint not null -References study ( study_id ) + Primary Key ( sample_id ) +sample_idsample_id varchar not null +Referred by analysis_sample ( sample_id ) + Index ( study_id ) +study_idstudy_id bigint not null +References study ( study_id ) + + + + +raw_dataTable qiita.raw_data + Unique Index ( raw_data_id ) Primary Key ( raw_data_id ) +raw_data_idraw_data_id bigserial not null +Referred by prep_template ( raw_data_id ) +Referred by raw_filepath ( raw_data_id ) + Index ( filetype_id ) +filetype_idfiletype_id bigint not null +References filetype ( filetype_id ) + link_filepaths_statuslink_filepaths_status varchar not null default 'idle' + + + + +filetypeTable qiita.filetype +Type of file (FASTA, FASTQ, SPECTRA, etc) + Primary Key ( filetype_id ) +filetype_idfiletype_id bigserial not null +Referred by raw_data ( filetype_id ) + Unique Index ( type ) +typetype varchar not null + + + + +prep_template_preprocessed_dataTable qiita.prep_template_preprocessed_data + Primary Key ( prep_template_id, preprocessed_data_id ) Index ( prep_template_id ) +prep_template_idprep_template_id bigint not null +References prep_template ( prep_template_id ) + Primary Key ( prep_template_id, preprocessed_data_id ) Index ( preprocessed_data_id ) +preprocessed_data_idpreprocessed_data_id bigint not null +References preprocessed_data ( preprocessed_data_id ) + + + + +prep_templateTable qiita.prep_template + Primary Key ( prep_template_id ) +prep_template_idprep_template_id bigserial not null +Referred by prep_columns ( prep_template_id ) +Referred by prep_template_filepath ( prep_template_id ) +Referred by prep_template_preprocessed_data ( prep_template_id ) +Referred by prep_template_sample ( prep_template_id ) +Referred by study_prep_template ( prep_template_id ) +Referred by study_prep_template ( prep_template_id ) + Index ( data_type_id ) +data_type_iddata_type_id bigint not null +References data_type ( data_type_id ) + Index ( raw_data_id ) +raw_data_idraw_data_id bigint not null +References raw_data ( raw_data_id ) + preprocessing_statuspreprocessing_status varchar not null default 'not_preprocessed' + investigation_typeinvestigation_type varchar +The investigation type (e.g., one of the values from EBI's set of known types) + + + + +raw_filepathTable qiita.raw_filepath + Primary Key ( raw_data_id, filepath_id ) Index ( raw_data_id ) +raw_data_idraw_data_id bigint not null +References raw_data ( raw_data_id ) + Primary Key ( raw_data_id, filepath_id ) Index ( filepath_id ) +filepath_idfilepath_id bigint not null +References filepath ( filepath_id ) + + + + +prep_template_filepathTable qiita.prep_template_filepath + Primary Key ( prep_template_id, filepath_id ) Index ( prep_template_id ) +prep_template_idprep_template_id bigint not null +References prep_template ( prep_template_id ) + Primary Key ( prep_template_id, filepath_id ) Index ( filepath_id ) +filepath_idfilepath_id bigint not null +References filepath ( filepath_id ) + + + + +study_prep_templateTable qiita.study_prep_template +links study to its prep templates + Primary Key ( study_id, prep_template_id ) Index ( study_id ) +study_idstudy_id bigint not null +References study ( study_id ) + Primary Key ( study_id, prep_template_id ) Index ( prep_template_id ) +prep_template_idprep_template_id bigint not null +References prep_template ( prep_template_id ) + + + + +prep_columnsTable qiita.prep_columns + Primary Key ( prep_template_id, column_name, column_type ) Index ( prep_template_id ) +prep_template_idprep_template_id bigint not null +References prep_template ( prep_template_id ) + Primary Key ( prep_template_id, column_name, column_type ) +column_namecolumn_name varchar not null + Primary Key ( prep_template_id, column_name, column_type ) +column_typecolumn_type varchar not null - - -prep_template_sampleTable qiita.prep_template_sample - Primary Key ( prep_template_id, sample_id ) Index ( prep_template_id ) -prep_template_idprep_template_id bigint not null +<rect class='table' x='1335' y='188' width='135' height='75' rx='7' ry='7' /> +<path d='M 1335.50 214.50 L 1335.50 195.50 Q 1335.50 188.50 1342.50 188.50 L 1462.50 188.50 Q 1469.50 188.50 1469.50 195.50 L 1469.50 214.50 L1335.50 214.50 ' style='fill:url(#tableHeaderGradient0); stroke:none;' /> +<a xlink:href='#prep_template_sample'><text x='1342' y='202' class='tableTitle'>prep_template_sample</text><title>Table qiita.prep_template_sample + Primary Key ( prep_template_id, sample_id ) Index ( prep_template_id ) +prep_template_idprep_template_id bigint not null The prep template identifier -References prep_template ( prep_template_id ) - Index ( sample_id ) Index ( sample_id ) Primary Key ( prep_template_id, sample_id ) -sample_idsample_id varchar not null -References study_sample ( sample_id ) +References prep_template ( prep_template_id ) + Index ( sample_id ) Index ( sample_id ) Primary Key ( prep_template_id, sample_id ) +sample_idsample_id varchar not null @@ -2312,46 +2317,6 @@
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table study_raw_data
links study to its raw data
study_id bigint NOT NULL
raw_data_id bigint NOT NULL
Indexes
idx_study_raw_data ON study_id
idx_study_raw_data_0 primary key ON study_id, raw_data_id
Foreign Keys
fk_study_raw_data_study ( study_id ) ref study (study_id)
fk_study_raw_data_raw_data ( raw_data_id ) ref raw_data (raw_data_id)
-

@@ -3098,117 +3063,6 @@
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table prep_columns
prep_template_id bigint NOT NULL
column_name varchar NOT NULL
column_type varchar NOT NULL
Indexes
idx_prep_columns_0 primary key ON prep_template_id, column_name, column_type
idx_prep_columns_1 ON prep_template_id
Foreign Keys
fk_prep_columns_prep_template ( prep_template_id ) ref prep_template (prep_template_id)
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table raw_filepath
raw_data_id bigint NOT NULL
filepath_id bigint NOT NULL
Indexes
idx_raw_filepath primary key ON raw_data_id, filepath_id
idx_raw_filepath_0 ON filepath_id
idx_raw_filepath_1 ON raw_data_id
Foreign Keys
fk_raw_filepath ( filepath_id ) ref filepath (filepath_id)
fk_raw_filepath_0 ( raw_data_id ) ref raw_data (raw_data_id)
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - -
Table filetype
Type of file (FASTA, FASTQ, SPECTRA, etc)
filetype_id bigserial NOT NULL
type varchar NOT NULL
Indexes
pk_filetype primary key ON filetype_id
idx_filetype unique ON type
-

@@ -3386,122 +3240,21 @@

- + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table prep_template
Table job
prep_template_idjob_id bigserial NOT NULL Unique identifier for job
data_type_iddata_type_id bigint NOT NULL What datatype (16s, metabolome, etc) job is run on.
raw_data_id bigint NOT NULL
preprocessing_status varchar NOT NULL DEFO 'not_preprocessed'
investigation_type varchar The investigation type (e.g., one of the values from EBI's set of known types)
Indexes
pk_prep_template primary key ON prep_template_id
idx_prep_template ON data_type_id
idx_prep_template_0 ON raw_data_id
Foreign Keys
fk_prep_template_data_type ( data_type_id ) ref data_type (data_type_id)
fk_prep_template_raw_data ( raw_data_id ) ref raw_data (raw_data_id)
- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table raw_data
raw_data_id bigserial NOT NULL
filetype_id bigint NOT NULL
link_filepaths_status varchar NOT NULL DEFO 'idle'
Indexes
pk_raw_data unique ON raw_data_id
idx_raw_data ON filetype_id
pk_raw_data_0 primary key ON raw_data_id
Foreign Keys
fk_raw_data_filetype ( filetype_id ) ref filetype (filetype_id)
- -

- - - - - - - - - - - - - - - - - + @@ -3852,49 +3605,6 @@
Table job
job_id bigserial NOT NULL Unique identifier for job
data_type_id bigint NOT NULL What datatype (16s, metabolome, etc) job is run on.
job_status_idjob_status_id bigint NOT NULL
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table prep_template_filepath
prep_template_id bigint NOT NULL
filepath_id bigint NOT NULL
Indexes
idx_prep_template_filepath primary key ON prep_template_id, filepath_id
idx_prep_template_filepath ON filepath_id
idx_prep_template_filepath ON prep_template_id
Foreign Keys
fk_filepath_id ( filepath_id ) ref filepath (filepath_id)
fk_prep_template_id ( prep_template_id ) ref prep_template (prep_template_id)
-

@@ -3938,49 +3648,6 @@
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Table prep_template_preprocessed_data
prep_template_id bigint NOT NULL
preprocessed_data_id bigint NOT NULL
Indexes
idx_prep_template_preprocessed_data primary key ON prep_template_id, preprocessed_data_id
idx_prep_template_preprocessed_data_0 ON prep_template_id
idx_prep_template_preprocessed_data_1 ON preprocessed_data_id
Foreign Keys
fk_prep_template_id ( prep_template_id ) ref prep_template (prep_template_id)
fk_prep_template_preprocessed_data ( preprocessed_data_id ) ref preprocessed_data (preprocessed_data_id)
-

@@ -5239,42 +4906,379 @@

- + - + + + + + + - + - - + + - - + + - - + + - - + + - - + + + + - + +
Table prep_template_sample
Table raw_data
prep_template_idraw_data_id bigserial NOT NULL
filetype_id bigint NOT NULL The prep template identifier
sample_id varchar NOT NULL link_filepaths_status varchar NOT NULL DEFO 'idle'
Indexes
idx_required_prep_info_2 ON sample_id
pk_raw_data unique ON raw_data_id
idx_common_prep_info_0 ON sample_id
idx_raw_data ON filetype_id
idx_common_prep_info primary key ON prep_template_id, sample_id
pk_raw_data_0 primary key ON raw_data_id
idx_common_prep_info_1 ON prep_template_id
Foreign Keys
fk_raw_data_filetype ( filetype_id ) ref filetype (filetype_id)
Foreign Keys
+ +

+ + + + + + - - + + + + + + + + + + + + + + + + + +
Table filetype
Type of file (FASTA, FASTQ, SPECTRA, etc)
fk_common_prep_info ( sample_id ) ref study_sample (sample_id) filetype_id bigserial NOT NULL
type varchar NOT NULL
Indexes
pk_filetype primary key ON filetype_id
idx_filetype unique ON type
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table prep_template_preprocessed_data
prep_template_id bigint NOT NULL
preprocessed_data_id bigint NOT NULL
Indexes
idx_prep_template_preprocessed_data primary key ON prep_template_id, preprocessed_data_id
idx_prep_template_preprocessed_data_0 ON prep_template_id
idx_prep_template_preprocessed_data_1 ON preprocessed_data_id
Foreign Keys
fk_prep_template_id ( prep_template_id ) ref prep_template (prep_template_id)
fk_prep_template_preprocessed_data ( preprocessed_data_id ) ref preprocessed_data (preprocessed_data_id)
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table prep_template
prep_template_id bigserial NOT NULL
data_type_id bigint NOT NULL
raw_data_id bigint NOT NULL
preprocessing_status varchar NOT NULL DEFO 'not_preprocessed'
investigation_type varchar The investigation type (e.g., one of the values from EBI's set of known types)
Indexes
pk_prep_template primary key ON prep_template_id
idx_prep_template ON data_type_id
idx_prep_template_0 ON raw_data_id
Foreign Keys
fk_prep_template_data_type ( data_type_id ) ref data_type (data_type_id)
fk_prep_template_raw_data ( raw_data_id ) ref raw_data (raw_data_id)
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table raw_filepath
raw_data_id bigint NOT NULL
filepath_id bigint NOT NULL
Indexes
idx_raw_filepath primary key ON raw_data_id, filepath_id
idx_raw_filepath_0 ON filepath_id
idx_raw_filepath_1 ON raw_data_id
Foreign Keys
fk_raw_filepath ( filepath_id ) ref filepath (filepath_id)
fk_raw_filepath_0 ( raw_data_id ) ref raw_data (raw_data_id)
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table prep_template_filepath
prep_template_id bigint NOT NULL
filepath_id bigint NOT NULL
Indexes
idx_prep_template_filepath primary key ON prep_template_id, filepath_id
idx_prep_template_filepath ON filepath_id
idx_prep_template_filepath ON prep_template_id
Foreign Keys
fk_filepath_id ( filepath_id ) ref filepath (filepath_id)
fk_prep_template_id ( prep_template_id ) ref prep_template (prep_template_id)
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table study_prep_template
links study to its prep templates
study_id bigint NOT NULL
prep_template_id bigint NOT NULL
Indexes
idx_study_raw_data primary key ON study_id, prep_template_id
idx_study_raw_data_0 ON study_id
idx_study_raw_data_1 ON prep_template_id
Foreign Keys
fk_study_prep_template_study ( study_id ) ref study (study_id)
fk_study_prep_template_pt ( prep_template_id ) ref prep_template (prep_template_id)
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Table prep_columns
prep_template_id bigint NOT NULL
column_name varchar NOT NULL
column_type varchar NOT NULL
Indexes
idx_prep_columns_0 primary key ON prep_template_id, column_name, column_type
idx_prep_columns_1 ON prep_template_id
Foreign Keys
fk_prep_columns_prep_template ( prep_template_id ) ref prep_template (prep_template_id)
+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 6021c0300d586d963af5710ccdba9b9fe70c7e56 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 19 May 2015 18:24:52 -0700 Subject: [PATCH 2/5] Adding patches --- qiita_db/support_files/patches/25.sql | 3 + .../patches/python_patches/25.py | 117 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 qiita_db/support_files/patches/25.sql create mode 100644 qiita_db/support_files/patches/python_patches/25.py diff --git a/qiita_db/support_files/patches/25.sql b/qiita_db/support_files/patches/25.sql new file mode 100644 index 000000000..1a1ac12be --- /dev/null +++ b/qiita_db/support_files/patches/25.sql @@ -0,0 +1,3 @@ +-- May 19, 2015 + +SELECT 42; \ No newline at end of file diff --git a/qiita_db/support_files/patches/python_patches/25.py b/qiita_db/support_files/patches/python_patches/25.py new file mode 100644 index 000000000..89a82d818 --- /dev/null +++ b/qiita_db/support_files/patches/python_patches/25.py @@ -0,0 +1,117 @@ +# May 19, 2015 +# We attach the prep template directly to the study. The raw data is no longer +# attached to the study directly, the prep template point to them. This will +# make the RawData to be effectively just a container for the raw files, +# which is how it was acting previously. + +from qiita_db.sql_connection import SQLConnectionHandler +from qiita_db.data import RawData +from qiita_db.util import move_filepaths_to_upload_folder + +conn_handler = SQLConnectionHandler() +queue = "PATCH_25" +conn_handler.create_queue(queue) + +# the system may contain raw data with no prep template associated to it. +# Retrieve all those raw data ids +sql = """SELECT raw_data_id + FROM qiita.raw_data + WHERE raw_data_id NOT IN ( + SELECT DISTINCT raw_data_id FROM qiita.prep_template);""" +rd_ids = [x[0] for x in conn_handler.execute_fetchall(sql)] + +# We will delete those RawData. However, if they have files attached, we should +# move them to the uploads folder of the study +sql_detach = """DELETE FROM qiita.study_raw_data + WHERE raw_data_id = %s AND study_id = %s""" +sql_unlink = "DELETE FROM qiita.raw_filepath WHERE raw_data_id = %s" +sql_delete = "DELETE FROM qiita.raw_data WHERE raw_data_id = %s" +move_files = [] +for rd_id in rd_ids: + rd = RawData(rd_id) + filepaths = rd.get_filepaths() + studies = sorted(rd.studies) + if filepaths: + # we need to move the files to a study. We chose the one with lower + # study id. Currently there is no case in the live database in which a + # RawData with no prep templates is attached to more than one study, + # but I think it is better to normalize this just in case + move_files.append((min(studies), filepaths)) + + # To delete the RawData we first need to unlink all the files + conn_handler.add_to_queue(queue, sql_unlink, (rd_id,)) + + # Then, remove the raw data from all the studies + for st_id in studies: + conn_handler.add_to_queue(queue, sql_detach, (rd_id, st_id)) + + conn_handler.add_to_queue(queue, sql_delete, (rd_id,)) + +# We can now perform all changes in the DB. Although this changes can be +# done in an SQL patch, they are done here because we need to execute the +# previous clean up in the database before we can actually execute the SQL +# patch. +sql = """CREATE TABLE qiita.study_prep_template ( + study_id bigint NOT NULL, + prep_template_id bigint NOT NULL, + CONSTRAINT idx_study_prep_template + PRIMARY KEY ( study_id, prep_template_id ) + ); + +CREATE INDEX idx_study_prep_template_0 + ON qiita.study_prep_template ( study_id ); + +CREATE INDEX idx_study_prep_template_1 + ON qiita.study_prep_template ( prep_template_id ); + +COMMENT ON TABLE qiita.study_prep_template IS + 'links study to its prep templates'; + +ALTER TABLE qiita.study_prep_template + ADD CONSTRAINT fk_study_prep_template_study + FOREIGN KEY ( study_id ) REFERENCES qiita.study( study_id ); + +ALTER TABLE qiita.study_prep_template + ADD CONSTRAINT fk_study_prep_template_pt + FOREIGN KEY ( prep_template_id ) + REFERENCES qiita.prep_template( prep_template_id ); + +-- Connect the existing prep templates in the system with their studies +DO $do$ +DECLARE + vals RECORD; +BEGIN +FOR vals IN + SELECT prep_template_id, study_id + FROM qiita.prep_template + JOIN qiita.study_raw_data USING (raw_data_id) +LOOP + INSERT INTO qiita.study_prep_template (study_id, prep_template_id) + VALUES (vals.study_id, vals.prep_template_id); +END LOOP; +END $do$; + +--- Drop the study_raw__data table as it's not longer used +DROP TABLE qiita.study_raw_data; +""" +conn_handler.add_to_queue(queue, sql) +conn_handler.execute_queue(queue) + +# After the changes in the database have been performed, move the files +# to the uploads folder +errors = [] +for st_id, fps in move_files: + try: + move_filepaths_to_upload_folder(st_id, fps) + except Exception, e: + # An error here is unlikely. However, it's possible and there is no + # clean way that we can unroll all the previous changes in the DB. + errors.append((st_id, fps, str(e))) + +# Show the user any error that could have been generated during the files +# movement +if errors: + print ("The following errors where generated when trying to move files " + "to the upload folder") + for st_id, fps, e in errors: + print "Study: %d, Filepaths: %s, Error: %s" % (st_id, fps, e) From 7592408f47d5b21115b7a09519fdb7ad6d9394f8 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Tue, 19 May 2015 18:49:01 -0700 Subject: [PATCH 3/5] raw_data_id can be now nullable - prep template with no raw data attached --- qiita_db/support_files/patches/python_patches/25.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qiita_db/support_files/patches/python_patches/25.py b/qiita_db/support_files/patches/python_patches/25.py index 89a82d818..541507749 100644 --- a/qiita_db/support_files/patches/python_patches/25.py +++ b/qiita_db/support_files/patches/python_patches/25.py @@ -93,6 +93,10 @@ --- Drop the study_raw__data table as it's not longer used DROP TABLE qiita.study_raw_data; + +-- The raw_data_id column now can be nullable +ALTER TABLE qiita.prep_template + ALTER COLUMN raw_data_id DROP NOT NULL; """ conn_handler.add_to_queue(queue, sql) conn_handler.execute_queue(queue) From 55d8f84c6fdbee0003312c27b01e2910e7e37ab8 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Sun, 24 May 2015 20:26:24 -0500 Subject: [PATCH 4/5] Addressing @antgonza's comments --- qiita_db/support_files/patches/python_patches/25.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiita_db/support_files/patches/python_patches/25.py b/qiita_db/support_files/patches/python_patches/25.py index 541507749..2dbe96c04 100644 --- a/qiita_db/support_files/patches/python_patches/25.py +++ b/qiita_db/support_files/patches/python_patches/25.py @@ -1,6 +1,6 @@ # May 19, 2015 # We attach the prep template directly to the study. The raw data is no longer -# attached to the study directly, the prep template point to them. This will +# attached to the study directly, the prep template points to them. This will # make the RawData to be effectively just a container for the raw files, # which is how it was acting previously. From 074147e3b9b4285d32f2532761faaa32933ca404 Mon Sep 17 00:00:00 2001 From: Jose Navas Date: Mon, 25 May 2015 17:05:57 -0500 Subject: [PATCH 5/5] Addressing @ElDeveloper comments --- qiita_db/support_files/patches/python_patches/25.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qiita_db/support_files/patches/python_patches/25.py b/qiita_db/support_files/patches/python_patches/25.py index 2dbe96c04..2dc2976e0 100644 --- a/qiita_db/support_files/patches/python_patches/25.py +++ b/qiita_db/support_files/patches/python_patches/25.py @@ -47,7 +47,7 @@ conn_handler.add_to_queue(queue, sql_delete, (rd_id,)) -# We can now perform all changes in the DB. Although this changes can be +# We can now perform all changes in the DB. Although these changes can be # done in an SQL patch, they are done here because we need to execute the # previous clean up in the database before we can actually execute the SQL # patch.
Table prep_template_sample
prep_template_id bigint NOT NULL The prep template identifier
sample_id varchar NOT NULL
Indexes
idx_required_prep_info_2 ON sample_id
idx_common_prep_info_0 ON sample_id
idx_common_prep_info primary key ON prep_template_id, sample_id
idx_common_prep_info_1 ON prep_template_id
Foreign Keys
fk_prep_template ( prep_template_id ) ref prep_template (prep_template_id)