예제 #1
0
파일: pg.py 프로젝트: dmonroy/meta.data
def create_database():  # pragma: no cover
    """Creates the database, runs the migrations."""

    import psycopg2  # isort:skip
    settings = get_settings()

    dbdata = parse_pgurl(settings.db_url)
    pg_dbdata = dbdata.copy()
    pg_dbdata['database'] = 'postgres'
    conn = psycopg2.connect(**pg_dbdata)
    conn.set_isolation_level(0)
    cur = conn.cursor()

    cur.execute('CREATE DATABASE {}'.format(dbdata['database']))
    cur.close()
    conn.close()

    conn = psycopg2.connect(**dbdata)
    conn.set_isolation_level(0)
    cur = conn.cursor()

    cur.close()
    conn.close()

    run_migrations()
예제 #2
0
파일: pg.py 프로젝트: dmonroy/meta.data
def drop_database():  # pragma: no cover
    """Drops the existing database."""

    import psycopg2  # isort:skip
    settings = get_settings()

    dbdata = parse_pgurl(settings.db_url)
    pg_dbdata = dbdata.copy()
    pg_dbdata['database'] = 'postgres'
    conn = psycopg2.connect(**pg_dbdata)
    conn.set_isolation_level(0)
    cur = conn.cursor()

    cur.execute('DROP DATABASE IF EXISTS {}'.format(dbdata['database']))
    cur.close()
    conn.close()
예제 #3
0
def settings():
    return get_settings()
예제 #4
0
파일: pg.py 프로젝트: dmonroy/meta.data
import asyncio
from urllib.parse import urlsplit

import aiopg
from meta.data.settings import get_settings
from schema_migrations import MigrationController

settings = get_settings()


def parse_pgurl(url):
    """Converts the database url into a dictionary."""

    parsed = urlsplit(url)

    return {
        'user': parsed.username,
        'password': parsed.password,
        'database': parsed.path.lstrip('/'),
        'host': parsed.hostname,
        'port': parsed.port,
    }


@asyncio.coroutine
def create_pool():  # pragma: no cover
    """Creates a connection pool to the database."""

    pool = yield from aiopg.create_pool(
        minsize=settings.db_pool_min,
        maxsize=settings.db_pool_max,