-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3533 from LiteFarmOrg/LF-4531/Set_up_new_task_aba…
…ndonment_reason_for_tasks_with_removed_animals LF-4531: Set up new task abandonment reason for tasks with removed animals
- Loading branch information
Showing
5 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/api/db/migration/20241118191954_add_constraint_to_task_abandonment_reason.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,43 @@ | ||
/* | ||
* Copyright 2024 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const up = async (knex) => { | ||
const reasons = [ | ||
'OTHER', | ||
'CROP_FAILURE', | ||
'LABOUR_ISSUE', | ||
'MARKET_PROBLEM', | ||
'WEATHER', | ||
'MACHINERY_ISSUE', | ||
'SCHEDULING_ISSUE', | ||
'NO_ANIMALS', | ||
]; | ||
await knex.raw(` | ||
ALTER TABLE task ADD CONSTRAINT abandonment_reason_check | ||
CHECK (abandonment_reason = ANY (ARRAY['${reasons.join(`'::text,'`)}'::text])) | ||
`); | ||
}; | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
export const down = async (knex) => { | ||
await knex.raw('ALTER TABLE task DROP CONSTRAINT abandonment_reason_check'); | ||
}; |
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
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
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
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