Coverage for src/lexigram/notification/cli/schema_setup.py: 0%

12 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-26 07:17 +0800

1"""Schema setup contributions for the lexigram-notification package.""" 

2 

3from __future__ import annotations 

4 

5from lexigram.contracts.cli.contributions import SchemaSetupOutcome, SchemaSetupResult 

6from lexigram.contracts.data.sql.database import DatabaseProviderProtocol 

7 

8_INBOX_TABLE = "notification_inbox_messages" 

9 

10 

11async def ensure_inbox_messages(db: DatabaseProviderProtocol) -> SchemaSetupOutcome: 

12 """Ensure the ``notification_inbox_messages`` table exists. 

13 

14 Args: 

15 db: The database provider. 

16 

17 Returns: 

18 Outcome reporting CREATED, ALREADY_PRESENT, or FAILED. 

19 """ 

20 from lexigram.notification.inbox.database import DatabaseInboxStore 

21 

22 try: 

23 existed = await db.table_exists(_INBOX_TABLE) 

24 await DatabaseInboxStore(db)._ensure_table() 

25 return SchemaSetupOutcome( 

26 status=( 

27 SchemaSetupResult.ALREADY_PRESENT 

28 if existed 

29 else SchemaSetupResult.CREATED 

30 ) 

31 ) 

32 except Exception as exc: 

33 return SchemaSetupOutcome(status=SchemaSetupResult.FAILED, message=str(exc))