Run artifact

workspace/targets/ReadingList/blueprint/DATABASE.md

DATABASE: ReadingList

FieldValue
Version20261023 V1
DescriptionPersistence stores and typed interfaces for ReadingList.
Depends OnARCHITECTURE.md
Providesbooks.create, books.get, books.list, books.delete
Build Order1

Persistence Boundary

BoundaryRule
Raw storage accessOnly the generated persistence/ package reaches the store.
Caller dependencyFeatures depend on declared access patterns and their DTOs, not on schemas.
ImplementationGenerated from this file at the DATABASE build step; never written by hand.

Access Patterns

FEATURE-BOOK-001 — Add a book

FieldValue
OwnerFEATURE-AddBook.md
Accesswrite
Repository operationbooks.create
Compatibilityunchanged

Input: NewBook

FieldTypeNotes
titleTEXTNon-empty, validated by the service before the call.
authorTEXTNon-empty, validated by the service before the call.

Output: Book

FieldTypeNotes
idINTEGERAssigned in insertion order.
titleTEXTAs supplied.
authorTEXTAs supplied.

FEATURE-BOOK-002 — Get a book by id

FieldValue
OwnerDATABASE.md
Accessread
Repository operationbooks.get
Compatibilityunchanged

Input: BookKey

FieldTypeNotes
idINTEGERBook identifier.

Output: Book

FieldTypeNotes
idINTEGERBook identifier.
titleTEXTStored title.
authorTEXTStored author.

FEATURE-BOOK-003 — List books in the order added

FieldValue
OwnerFEATURE-ListBooks.md
Accessread
Repository operationbooks.list
Compatibilityunchanged

Input: BookListQuery

FieldTypeNotes

Output: Book

FieldTypeNotes
idINTEGERRows are returned ordered by id ascending, which is the order added.
titleTEXTStored title.
authorTEXTStored author.

FEATURE-BOOK-004 — Remove a book

FieldValue
OwnerFEATURE-RemoveBook.md
Accesswrite
Repository operationbooks.delete
Compatibilityunchanged

Input: BookKey

FieldTypeNotes
idINTEGERIdentifier of the book to remove.

Output: DeletedBook

FieldTypeNotes
idINTEGERIdentifier of the removed book.

Schemas

books

FieldTypeNotes
idINTEGER PKAutoincrementing key; ascending id is the order added.
titleTEXT NOT NULLBook title.
authorTEXT NOT NULLBook author.

Migrations

Each relational change has one staged record in migrations/MIGRATION-<AccessPatternId>.md. The record carries Alembic upgrade/downgrade snippets and progresses from planned to built only when its DATABASE build story completes. Alembic records deployment application separately.

Access PatternRevisionState

Config (.env)

KeyTypeRequiredNotes
DATABASE_URLstringNoOverrides DATABASE_PATH when set.
DATABASE_PATHstringNoDefaults to data/app.db.

File Stores

StoreRoot dirNotes

External Services

ServiceWrapperNotes

External Libraries

LibraryOwnershipDistributionConsumer Contract

Programmatic Acceptance

=== AC books-create ===
Intent: books.create stores a book and returns the declared Output row carrying the supplied title and author.
Suite: scoped

from persistence.testing import db_session

title = "ac-create-title" author = "ac-create-author" with db_session() as db: row = db.books.create(title=title, author=author) assert row.id is not None assert row.title == title assert row.author == author === END AC books-create ===

=== AC books-get ===
Intent: books.get reads back a created book by id with the stored title and author.
Suite: scoped

from persistence.testing import db_session

title = "ac-get-title" author = "ac-get-author" with db_session() as db: created = db.books.create(title=title, author=author) fetched = db.books.get(id=created.id) assert fetched.id == created.id assert fetched.title == title assert fetched.author == author === END AC books-get ===

=== AC books-list ===
Intent: books.list returns books in the order they were added.
Suite: scoped

from persistence.testing import db_session

titles = ["ac-list-first", "ac-list-second", "ac-list-third"] with db_session() as db: created_ids = [db.books.create(title=t, author="ac-list-author").id for t in titles] listed_ids = [row.id for row in db.books.list()] mine = [i for i in listed_ids if i in created_ids] assert mine == created_ids === END AC books-list ===

=== AC books-delete ===
Intent: books.delete removes a book so it no longer appears in the next list read, and leaves other books in place.
Suite: scoped

from persistence.testing import db_session

with db_session() as db: keep = db.books.create(title="ac-delete-keep", author="ac-delete-author") gone = db.books.create(title="ac-delete-gone", author="ac-delete-author") db.books.delete(id=gone.id) listed_ids = [row.id for row in db.books.list()] assert gone.id not in listed_ids assert keep.id in listed_ids === END AC books-delete ===

User Acceptance

Guardrails