-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add jsonb column to store raw body in grants table
- Loading branch information
Showing
3 changed files
with
172 additions
and
6 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/server/migrations/20240105223338_add_raw_body_jsonb_column_to_grants.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,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'); | ||
}; |
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