Skip to content

Commit

Permalink
add jsonb column to store raw body in grants table (#2435)
Browse files Browse the repository at this point in the history
  • Loading branch information
sanason authored Jan 10, 2024
1 parent 108cc36 commit 0db5162
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.raw(`
ALTER TABLE grants ADD COLUMN raw_body_json jsonb;
CREATE OR REPLACE FUNCTION jsonb_from_text(inval TEXT) RETURNS JSONB AS $$
BEGIN
RETURN inval::jsonb;
exception when others then return null;
END;
$$ LANGUAGE plpgsql IMMUTABLE;
UPDATE grants SET raw_body_json = jsonb_from_text(raw_body) WHERE raw_body IS NOT NULL;
DROP FUNCTION jsonb_from_text;
`);
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.raw('ALTER TABLE grants DROP COLUMN raw_body_json');
};
2 changes: 1 addition & 1 deletion packages/server/seeds/dev/01_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const globalCodes = [
];

exports.seed = async (knex) => {
const tables = ['agency_eligibility_codes', 'keywords', 'eligibility_codes', 'grants', 'assigned_grants_agency', 'grants_interested'];
const tables = ['agency_eligibility_codes', 'keywords', 'eligibility_codes', 'grants', 'assigned_grants_agency', 'grants_interested', 'grants_saved_searches'];

// eslint-disable-next-line no-restricted-syntax
for (const table of tables) {
Expand Down
148 changes: 143 additions & 5 deletions packages/server/seeds/dev/ref/grants.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,36 @@ const grants = [
eligibility_codes: '25',
funding_activity_category_codes: 'ST',
opportunity_status: 'posted',
raw_body: 'raw body',
raw_body_json: {
opportunity: {
id: '335255',
number: '21-605',
title: 'EAR Postdoctoral Fellowships',
description: '<p class="MsoNormal">The Division of Earth Sciences (EAR) awards Postdoctoral Fellowships </p>',
milestones: {
post_date: '2021-08-11',
close: {
date: '2021-11-03',
},
},
category: { code: 'D', name: 'Discretionary' },
},
agency: { code: 'NSF' },
award: { ceiling: '6500' },
cost_sharing_or_matching_requirement: false,
cfda_numbers: ['47.050'],
eligible_applicants: [
{ code: '25' },
],
funding_activity: {
categories: [
{
name: 'Science and Technology and Other Research and Development',
code: 'ST',
},
],
},
},
created_at: '2021-08-11 11:30:38.89828-07',
updated_at: '2021-08-11 12:30:39.531-07',
},
Expand All @@ -71,9 +100,41 @@ const grants = [
eligibility_codes: '11 07 25',
funding_activity_category_codes: 'HL ISS',
opportunity_status: 'posted',
raw_body: 'raw body',
raw_body_json: {
opportunity: {
id: '333816',
number: 'HHS-2021-IHS-TPI-0001',
title: 'Community Health Aide Program: Tribal Planning & Implementation',
description: ' <p>Health Aide Program for Covid</p>',
milestones: {
post_date: '2021-08-05',
},
category: { code: 'D', name: 'Discretionary' },
},
agency: { code: 'HHS-IHS' },
award: { ceiling: '500000' },
cost_sharing_or_matching_requirement: false,
cfda_numbers: ['93.382'],
eligible_applicants: [
{ code: '11' }, { code: '07' }, { code: '25' },
],
funding_activity: {
categories: [
{
name: 'Health',
code: 'HL',
},
{
name: 'Income Security and Social Services',
code: 'ISS',
},
],
},
revision: { id: 'c3' },
},
created_at: '2021-08-06 16:03:53.57025-07',
updated_at: '2021-08-11 12:35:42.562-07',
revision_id: 'c3',
},
{
status: 'inbox',
Expand All @@ -94,7 +155,33 @@ const grants = [
eligibility_codes: '25',
funding_activity_category_codes: 'HL',
opportunity_status: 'posted',
raw_body: 'raw body',
raw_body_json: {
opportunity: {
id: '666999',
number: 'grant-number-666999',
title: 'Test Grant 666999',
description: '<p>Test Grant Description 666999</p>',
milestones: {
post_date: '2021-09-04',
close: {
date: daysAhead(2),
},
},
category: { code: 'D', name: 'Discretionary' },
},
agency: { code: 'NSF' },
award: { ceiling: '6500' },
cost_sharing_or_matching_requirement: false,
cfda_numbers: ['47.050'],
eligible_applicants: [
{ code: '25' },
],
funding_activity: {
categories: [
{ name: 'Health', code: 'HL' },
],
},
},
created_at: '2021-08-11 11:30:38.89828-07',
updated_at: '2021-08-11 12:30:39.531-07',
},
Expand All @@ -117,7 +204,32 @@ const grants = [
eligibility_codes: '',
funding_activity_category_codes: 'HL',
opportunity_status: 'posted',
raw_body: 'raw body',
raw_body_json: {
opportunity: {
id: '0',
number: '0',
title: 'Test Grant 0',
description: '',
milestones: {
post_date: '2021-08-05',
close: {
date: daysAhead(3),
},
},
category: { code: 'D', name: 'Discretionary' },
},
agency: { code: 'HHS-IHS' },
award: { ceiling: '500000' },
cost_sharing_or_matching_requirement: false,
cfda_numbers: ['93.382'],
eligible_applicants: [
],
funding_activity: {
categories: [
{ name: 'Health', code: 'HL' },
],
},
},
created_at: '2021-08-06 16:03:53.57025-07',
updated_at: '2021-08-11 12:35:42.562-07',
},
Expand All @@ -140,7 +252,33 @@ const grants = [
eligibility_codes: '11 07 25',
funding_activity_category_codes: 'O',
opportunity_status: 'posted',
raw_body: 'raw body',
raw_body_json: {
opportunity: {
id: '333333',
number: 'HHS-2021-IHS-TPI-0002',
title: 'Community Health Aide Program: County Planning & Implementation',
description: ' <p>Health Aide Program for Covid</p>',
milestones: {
post_date: '2021-08-05',
close: {
date: daysAhead(4),
},
},
category: { code: 'D', name: 'Discretionary' },
},
agency: { code: 'HHS-IHS' },
award: { ceiling: '500000' },
cost_sharing_or_matching_requirement: false,
cfda_numbers: ['93.382'],
eligible_applicants: [
{ code: '11' }, { code: '07' }, { code: '25' },
],
funding_activity: {
categories: [
{ name: 'Other', code: 'O' },
],
},
},
created_at: '2021-08-06 16:03:53.57025-07',
updated_at: '2021-08-11 12:35:42.562-07',
},
Expand Down

0 comments on commit 0db5162

Please sign in to comment.