Ejemplo n.º 1
0
 return proddb.withTransaction('READ_WRITE', client => go(function*() {
   yield initialization.reloadDatabaseCode( client, path.join(__dirname, '../psql/schema'));
   yield client.query('UPDATE adgangsadresser a SET aendret = v.aendret FROM dar1_adgangsadresser_view v WHERE a.id = v.id');
   yield applyCurrentTableToChangeTable(client, tableSchema.tables.adgangsadresser, ['aendret']);
   yield client.query('UPDATE enhedsadresser a SET aendret = v.aendret FROM dar1_enhedsadresser_view v WHERE a.id = v.id');
   yield applyCurrentTableToChangeTable(client, tableSchema.tables.enhedsadresser, ['aendret']);
   yield client.query('UPDATE adgangsadresser_mat a SET aendret = v.aendret FROM adgangsadresser_mat_view v WHERE a.id = v.id');
   yield applyCurrentTableToChangeTable(client, tableSchema.tables.adgangsadresser_mat, ['aendret']);
   yield client.query('UPDATE adresser_mat a SET aendret = v.aendret, a_aendret = v.a_aendret FROM adresser_mat_view v WHERE a.id = v.id');
   yield applyCurrentTableToChangeTable(client, tableSchema.tables.adresser_mat, ['aendret', 'a_aendret']);
   yield withImportTransaction(client, 'updateAfterDataPatch', (txid) => go(function*() {
     yield importDarImpl.updateDawa(client, txid);
   }));
 }));
Ejemplo n.º 2
0
const initBboxAndVisualCenters = (client, txid, tableModel, clearHistory) => go(function*() {
  if(clearHistory) {
    yield client.query(`DELETE FROM ${tableModel.table}_changes`);
  }
  const allPrimaryKeys = yield client.queryRows(`SELECT ${tableModel.primaryKey.join(',')}
    FROM ${tableModel.table} WHERE geom IS NOT NULL`);
  for(let key of allPrimaryKeys) {
    const whereClause = `${tableModel.primaryKey.map(keyName => format(`${keyName} = %L`, key[keyName])).join(' AND ')}`;
    const query = `SELECT st_asgeojson(geom) as geom_json, st_isvalid(geom) as valid FROM ${tableModel.table} WHERE ${whereClause}`;
    const queryResult = (yield client.queryRows(query))[0];
    const geojsonText = queryResult.geom_json;
    if(geojsonText) {
      const geojson = JSON.parse(geojsonText);
      const visualCenter = computeVisualCenter(geojson);
      const visualCenterGeojson = {type: 'Point', coordinates: visualCenter};
      if(visualCenter) {
        yield client.query(`UPDATE ${tableModel.table} SET visueltcenter = ST_SetSRID(ST_GeomFromGeoJSON($1), 25832),bbox=st_envelope(geom) WHERE ${whereClause}`, [JSON.stringify(visualCenterGeojson)]);
      }
    }
  }
  if(clearHistory) {
    yield initChangeTable(client, txid, tableModel);
  }
  else {
    yield applyCurrentTableToChangeTable(client, tableModel, ['bbox', 'visueltcenter']);
  }
});
Ejemplo n.º 3
0
const materializeWithoutEvents = (client, tableModels, materialization, columnNames) => go(function*() {
  const tableModel = tableModels[materialization.table];
  yield client.query(`UPDATE ${materialization.table} t
  SET ${columnNames.map(col => `${col} = v.${col}`).join(', ')} 
  FROM ${materialization.view} v 
  WHERE ${columnsEqualClause('t', 'v', tableModel.primaryKey)}`);
  yield applyCurrentTableToChangeTable(client, tableModel, columnNames);
});
Ejemplo n.º 4
0
  yield proddb.withTransaction('READ_WRITE', client => go(function*() {
    yield client.query(fs.readFileSync(require.resolve('./schema/tables/blobref.sql'), {encoding: 'utf8'}));
    yield client.query(fs.readFileSync(require.resolve('./schema/tables/vask_adgangsadresser.sql'), {encoding: 'utf8'}));
    yield client.query(fs.readFileSync(require.resolve('./schema/tables/vask_adresser.sql'), {encoding: 'utf8'}));
    yield createChangeTable(client, tableSchema.tables.vask_adgangsadresser);
    yield createChangeTable(client, tableSchema.tables.vask_adresser);
    yield client.query('alter table stedtilknytninger_changes alter public drop not null');
    yield client.query('alter table navngivenvej_postnummer_changes alter public drop not null');
    yield withMigrationTransaction(client, 'migrate_1_28_0', (txid) => go(function*() {
      yield generateHistory(client, txid, '2018-05-05T00:00:00.000Z');
    }));
    const offloadedTables = ['vejmidter', 'ejerlav', 'steder', ...temaModels.map(tema => tema.table)];
    for(let table of offloadedTables) {
      yield client.query(`
    ALTER TABLE ${table} ADD COLUMN geom_blobref text;
ALTER TABLE ${table}_changes ADD COLUMN geom_blobref text;
DELETE FROM ${table}_changes
`);

    }
    yield client.query(`
ALTER TABLE hoejde_importer_afventer DROP COLUMN disableuntil;
create table hoejde_importer_disabled(
                                       husnummerid uuid primary key,
  -- disable height lookup until this timestamp
                                       disableuntil timestamptz
);
ALTER TABLE ikke_brofaste_adresser DROP CONSTRAINT ikke_brofaste_adresser_pkey,
                         ADD PRIMARY KEY(adgangsadresseid);`);
    yield withImportTransaction(client, 'migrate_1_28_0', (txid) => go(function*() {
      for(let table of offloadedTables) {
        const tableModel = tableSchema.tables[table];
        yield migrateS3Offloaded(client, txid, tableModel);
      }
    }));
    yield reloadDatabaseCode(client, path.join(__dirname, 'schema'));
    yield client.query('UPDATE vejstykker t set oprettet = v.oprettet FROM vejstykker_view v WHERE v.kommunekode= t.kommunekode AND v.kode = t.kode');
    yield applyCurrentTableToChangeTable(client, tableSchema.tables.vejstykker, ['oprettet']);
  }));