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