def _require_extensions(*names): missing = sorted(name for name in names if not has_extension(db.engine, name)) if not missing: return True click.secho(f"Required Postgres extensions missing: {', '.join(missing)}", fg='red') click.secho('Create them using these SQL commands (as a Postgres superuser):', fg='yellow') for name in missing: click.secho(f' CREATE EXTENSION {name};', bold=True) return False
def _require_extensions(*names): missing = sorted(name for name in names if not has_extension(db.engine, name)) if not missing: return True print(cformat('%{red}Required Postgres extensions missing: {}').format(', '.join(missing))) print(cformat('%{yellow}Create them using these SQL commands (as a Postgres superuser):')) for name in missing: print(cformat('%{white!} CREATE EXTENSION {};').format(name)) return False
def _require_extensions(*names): missing = sorted(name for name in names if not has_extension(db.engine, name)) if not missing: return True print colored('Required Postgres extensions missing: {}'.format(', '.join(missing)), 'red') print colored('Create them using these SQL commands (as a Postgres superuser):', 'yellow') for name in missing: print colored(' CREATE EXTENSION {};'.format(name), 'white', attrs={'bold': True}) return False
def upgrade(): if context.is_offline_mode(): raise Exception('This upgrade is only possible in online mode') if has_extension(op.get_bind(), 'unaccent'): print 'Unaccent extension is available - indico_unaccent will use it' op.execute(SQL_FUNCTION_UNACCENT) else: print 'Unaccent extension is NOT available - indico_unaccent will not touch its argument' op.execute(SQL_FUNCTION_NOOP)
def _after_create(target, conn, **kw): assert target is column.table col_func = func.indico_unaccent(func.lower(column)) index_kwargs = {} if not current_app.config['TESTING'] and has_extension(conn, 'pg_trgm'): index_kwargs = {'postgresql_using': 'gin', 'postgresql_ops': {col_func.key: 'gin_trgm_ops'}} elif not current_app.config['TESTING']: print 'Warning: pg_trgm extension is not available' Index(conv('ix_{}_{}_unaccent'.format(column.table.name, column.name)), col_func, **index_kwargs).create(conn)
def create_unaccent_function(conn): """Creates the unaccent function if it doesn't exist yet. In TESTING mode it always uses the no-op version to have a consistent database setup. """ if not current_app.config['TESTING'] and has_extension(conn, 'unaccent'): DDL(SQL_FUNCTION_UNACCENT).execute_if(callable_=_should_create_function).execute(conn) else: if not current_app.config['TESTING']: print 'Warning: unaccent extension is not available' DDL(SQL_FUNCTION_NOOP).execute_if(callable_=_should_create_function).execute(conn)
def create_unaccent_function(conn): """Creates the unaccent function if it doesn't exist yet. In TESTING mode it always uses the no-op version to have a consistent database setup. """ if not current_app.config['TESTING'] and has_extension(conn, 'unaccent'): DDL(SQL_FUNCTION_UNACCENT).execute_if( callable_=_should_create_function).execute(conn) else: if not current_app.config['TESTING']: print 'Warning: unaccent extension is not available' DDL(SQL_FUNCTION_NOOP).execute_if( callable_=_should_create_function).execute(conn)
def upgrade(): if context.is_offline_mode(): raise Exception('This upgrade is only possible in online mode') has_trgm = has_extension(op.get_bind(), 'pg_trgm') if has_trgm: print 'pg_trgm extension is available - creating trigram indexes' else: print 'pg_trgm extension is not available - creating normal indexes' _create_index(has_trgm, 'users', 'first_name') _create_index(has_trgm, 'users', 'last_name') _create_index(has_trgm, 'users', 'phone') _create_index(has_trgm, 'users', 'address') _create_index(has_trgm, 'affiliations', 'name') _create_index(has_trgm, 'emails', 'email')
def _after_create(target, conn, **kw): assert target is column.table col_func = func.indico_unaccent(func.lower(column)) index_kwargs = {} if not current_app.config['TESTING'] and has_extension( conn, 'pg_trgm'): index_kwargs = { 'postgresql_using': 'gin', 'postgresql_ops': { col_func.key: 'gin_trgm_ops' } } elif not current_app.config['TESTING']: print 'Warning: pg_trgm extension is not available' Index(conv('ix_{}_{}_unaccent'.format(column.table.name, column.name)), col_func, **index_kwargs).create(conn)