This repository has been archived by the owner on Jan 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove trials_trialrecords table and add sources and trialrecords seeds
The relationship between Trial and Trialrecords is one-to-many, so there's no need for a relationship table.
- Loading branch information
1 parent
577b33c
commit a679484
Showing
2 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
migrations/20160415172210_remove_trials_trialrecords_table.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
exports.up = (knex) => { | ||
const query = ` | ||
UPDATE trialrecords | ||
SET trial_id = trials_trialrecords.trial_id | ||
FROM ( | ||
SELECT trial_id, trialrecord_id | ||
FROM trials_trialrecords | ||
) AS trials_trialrecords | ||
WHERE trialrecords.id = trials_trialrecords.trialrecord_id | ||
`; | ||
function addTrialIdColumn(table) { | ||
table.uuid('trial_id') | ||
.references('trials.id') | ||
.index(); | ||
} | ||
|
||
return knex.schema.table('trialrecords', addTrialIdColumn) | ||
.then(() => knex.raw(query)) | ||
.then(() => knex.schema.dropTable('trials_trialrecords')); | ||
}; | ||
|
||
exports.down = () => { | ||
throw Error('Destructive migration can\'t be rolled back.'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters