<commit_before>class MigrateToStudyVersion extends edu.northwestern.bioinformatics.bering.Migration {
    void up() {
		//New column for number of consents reqd.
		addColumn('studies','consent_required', 'string');
		execute("update studies set consent_required='ALL'");

		// associating epoch to study version
        addColumn('epochs','stu_version_id', 'integer');
        execute("update epochs set stu_version_id=stu_id");
		execute("alter table epochs drop constraint FK_EPH_STU");
		execute("ALTER TABLE epochs drop CONSTRAINT UK_STU_EPH");
		execute("ALTER TABLE epochs ADD CONSTRAINT UK_STU_VER_EPH UNIQUE(name,stu_version_id)");
		execute("ALTER TABLE epochs ADD CONSTRAINT FK_EPH_STU_VER FOREIGN KEY (stu_version_id) REFERENCES study_versions (ID)");
		dropColumn('epochs', 'stu_id');
        
        // associating disease to study version
        addColumn('study_diseases','stu_version_id', 'integer');
        execute("update study_diseases set stu_version_id=study_id");
		execute("alter table study_diseases drop constraint UK_STU_DTM");
		execute("ALTER TABLE study_diseases ADD CONSTRAINT UK_STU_VER_DTM UNIQUE(stu_version_id,DISEASE_TERM_ID)");
		dropColumn('study_diseases', 'study_id');
		
		// associating companion association to parent study version
      	addColumn('comp_stu_associations', 'parent_version_id', 'integer');
      	execute("update comp_stu_associations set parent_version_id=parent_study_id");
      	dropColumn('comp_stu_associations', 'parent_study_id');
    
    	if (databaseMatches('postgres')){
    	// migrating consent version to new table consents from studies.
    	execute('insert into "consents"("id", "retired_indicator", "version", "name", "stu_version_id") select "id", "retired_indicator", 0, "consent_version", "id" from studies') ;
    	
		//migrate study to study version
		
		// migrate study site to study site study version
		execute("insert into study_site_versions (id, retired_indicator, version, start_date, irb_approval_date, stu_version_id, sto_id) select id , retired_indicator, 0 , start_date, irb_approval_date, study_id, id from study_organizations where type='SST'	")
		}
		// migrate study site to study site study status history
		
    }

	void down() {
    }
}<commit_msg>cpr-949 moved not null FK constraint to later script until after the study versions are migrated<commit_after>class MigrateToStudyVersion extends edu.northwestern.bioinformatics.bering.Migration {
    void up() {
		//New column for number of consents reqd.
		addColumn('studies','consent_required', 'string');
		execute("update studies set consent_required='ALL'");

		// associating epoch to study version
        addColumn('epochs','stu_version_id', 'integer');
        execute("update epochs set stu_version_id=stu_id");
		execute("alter table epochs drop constraint FK_EPH_STU");
		execute("ALTER TABLE epochs drop CONSTRAINT UK_STU_EPH");
		execute("ALTER TABLE epochs ADD CONSTRAINT UK_STU_VER_EPH UNIQUE(name,stu_version_id)");
		dropColumn('epochs', 'stu_id');
        
        // associating disease to study version
        addColumn('study_diseases','stu_version_id', 'integer');
        execute("update study_diseases set stu_version_id=study_id");
		execute("alter table study_diseases drop constraint UK_STU_DTM");
		execute("ALTER TABLE study_diseases ADD CONSTRAINT UK_STU_VER_DTM UNIQUE(stu_version_id,DISEASE_TERM_ID)");
		dropColumn('study_diseases', 'study_id');
		
		// associating companion association to parent study version
      	addColumn('comp_stu_associations', 'parent_version_id', 'integer');
      	execute("update comp_stu_associations set parent_version_id=parent_study_id");
      	dropColumn('comp_stu_associations', 'parent_study_id');
    
    	if (databaseMatches('postgres')){
    	// migrating consent version to new table consents from studies.
    	execute('insert into "consents"("id", "retired_indicator", "version", "name", "stu_version_id") select "id", "retired_indicator", 0, "consent_version", "id" from studies') ;
    	
		//migrate study to study version
		
		// migrate study site to study site study version
		execute("insert into study_site_versions (id, retired_indicator, version, start_date, irb_approval_date, stu_version_id, sto_id) select id , retired_indicator, 0 , start_date, irb_approval_date, study_id, id from study_organizations where type='SST'	")
		}
		// migrate study site to study site study status history
		
    }

	void down() {
    }
}
{'fraction_non_alphanumeric': 0.10259856630824372, 'fraction_numerical': 0.0015681003584229391, 'mean_word_length': 4.993288590604027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5048601', 'n_tokens_mistral': 1482, 'n_tokens_neox': 1384, 'n_words': 357}