mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(api): ability to archive boards
This commit is contained in:
parent
3e0fb45dd7
commit
c33111468e
@ -73,7 +73,8 @@ async def update_board(
|
|||||||
try:
|
try:
|
||||||
result = ApiDependencies.invoker.services.boards.update(board_id=board_id, changes=changes)
|
result = ApiDependencies.invoker.services.boards.update(board_id=board_id, changes=changes)
|
||||||
return result
|
return result
|
||||||
except Exception:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
raise HTTPException(status_code=500, detail="Failed to update board")
|
raise HTTPException(status_code=500, detail="Failed to update board")
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ class BoardRecord(BaseModelExcludeNull):
|
|||||||
"""The updated timestamp of the image."""
|
"""The updated timestamp of the image."""
|
||||||
cover_image_name: Optional[str] = Field(default=None, description="The name of the cover image of the board.")
|
cover_image_name: Optional[str] = Field(default=None, description="The name of the cover image of the board.")
|
||||||
"""The name of the cover image of the board."""
|
"""The name of the cover image of the board."""
|
||||||
|
archived: Optional[bool] = Field(default=None, description="Whether or not the board is archived.")
|
||||||
|
"""Whether or not the board is archived."""
|
||||||
|
|
||||||
|
|
||||||
def deserialize_board_record(board_dict: dict) -> BoardRecord:
|
def deserialize_board_record(board_dict: dict) -> BoardRecord:
|
||||||
@ -35,6 +37,7 @@ def deserialize_board_record(board_dict: dict) -> BoardRecord:
|
|||||||
created_at = board_dict.get("created_at", get_iso_timestamp())
|
created_at = board_dict.get("created_at", get_iso_timestamp())
|
||||||
updated_at = board_dict.get("updated_at", get_iso_timestamp())
|
updated_at = board_dict.get("updated_at", get_iso_timestamp())
|
||||||
deleted_at = board_dict.get("deleted_at", get_iso_timestamp())
|
deleted_at = board_dict.get("deleted_at", get_iso_timestamp())
|
||||||
|
archived = board_dict.get("archived", False)
|
||||||
|
|
||||||
return BoardRecord(
|
return BoardRecord(
|
||||||
board_id=board_id,
|
board_id=board_id,
|
||||||
@ -43,12 +46,14 @@ def deserialize_board_record(board_dict: dict) -> BoardRecord:
|
|||||||
created_at=created_at,
|
created_at=created_at,
|
||||||
updated_at=updated_at,
|
updated_at=updated_at,
|
||||||
deleted_at=deleted_at,
|
deleted_at=deleted_at,
|
||||||
|
archived=archived
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BoardChanges(BaseModel, extra="forbid"):
|
class BoardChanges(BaseModel, extra="forbid"):
|
||||||
board_name: Optional[str] = Field(default=None, description="The board's new name.")
|
board_name: Optional[str] = Field(default=None, description="The board's new name.")
|
||||||
cover_image_name: Optional[str] = Field(default=None, description="The name of the board's new cover image.")
|
cover_image_name: Optional[str] = Field(default=None, description="The name of the board's new cover image.")
|
||||||
|
archived: Optional[bool] = Field(default=None, description="Whether or not the board is archived")
|
||||||
|
|
||||||
|
|
||||||
class BoardRecordNotFoundException(Exception):
|
class BoardRecordNotFoundException(Exception):
|
||||||
|
@ -125,8 +125,20 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase):
|
|||||||
(changes.cover_image_name, board_id),
|
(changes.cover_image_name, board_id),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Change the archived status of a board
|
||||||
|
if changes.archived is not None:
|
||||||
|
self._cursor.execute(
|
||||||
|
"""--sql
|
||||||
|
UPDATE boards
|
||||||
|
SET archived = ?
|
||||||
|
WHERE board_id = ?;
|
||||||
|
""",
|
||||||
|
(changes.archived, board_id),
|
||||||
|
)
|
||||||
|
|
||||||
self._conn.commit()
|
self._conn.commit()
|
||||||
except sqlite3.Error as e:
|
except sqlite3.Error as e:
|
||||||
|
print(e)
|
||||||
self._conn.rollback()
|
self._conn.rollback()
|
||||||
raise BoardRecordSaveException from e
|
raise BoardRecordSaveException from e
|
||||||
finally:
|
finally:
|
||||||
@ -136,7 +148,7 @@ class SqliteBoardRecordStorage(BoardRecordStorageBase):
|
|||||||
def get_many(
|
def get_many(
|
||||||
self,
|
self,
|
||||||
offset: int = 0,
|
offset: int = 0,
|
||||||
limit: int = 10,
|
limit: int = 10
|
||||||
) -> OffsetPaginatedResults[BoardRecord]:
|
) -> OffsetPaginatedResults[BoardRecord]:
|
||||||
try:
|
try:
|
||||||
self._lock.acquire()
|
self._lock.acquire()
|
||||||
|
@ -15,6 +15,7 @@ from invokeai.app.services.shared.sqlite_migrator.migrations.migration_9 import
|
|||||||
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_10 import build_migration_10
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_10 import build_migration_10
|
||||||
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_11 import build_migration_11
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_11 import build_migration_11
|
||||||
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_12 import build_migration_12
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_12 import build_migration_12
|
||||||
|
from invokeai.app.services.shared.sqlite_migrator.migrations.migration_13 import build_migration_13
|
||||||
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_impl import SqliteMigrator
|
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_impl import SqliteMigrator
|
||||||
|
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ def init_db(config: InvokeAIAppConfig, logger: Logger, image_files: ImageFileSto
|
|||||||
migrator.register_migration(build_migration_10())
|
migrator.register_migration(build_migration_10())
|
||||||
migrator.register_migration(build_migration_11(app_config=config, logger=logger))
|
migrator.register_migration(build_migration_11(app_config=config, logger=logger))
|
||||||
migrator.register_migration(build_migration_12(app_config=config))
|
migrator.register_migration(build_migration_12(app_config=config))
|
||||||
|
migrator.register_migration(build_migration_13())
|
||||||
migrator.run_migrations()
|
migrator.run_migrations()
|
||||||
|
|
||||||
return db
|
return db
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
import sqlite3
|
||||||
|
|
||||||
|
from invokeai.app.services.shared.sqlite_migrator.sqlite_migrator_common import Migration
|
||||||
|
|
||||||
|
|
||||||
|
class Migration13Callback:
|
||||||
|
def __call__(self, cursor: sqlite3.Cursor) -> None:
|
||||||
|
self._update_error_cols(cursor)
|
||||||
|
|
||||||
|
def _update_error_cols(self, cursor: sqlite3.Cursor) -> None:
|
||||||
|
"""
|
||||||
|
- Adds `archived` columns to the board table.
|
||||||
|
"""
|
||||||
|
|
||||||
|
cursor.execute("ALTER TABLE boards ADD COLUMN archived BOOLEAN DEFAULT FALSE;")
|
||||||
|
|
||||||
|
|
||||||
|
def build_migration_13() -> Migration:
|
||||||
|
"""
|
||||||
|
Build the migration from database version 12 to 13..
|
||||||
|
|
||||||
|
This migration does the following:
|
||||||
|
- Adds `archived` columns to the board table.
|
||||||
|
"""
|
||||||
|
migration_13 = Migration(
|
||||||
|
from_version=12,
|
||||||
|
to_version=13,
|
||||||
|
callback=Migration13Callback(),
|
||||||
|
)
|
||||||
|
|
||||||
|
return migration_13
|
Loading…
Reference in New Issue
Block a user