Fixes to memory component
This commit is contained in:
parent
6afecd268e
commit
fee4982aa2
2 changed files with 10 additions and 12 deletions
|
|
@ -9,7 +9,7 @@ from relationaldb.models import memory, metadatas, operation, sessions, user, do
|
|||
from sqlalchemy import create_engine, text
|
||||
from dotenv import load_dotenv
|
||||
from relationaldb.database import (
|
||||
Base,DatabaseConfig)
|
||||
Base,get_sqlalchemy_database_url)
|
||||
from cognitive_architecture.config import Config
|
||||
config = Config()
|
||||
config.load()
|
||||
|
|
@ -22,10 +22,9 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
class DatabaseManager:
|
||||
"""Manages database creation, deletion, and table initialization."""
|
||||
def __init__(self, config: DatabaseConfig):
|
||||
"""Initialize the DatabaseManager with a given configuration."""
|
||||
self.config = config
|
||||
self.engine = create_async_engine(config.get_sqlalchemy_database_url(), echo=True)
|
||||
def __init__(self):
|
||||
"""Initialize the Database Url with a given configuration."""
|
||||
self.engine = create_async_engine(get_sqlalchemy_database_url(), echo=True)
|
||||
self.db_type = config.db_type
|
||||
|
||||
@asynccontextmanager
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
"""This module is used to create the database and tables for the cognitive architecture."""
|
||||
import asyncio
|
||||
import logging
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from cognitive_architecture.config import Config
|
||||
from cognitive_architecture.database.create_database import DatabaseManager
|
||||
from cognitive_architecture.database.relationaldb.database import DatabaseConfig
|
||||
|
||||
|
||||
config = Config()
|
||||
config.load()
|
||||
|
|
@ -15,9 +15,9 @@ logger = logging.getLogger(__name__)
|
|||
async def main():
|
||||
"""Runs as a part of startup docker scripts to create the database and tables."""
|
||||
|
||||
dbconfig = DatabaseConfig(db_type=config.db_type, db_name=config.db_name)
|
||||
db_manager = DatabaseManager(config=dbconfig)
|
||||
database_name = dbconfig.db_name
|
||||
|
||||
db_manager = DatabaseManager()
|
||||
database_name = config.db_name
|
||||
|
||||
if not await db_manager.database_exists(database_name):
|
||||
print(f"Database {database_name} does not exist. Creating...")
|
||||
|
|
@ -27,5 +27,4 @@ async def main():
|
|||
await db_manager.create_tables()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
asyncio.run(main())
|
||||
asyncio.run(main())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue