message: fix(SPD): Correct and ingest invalid SPD postcodes
  Some postcodes on SPD have an extra character appended. Since these are
  picked up as invalid postcodes, they can no longer be queried
  This change will ingest the first instance of these invalid postcodes
  (i.e. those ending with A) and drop all others
diff: @@ -45,7 +45,7 @@ const foreignColumns = [
  const toJoinString = () => {
  return relationships
  .map(
  - r =>
  + (r) =>
  `LEFT OUTER JOIN ${r.table} ON ${TABLE_NAME}.${r.key}=${r.table}.${r.foreignKey}`
  )
  .join(" ");
  @@ -65,17 +65,35 @@ const findQuery = `
  `;
  const SPD_COL_MAPPINGS = Object.freeze([
  - { column: "postcode", method: row => row.extract("Postcode") },
  + { column: "postcode", method: (row) => row.extract("Postcode") },
  {
  column: "pc_compact",
  - method: row => row.extract("Postcode").replace(/\s/g, ""),
  + method: (row) => row.extract("Postcode").replace(/\s/g, ""),
  },
  {
  column: "scottish_constituency_id",
  - method: row => row.extract("ScottishParliamentaryConstituency2014Code"),
  + method: (row) => row.extract("ScottishParliamentaryConstituency2014Code"),
  },
  ]);
  +const EXCEPTION_REGEX = /A$/;
  +
  +/**
  + * Validates and potentially mutates a CSV row for ingest
  + *
  + * Unfortunately SPD appends extra characters to some postcodes. This method returns null when these cases are met, unless the postcode ends in `A`.
  + *
  + * Postcodes suffixed with `A` are made valid and returned to the stream for ingest
  + */
  +const clean = (row) => {
  + const postcode = row[0];
  + if (Postcode.isValid(postcode)) return row;
  + // Reject if invalid postcide has a non-A suffix
  + if (postcode.match(EXCEPTION_REGEX) === null) return null;
  + row[0] = postcode.replace(EXCEPTION_REGEX, "");
  + return row;
  +};
  +
  class ScottishPostcode extends Base {
  constructor() {
  super(TABLE_NAME, schema, indexes);
  @@ -117,13 +135,14 @@ class ScottishPostcode extends Base {
  this._csvSeed(
  {
  filepath,
  - transform: row => {
  - row.extract = code => extractor(row, code);
  + transform: (row) => {
  + clean(row);
  + row.extract = (code) => extractor(row, code);
  if (row.extract("Postcode") === "Postcode") return null; // Skip if header
  if (row.extract("DateOfDeletion").length !== 0) return null; // Skip row if terminated
  - return SPD_COL_MAPPINGS.map(elem => elem.method(row));
  + return SPD_COL_MAPPINGS.map((elem) => elem.method(row));
  },
  - columns: SPD_COL_MAPPINGS.map(elem => elem.column).join(","),
  + columns: SPD_COL_MAPPINGS.map((elem) => elem.column).join(","),
  },
  callback
  );
  @@ -136,13 +155,13 @@ class ScottishPostcode extends Base {
  [
  this._createRelation.bind(this),
  this.clear.bind(this),
  - cb =>
  + (cb) =>
  this.seedPostcodes.call(
  this,
  { filepath: largeUserFile, extractor: largeUserExtractor },
  cb
  ),
  - cb =>
  + (cb) =>
  this.seedPostcodes.call(
  this,
  { filepath: smallUserFile, extractor: smallUserExtractor },
  