Add precondition check for database validation
This commit is contained in:
parent
3ecc6574ae
commit
7985167411
3 changed files with 38 additions and 2 deletions
|
@ -1,6 +1,6 @@
|
|||
from peewee import OperationalError
|
||||
|
||||
from data.database import validate_database_url
|
||||
from data.database import validate_database_precondition
|
||||
from util.config.validators import BaseValidator, ConfigValidationException
|
||||
|
||||
class DatabaseValidator(BaseValidator):
|
||||
|
@ -12,7 +12,7 @@ class DatabaseValidator(BaseValidator):
|
|||
config = validator_context.config
|
||||
|
||||
try:
|
||||
validate_database_url(config['DB_URI'], config.get('DB_CONNECTION_ARGS', {}))
|
||||
validate_database_precondition(config['DB_URI'], config.get('DB_CONNECTION_ARGS', {}))
|
||||
except OperationalError as ex:
|
||||
if ex.args and len(ex.args) > 1:
|
||||
raise ConfigValidationException(ex.args[1])
|
||||
|
|
|
@ -4,6 +4,7 @@ import json
|
|||
|
||||
import anunidecode # Don't listen to pylint's lies. This import is required.
|
||||
|
||||
from peewee import OperationalError
|
||||
|
||||
INVALID_PASSWORD_MESSAGE = 'Invalid password, password must be at least ' + \
|
||||
'8 characters and contain no whitespace.'
|
||||
|
@ -89,3 +90,12 @@ def is_json(value):
|
|||
except (TypeError, ValueError):
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def validate_postgres_precondition(driver):
|
||||
cursor = driver.execute_sql("SELECT extname FROM pg_extension", ("public",))
|
||||
if 'pg_trgm' not in [extname for extname, in cursor.fetchall()]:
|
||||
raise OperationalError("""
|
||||
"pg_trgm" extension does not exists in the database.
|
||||
Please run `CREATE EXTENSION IF NOT EXISTS pg_trgm;` as superuser on this database.
|
||||
""")
|
||||
|
|
Reference in a new issue