feat(db): instantiate SqliteMigrator with a SqliteDatabase

Simplifies a couple things:
- Init is more straightforward
- It's clear in the migrator that the connection we are working with is related to the SqliteDatabase
This commit is contained in:
psychedelicious
2023-12-12 10:46:08 +11:00
parent 417db71471
commit 3414437eea
7 changed files with 58 additions and 101 deletions

View File

@ -44,13 +44,7 @@ def store(app_config: InvokeAIAppConfig) -> ModelRecordServiceBase:
logger = InvokeAILogger.get_logger(config=app_config)
db_path = None if app_config.use_memory_db else app_config.db_path
db = SqliteDatabase(db_path=db_path, logger=logger, verbose=app_config.log_sql)
migrator = SQLiteMigrator(
db_path=db.db_path,
conn=db.conn,
lock=db.lock,
logger=logger,
log_sql=app_config.log_sql,
)
migrator = SQLiteMigrator(db=db)
migrator.register_migration(migration_1)
migrator.register_migration(migration_2)
migrator.run_migrations()

View File

@ -35,13 +35,7 @@ def store(datadir: Any) -> ModelRecordServiceBase:
logger = InvokeAILogger.get_logger(config=config)
db_path = None if config.use_memory_db else config.db_path
db = SqliteDatabase(db_path=db_path, logger=logger, verbose=config.log_sql)
migrator = SQLiteMigrator(
db_path=db.db_path,
conn=db.conn,
lock=db.lock,
logger=logger,
log_sql=config.log_sql,
)
migrator = SQLiteMigrator(db=db)
migrator.register_migration(migration_1)
migrator.register_migration(migration_2)
migrator.run_migrations()