@classmethod
    def create_persistent_store(cls, persistent_store_name, spatial=False):
        # Get database manager url from the config
        database_manager_db = settings.TETHYS_DATABASES['tethys_db_manager']
        database_manager_name = database_manager_db['USER'] if 'USER' in database_manager_db else 'tethys_db_manager'

        database_manager_url = 'postgresql://{0}:{1}@{2}:{3}/{4}'.format(
            database_manager_name,
            database_manager_db['PASSWORD'] if 'PASSWORD' in database_manager_db else 'pass',
            database_manager_db['HOST'] if 'HOST' in database_manager_db else '127.0.0.1',
            database_manager_db['PORT'] if 'PORT' in database_manager_db else '5435',
            database_manager_db['NAME'] if 'NAME' in database_manager_db else 'tethys_db_manager'
        )

        # Compose db name
        full_db_name = '_'.join((cls.package, persistent_store_name))
        engine = create_engine(database_manager_url)

        if cls.persistent_store_exists(persistent_store_name):
            raise NameError('Database with name "{0}" for app "{1}" already exists.'.format(
                persistent_store_name,
                cls.package
            ))

        # Cannot create databases in a transaction: connect and commit to close transaction
        create_connection = engine.connect()

        # Create db
        create_db_statement = '''
                              CREATE DATABASE {0}
                              WITH OWNER {1}
                              TEMPLATE template0
                              ENCODING 'UTF8'
                              '''.format(full_db_name, database_manager_name)

        # Close transaction first and then execute
        create_connection.execute('commit')
        create_connection.execute(create_db_statement)
        create_connection.close()

        # Enable PostGIS extension
        if spatial:
            # Get URL for Tethys Superuser to enable extensions
            super_db = settings.TETHYS_DATABASES['tethys_super']

            new_db_url = 'postgresql://{0}:{1}@{2}:{3}/{4}'.format(
                super_db['USER'] if 'USER' in super_db else 'tethys_super',
                super_db['PASSWORD'] if 'PASSWORD' in super_db else 'pass',
                super_db['HOST'] if 'HOST' in super_db else '127.0.0.1',
                super_db['PORT'] if 'PORT' in super_db else '5435',
                full_db_name
            )

            # Connect to new database
            new_db_engine = create_engine(new_db_url)
            new_db_connection = new_db_engine.connect()

            # Notify user
            enable_postgis_statement = 'CREATE EXTENSION IF NOT EXISTS postgis'

            # Execute postgis statement
            new_db_connection.execute(enable_postgis_statement)
            new_db_connection.close()

        return True
Creates a new persistent store database for this app.
dataset/ETHPy150Open tethysplatform/tethys/tethys_apps/base/app_base.py/TethysAppBase.create_persistent_store