politics-rewired / Spoke

Politics Rewired's fork of Spoke
GNU General Public License v3.0
36 stars 17 forks source link

Convert JSON fields from text to jsonb #1596

Open bchrobot opened 1 year ago

bchrobot commented 1 year ago

Spoke has a number of text-type Postgres columns that store JSON values. Rather than sprinkling try { JSON.parse(json_field_name) } catch {} throughout the codebase, we should just formalize in the schema that these are JSON fields.

We should use jsonb rather than json for performance reasons. We do not care about the exact format or ordering of the input JSON text so there is no reason to use json over jsonb.

Fields:

lediur commented 1 year ago

Could you provide a list of columns we should change, or some set of heuristics to determine whether a column needs changing? I think even a short list of examples would be a good starting place.

bchrobot commented 1 year ago

Could you provide a list of columns we should change, or some set of heuristics to determine whether a column needs changing? I think even a short list of examples would be a good starting place.

I went through the schema and added a list of fields to the description. Generally it's any text column with a default of '{}'::text.