def downgrade():
    database_init(database)
    migrator = PostgresqlMigrator(database)
    try:
        migrate(migrator.rename_table("auth_users", "users"))
        migrate(migrator.rename_table("podcast_podcasts", "podcasts"))
        migrate(migrator.rename_table("podcast_episodes", "episodes"))
    except Exception as err:
        print(f"Couldn't rename table: {err}. SKIP")
Beispiel #2
0
def run_worker():
    """ Allows to run RQ worker for consuming background tasks (like downloading youtube tracks)
    """
    database_init(database)

    if settings.SENTRY_DSN:
        sentry_logging = LoggingIntegration(level=logging.INFO,
                                            event_level=logging.ERROR)
        sentry_sdk.init(settings.SENTRY_DSN,
                        integrations=[RqIntegration(), sentry_logging])

    with Connection(Redis(*settings.REDIS_CON)):
        qs = sys.argv[1:] or ["default"]
        Worker(qs).work()
def downgrade():
    database_init(database)
    remove_tables(models)
Beispiel #4
0
 def wrapper(*args, **kwargs):
     db_objects = peewee_async.Manager(database_init(database))
     with db_objects.allow_sync():
         return func(*args, **kwargs)
def upgrade():
    database_init(database)
    create_tables(models)
Beispiel #6
0
def db_objects():
    return peewee_async.Manager(database_init(database))
def downgrade():
    database_init(database)
    query = Episode.update(downloaded=True).where(
        Episode.status == Episode.STATUS_PUBLISHED)
    query.execute()
def upgrade():
    database_init(database)
    query = Episode.update(status=Episode.STATUS_PUBLISHED).where(
        Episode.downloaded == True)
    query.execute()
Beispiel #9
0
async def create_app() -> PodcastWebApp:
    """ Prepare application """
    redis_pool = await aioredis.create_pool(settings.REDIS_CON)
    session_engine = SimpleCookieStorage(
    ) if settings.TEST_MODE else RedisStorage(redis_pool)
    middlewares = [
        session_middleware(session_engine),
        request_user_middleware,
        aiohttp_i18n.babel_middleware(),
    ]

    if settings.DEBUG:
        middlewares.append(aiohttp_debugtoolbar.middleware)

    app = PodcastWebApp(middlewares=middlewares,
                        logger=logger,
                        debug=settings.DEBUG)
    app.redis_pool = redis_pool
    app.gettext_translation = app_i18n.aiohttp_translations
    app.on_shutdown.append(shutdown_app)

    # db conn
    app.database = database_init(database)
    app.database.set_allow_sync(False)
    app.objects = peewee_async.Manager(app.database)

    app["static_root_url"] = settings.STATIC_URL
    jinja_env = aiohttp_jinja2.setup(
        app,
        loader=jinja2.FileSystemLoader(settings.TEMPLATE_PATH),
        context_processors=[
            aiohttp_jinja2.request_processor,
            context_processors.podcast_items,
            context_processors.mobile_app_web_view,
        ],
        filters={
            "datetime_format": jinja_filters.datetime_format,
            "human_length": jinja_filters.human_length,
        },
        extensions=["jinja2.ext.i18n"],
    )
    jinja_env.globals.update(tags)
    jinja_env.install_gettext_translations(app.gettext_translation)
    if settings.DEBUG:
        aiohttp_debugtoolbar.setup(app, intercept_redirects=False)

    # make routes
    from urls import urls as app_routes

    for route in app_routes:
        app.router.add_route(**route.as_dict)

    app.router.add_static("/static", settings.STATIC_PATH, name="static")

    app.logger = get_logger()
    app.rq_queue = rq.Queue(
        name="youtube_downloads",
        connection=Redis(*settings.REDIS_CON),
        default_timeout=settings.RQ_DEFAULT_TIMEOUT,
    )

    if settings.SENTRY_DSN:
        sentry_logging = LoggingIntegration(level=logging.INFO,
                                            event_level=logging.ERROR)
        sentry_sdk.init(settings.SENTRY_DSN,
                        integrations=[AioHttpIntegration(), sentry_logging])

    return app
Beispiel #10
0
    "downgrade": migrations_downgrade,
    "show": show_migration_history,
}

parser = argparse.ArgumentParser(
    usage="venv/bin/python -m migrations.run create|upgrade|downgrade|show")
parser.add_argument(
    "operation",
    metavar="Operation-Type",
    type=str,
    choices=operations_map.keys(),
    help="""
        "create" - create migration module; 
        "upgrade" - apply all not applied migrations;  
        "downgrade" - downgrade applied migrations (all after specified);  
        "show" - print list of applied migrations;
    """,
)
parser.add_argument(
    "--revision",
    metavar="Migration Number",
    type=str,
    default="",
)

args = parser.parse_args()
handler = operations_map[args.operation]
database_init(database)
args = [args.revision] if args.revision else []
handler(*args)