kopia lustrzana https://github.com/kartoza/docker-osm
Search for OSM tables in proper schema during initialisations in enrich and imposm
rodzic
ce4af9794a
commit
2acc3d485f
|
@ -102,6 +102,7 @@ services:
|
||||||
- IMPORT_QUEUE=${IMPORT_QUEUE}
|
- IMPORT_QUEUE=${IMPORT_QUEUE}
|
||||||
- IMPORT_DONE=${IMPORT_DONE}
|
- IMPORT_DONE=${IMPORT_DONE}
|
||||||
- TIME=${TIME}
|
- TIME=${TIME}
|
||||||
|
- DBSCHEMA_PRODUCTION=${DBSCHEMA_PRODUCTION}
|
||||||
|
|
||||||
martin:
|
martin:
|
||||||
image: urbica/martin
|
image: urbica/martin
|
||||||
|
|
|
@ -103,3 +103,4 @@ services:
|
||||||
- IMPORT_QUEUE=${IMPORT_QUEUE}
|
- IMPORT_QUEUE=${IMPORT_QUEUE}
|
||||||
- IMPORT_DONE=${IMPORT_DONE}
|
- IMPORT_DONE=${IMPORT_DONE}
|
||||||
- TIME=${TIME}
|
- TIME=${TIME}
|
||||||
|
- DBSCHEMA_PRODUCTION=${DBSCHEMA_PRODUCTION}
|
||||||
|
|
|
@ -19,14 +19,15 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from sys import exit, stderr
|
|
||||||
from os import environ, listdir, mknod
|
from os import environ, listdir, mknod
|
||||||
from shutil import move
|
|
||||||
from os.path import join, exists, abspath, isabs
|
from os.path import join, exists, abspath, isabs
|
||||||
from psycopg2 import connect, OperationalError
|
from shutil import move
|
||||||
from subprocess import call
|
from subprocess import call
|
||||||
|
from sys import exit, stderr
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
from psycopg2 import connect, OperationalError
|
||||||
|
|
||||||
|
|
||||||
class Importer(object):
|
class Importer(object):
|
||||||
|
|
||||||
|
@ -230,10 +231,11 @@ class Importer(object):
|
||||||
command += ['-f', self.qgis_style]
|
command += ['-f', self.qgis_style]
|
||||||
call(command)
|
call(command)
|
||||||
|
|
||||||
def locate_table(self, name):
|
def locate_table(self, name, schema):
|
||||||
"""Check for tables in the DB table exists in the DB"""
|
"""Check for tables in the DB table exists in the DB"""
|
||||||
sql = """ SELECT EXISTS (SELECT 1 AS result from information_schema.tables where table_name like 'TEMP_TABLE'); """
|
sql = """ SELECT EXISTS (SELECT 1 AS result from information_schema.tables
|
||||||
self.cursor.execute(sql.replace('TEMP_TABLE', '%s' % name))
|
where table_name like TEMP_TABLE and table_schema = 'TEMP_SCHEMA'); """
|
||||||
|
self.cursor.execute(sql.replace('TEMP_TABLE', '%s' % name).replace('TEMP_SCHEMA', '%s' % schema))
|
||||||
# noinspection PyUnboundLocalVariable
|
# noinspection PyUnboundLocalVariable
|
||||||
return self.cursor.fetchone()[0]
|
return self.cursor.fetchone()[0]
|
||||||
|
|
||||||
|
@ -244,9 +246,11 @@ class Importer(object):
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""First checker."""
|
"""First checker."""
|
||||||
osm_tables = self.locate_table('osm_%')
|
|
||||||
|
osm_tables = self.locate_table("'osm_%'", self.default['DBSCHEMA_PRODUCTION'])
|
||||||
|
|
||||||
if osm_tables != 1:
|
if osm_tables != 1:
|
||||||
|
|
||||||
# It means that the DB is empty. Let's import the PBF file.
|
# It means that the DB is empty. Let's import the PBF file.
|
||||||
|
|
||||||
if self.clip_json_file:
|
if self.clip_json_file:
|
||||||
|
|
|
@ -231,7 +231,8 @@ class Enrich(object):
|
||||||
if enrich_type == 'int':
|
if enrich_type == 'int':
|
||||||
new_columns_postgis.append('ADD COLUMN IF NOT EXISTS %s NUMERIC' % enrich_key)
|
new_columns_postgis.append('ADD COLUMN IF NOT EXISTS %s NUMERIC' % enrich_key)
|
||||||
elif enrich_type == 'string':
|
elif enrich_type == 'string':
|
||||||
new_columns_postgis.append('ADD COLUMN IF NOT EXISTS %s CHARACTER VARYING (255)' % enrich_key)
|
new_columns_postgis.append(
|
||||||
|
'ADD COLUMN IF NOT EXISTS %s CHARACTER VARYING (255)' % enrich_key)
|
||||||
elif enrich_type == 'datetime':
|
elif enrich_type == 'datetime':
|
||||||
new_columns_postgis.append('ADD COLUMN IF NOT EXISTS %s TIMESTAMPTZ' % enrich_key)
|
new_columns_postgis.append('ADD COLUMN IF NOT EXISTS %s TIMESTAMPTZ' % enrich_key)
|
||||||
|
|
||||||
|
@ -420,7 +421,8 @@ class Enrich(object):
|
||||||
row_batch = {}
|
row_batch = {}
|
||||||
osm_ids = []
|
osm_ids = []
|
||||||
try:
|
try:
|
||||||
check_sql = ''' select * from "%s" WHERE "changeset_timestamp" IS NULL AND "osm_id" IS NOT NULL ORDER BY "osm_id" ''' % table_name
|
check_sql = ''' select * from "%s" WHERE "changeset_timestamp"
|
||||||
|
IS NULL AND "osm_id" IS NOT NULL ORDER BY "osm_id" ''' % table_name
|
||||||
cursor.execute(check_sql)
|
cursor.execute(check_sql)
|
||||||
row = True
|
row = True
|
||||||
while row:
|
while row:
|
||||||
|
@ -556,12 +558,13 @@ class Enrich(object):
|
||||||
except IOError:
|
except IOError:
|
||||||
self.info('cache file can\'t be created')
|
self.info('cache file can\'t be created')
|
||||||
|
|
||||||
def locate_table(self, name):
|
def locate_table(self, name, schema):
|
||||||
"""Check for tables in the DB table exists in the DB"""
|
"""Check for tables in the DB table exists in the DB"""
|
||||||
connection = self.create_connection()
|
connection = self.create_connection()
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
sql = """ SELECT EXISTS (SELECT 1 AS result from information_schema.tables where table_name like 'TEMP_TABLE'); """
|
sql = """ SELECT EXISTS (SELECT 1 AS result from information_schema.tables
|
||||||
cursor.execute(sql.replace('TEMP_TABLE', '%s' % name))
|
where table_name like TEMP_TABLE and table_schema = 'TEMP_SCHEMA'); """
|
||||||
|
self.cursor.execute(sql.replace('TEMP_TABLE', '%s' % name).replace('TEMP_SCHEMA', '%s' % schema))
|
||||||
# noinspection PyUnboundLocalVariable
|
# noinspection PyUnboundLocalVariable
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
|
|
||||||
|
@ -569,7 +572,8 @@ class Enrich(object):
|
||||||
"""First checker."""
|
"""First checker."""
|
||||||
while True:
|
while True:
|
||||||
self.info('Run enrich process')
|
self.info('Run enrich process')
|
||||||
osm_tables = self.locate_table('osm_%')
|
|
||||||
|
osm_tables = self.locate_table("'osm_%'", self.default['DBSCHEMA_PRODUCTION'])
|
||||||
if osm_tables != 1:
|
if osm_tables != 1:
|
||||||
self.info('Imposm is still running, wait a while and try again')
|
self.info('Imposm is still running, wait a while and try again')
|
||||||
else:
|
else:
|
||||||
|
|
Ładowanie…
Reference in New Issue