fix(server): prevent duplicate geodata temp table (#18580)

drop tmp table, create gist index first
This commit is contained in:
Mert 2025-07-01 06:28:30 +03:00 committed by GitHub
parent 3c6e9e1191
commit a068a41c06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -232,6 +232,7 @@ export class MapRepository {
this.loadAdmin(resourcePaths.geodata.admin2), this.loadAdmin(resourcePaths.geodata.admin2),
]); ]);
await this.db.schema.dropTable('geodata_places_tmp').ifExists().execute();
await this.db.transaction().execute(async (manager) => { await this.db.transaction().execute(async (manager) => {
await sql`CREATE TABLE geodata_places_tmp await sql`CREATE TABLE geodata_places_tmp
( (
@ -240,7 +241,12 @@ export class MapRepository {
await manager.schema.dropTable('geodata_places').execute(); await manager.schema.dropTable('geodata_places').execute();
await manager.schema.alterTable('geodata_places_tmp').renameTo('geodata_places').execute(); await manager.schema.alterTable('geodata_places_tmp').renameTo('geodata_places').execute();
}); });
await this.db.schema
.createIndex('IDX_geodata_gist_earthcoord')
.on('geodata_places')
.using('gist')
.expression(sql`ll_to_earth_public(latitude, longitude)`)
.execute();
await this.loadCities500(admin1, admin2); await this.loadCities500(admin1, admin2);
await this.createGeodataIndices(); await this.createGeodataIndices();
} }
@ -325,12 +331,6 @@ export class MapRepository {
private createGeodataIndices() { private createGeodataIndices() {
return Promise.all([ return Promise.all([
sql`ALTER TABLE geodata_places ADD PRIMARY KEY (id) WITH (FILLFACTOR = 100)`.execute(this.db), sql`ALTER TABLE geodata_places ADD PRIMARY KEY (id) WITH (FILLFACTOR = 100)`.execute(this.db),
sql`
CREATE INDEX IDX_geodata_gist_earthcoord
ON geodata_places
USING gist (ll_to_earth_public(latitude, longitude))
WITH (fillfactor = 100)
`.execute(this.db),
this.db.schema this.db.schema
.createIndex(`idx_geodata_places_alternate_names`) .createIndex(`idx_geodata_places_alternate_names`)
.on('geodata_places') .on('geodata_places')