Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Sqlalcehmy to the v2 #746

Merged
merged 9 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions alws/database.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# -*- mode:python; coding:utf-8; -*-
# author: Vyacheslav Potoropin <[email protected]>
# created: 2021-06-22
from sqlalchemy import create_engine
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy import MetaData, create_engine
from sqlalchemy.ext.asyncio import (
AsyncAttrs,
AsyncSession,
create_async_engine,
)
from sqlalchemy.orm import DeclarativeBase, scoped_session, sessionmaker
from sqlalchemy.pool import NullPool

from alws.config import settings
Expand All @@ -18,12 +21,22 @@
sync_engine = create_engine(
settings.sync_database_url, pool_pre_ping=True, pool_recycle=3600
)
Base = declarative_base()


class Base(AsyncAttrs, DeclarativeBase):
__allow_unmapped__ = True
metadata = MetaData()


sync_session_factory = sessionmaker(sync_engine, expire_on_commit=False)
Session = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)
SyncSession = scoped_session(sync_session_factory)

PulpBase = declarative_base()

class PulpBase(AsyncAttrs, DeclarativeBase):
__allow_unmapped__ = True


pulp_engine = create_engine(
settings.pulp_database_url, pool_pre_ping=True, pool_recycle=3600
)
Expand Down
Loading
Loading