예제 #1
0
def database(name, owner, template='template0', encoding='UTF8',
             locale='en_US.UTF-8', allow_restart=False):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')
    """

    locale_transform = lambda l: l.strip().lower().replace('-', '')

    if not database_exists(name):
        locales = map(
            locale_transform,
            run('locale -a').split()
        )
        if locale_transform(locale) not in locales:
            if not allow_restart:
                abort(
                    'New locale "{}" must be installed and '
                    'postgres must be restarted after that'.format(
                        locale
                    )
                )
            require_locale(locale)
            restarted(_service_name())

        create_database(name, owner, template=template, encoding=encoding,
                        locale=locale)
예제 #2
0
def database(name,
             owner,
             template='template0',
             encoding='UTF8',
             locale='en_US.UTF-8'):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        if locale not in run('locale -a').split():
            require_locale(locale)
            restarted(_service_name())

        create_database(name,
                        owner,
                        template=template,
                        encoding=encoding,
                        locale=locale)
예제 #3
0
def database(name,
             owner,
             template='template0',
             encoding='UTF8',
             locale='en_US.UTF-8'):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        with watch('/etc/locale.gen') as locales:
            require_locale(locale)
        if locales.changed:
            restarted(_service_name())

        create_database(name,
                        owner,
                        template=template,
                        encoding=encoding,
                        locale=locale)
예제 #4
0
def init_postgres(encoding='UTF8', locale='en_US.UTF-8'):
    """
    Arch postgresql daemon needs to be initiated once with its own user.

    """
    require_locale(locale)
    cmd = "initdb --locale {0} -E {1} -D '/var/lib/postgres/data/'".format(
        locale, encoding
    )
    _run_as_pg(cmd)
예제 #5
0
def database(name, owner, template="template0", encoding="UTF8", locale="en_US.UTF-8"):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        if locale not in run("locale -a").split():
            require_locale(locale)
            restarted(_service_name())

        create_database(name, owner, template=template, encoding=encoding, locale=locale)
예제 #6
0
def database(name, owner, template='template0', encoding='UTF8',
             locale='en_US.UTF-8'):
    """
    Require a PostgreSQL database.

    ::

        from fabtools import require

        require.postgres.database('myapp', owner='dbuser')

    """
    if not database_exists(name):

        with watch('/etc/locale.gen') as locales:
            require_locale(locale)
        if locales.changed:
            restarted(_service_name())

        create_database(name, owner, template=template, encoding=encoding,
                        locale=locale)