Database (Room)

Scanly persists document metadata in a Room database at schema version 12.

Database file

PropertyValue
ClassScanlyDatabase
Pathdatabases/scanly.db (+ -wal, -shm) under app internal storage
Schema version12
exportSchemafalse

Location: app/src/main/java/in/c1ph3rj/scanly/data/local/db/ScanlyDatabase.kt

Entities

documents (DocumentEntity)

ColumnTypeNotes
idTEXT PKUUID
titleTEXTUser-visible name
pageCountINTEGERDenormalized count
coverThumbnailPathTEXT?Path to cover thumb
preferredFilterPresetTEXT?Default filter for new pages
rootDirectoryPathTEXTApp-private document directory
createdAtMillisINTEGERCreation timestamp
updatedAtMillisINTEGERLast modification
groupIdTEXT? FK→ document_groups.id, ON DELETE SET NULL

Indexes: updatedAtMillis, groupId

scan_pages (ScanPageEntity)

ColumnTypeNotes
idTEXT PKUUID
documentIdTEXT FK→ documents.id, CASCADE
pageIndexINTEGEROrder within document (0-based)
rawImagePathTEXTImmutable capture
processedImagePathTEXT?Derived corrected image
thumbnailPathTEXT?List thumbnail
cropTopLeftX/Y … cropBottomRightX/YREALNormalized crop quad (8 values)
rotationDegreesINTEGERUser rotation
filterPresetTEXTPageFilterPreset.storageValue (legacy values are remapped by MIGRATION_4_5)
filterBrightnessREALPost-filter brightness tweak (-1..1, default 0)
filterContrastREALPost-filter contrast tweak (-1..1, default 0)
filterSaturationREALPost-filter saturation tweak (-1..1, default 0)
filterSharpnessREALPost-filter sharpness (0..1, default 0)
filterIntensityREALPreset strength (0..1.5, default 1; 1 is the tuned look, 0 is lighting correction only). Added in schema 5
processingStateTEXTCAPTURED, PROCESSED, or NEEDS_REVIEW
createdAtMillisINTEGERCreation timestamp

Unique constraint: (documentId, pageIndex)

document_groups (DocumentGroupEntity)

ColumnTypeNotes
idTEXT PKUUID
titleTEXTGroup name
createdAtMillisINTEGERCreation timestamp
updatedAtMillisINTEGERLast modification

Index: updatedAtMillis

page_texts (PageTextEntity)

One row per scanned page, with recognized text, an optional user correction, the text used for search, normalized text-layout blocks, source image dimensions, and recognition timestamps. pageId is unique and references scan_pages with cascade delete; documentId is indexed.

page_texts_fts is an FTS4 external-content index over searchText. Room-managed triggers keep it synchronized. Rows are replaced with delete + insert so the triggers run. page_texts_terms is an FTS4 vocabulary table created idempotently when the database opens.

Schema 11 adds engine, requestedEngine and fallbackReason: which OCR engine read the page, which engine was selected, and why ML Kit stepped in. See ../architecture/ocr-engines.md.

signatures (SignatureEntity)

Saved signatures and initials with source type, app-private image path, dimensions, and creation/update timestamps. Indexed by updatedAtMillis.

page_markups (PageMarkupEntity)

One row per signed Scanly page, containing serialized marks, the clean base-image path, and update time. pageId is the primary key and cascades with its scan_pages row. The visible processed image contains the composite; the base image lets the user edit or remove marks later.

DAOs

DAOKey operations
DocumentDaoObserve all/recent/ungrouped/by-group; CRUD; update snapshots
ScanPageDaoObserve by document; CRUD; reorder (update indices)
DocumentGroupDaoObserve all/recent; CRUD; join stats (doc count, page count, cover)
PageTextDaoRead/write per-page OCR text, FTS search, and index progress
SignatureDaoObserve, save, and delete saved signatures
PageMarkupDaoRead/write per-page markups

Migrations

MIGRATION_1_2

Adds preferredFilterPreset TEXT column to documents.

MIGRATION_2_3

  1. Creates document_groups table.
  2. Rebuilds documents with groupId FK (SQLite table-recreation pattern).
  3. Copies existing rows with groupId = NULL (all pre-1.0.4 documents stay ungrouped).
  4. Recreates indexes.

MIGRATION_3_4

Adds per-page filter customization columns on scan_pages (all REAL NOT NULL DEFAULT 0):

  • filterBrightness
  • filterContrast
  • filterSaturation
  • filterSharpness

Registered in DatabaseModule with MIGRATION_1_2 and MIGRATION_2_3.

MIGRATION_4_5

  1. Adds filterIntensity REAL NOT NULL DEFAULT 1 to scan_pages. Existing pages get the default intensity, which is the tuned look.
  2. Remaps presets removed in the filter overhaul. For each legacy value, scan_pages.filterPreset and documents.preferredFilterPreset are rewritten to the replacement:
Legacy valueReplacement
enhanced_colornatural_color
shadow_reductionmagic_color
cleangrayscale
soft_black_and_whitefaded
receiptfaded

The mapping comes from PageFilterPreset.legacyStorageMigrations, so the migration and PageFilterPreset.fromStorage stay in sync. Registered in DatabaseModule after MIGRATION_3_4.

MIGRATION_5_6

Creates page_texts, its FTS4 external-content table, the page/document indexes, and synchronization triggers. Existing pages have no text rows yet; the background indexer recognizes them after upgrade.

MIGRATION_6_7

Creates signatures and page_markups, including the signature timestamp index and the markup-to-page foreign key. Existing document pages and their images are unchanged.

MIGRATION_7_8

Adds documents.deletedAtMillis for Recently deleted.

MIGRATION_8_9

Adds document_groups.deletedAtMillis, documents.deletedWithGroup, and scan_pages.deletedAtMillis and deletedFromIndex.

MIGRATION_9_10

Adds documents.releasedFromGroupId for "Delete folder only".

MIGRATION_10_11

Adds page_texts.engine, requestedEngine and fallbackReason (nullable TEXT). Rows with non-empty text are marked ML_KIT in both engine columns, since every earlier read used ML Kit. Blank rows stay NULL.

Repository mapping

RepositoryDAOs used
DefaultDocumentRepositoryDocumentDao
DefaultPageRepositoryScanPageDao, DocumentDao
DefaultGroupRepositoryDocumentGroupDao, DocumentDao
DefaultDocumentExportRepositoryDocumentDao, ScanPageDao, DocumentGroupDao
DefaultAppDataRepositoryScanlyDatabase.clearAllTables()
DefaultPageTextRepositoryPageTextDao, ScanPageDao, DocumentDao
DefaultSignatureRepositorySignatureDao and app-private signature image files
DefaultPageMarkupRepositoryPageMarkupDao, page/document DAOs, page image files

Upgrade notes

  • Upgrading from v1.0.0: Room migrates automatically from schema 1 or 2 through schema 12.
  • Existing documents remain; they appear ungrouped until moved into a collection.
  • Upgrading from schema 5: Room runs MIGRATION_5_6 and MIGRATION_6_7; page-text indexing resumes in the background.
  • Upgrading from schema 6: MIGRATION_6_7 adds saved signatures and editable page markups.
  • Upgrading from schema 10: MIGRATION_10_11 adds the OCR provenance columns; pages are not re-read automatically.
  • Upgrading from schema 11: MIGRATION_11_12 adds derived search text and rebuilds the page-text index; existing pages are re-derived in the background without being read again.
  • No manual migration steps required.

See ../releases.md and ../../VERSION.md.

View source on GitHub · Markdown