Database (Room)

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

Database file

PropertyValue
ClassScanlyDatabase
Pathdatabases/scanly.db (+ -wal, -shm) under app internal storage
Schema version5
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

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)

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.

Repository mapping

RepositoryDAOs used
DefaultDocumentRepositoryDocumentDao
DefaultPageRepositoryScanPageDao, DocumentDao
DefaultGroupRepositoryDocumentGroupDao, DocumentDao
DefaultDocumentExportRepositoryDocumentDao, ScanPageDao, DocumentGroupDao
DefaultAppDataRepositoryScanlyDatabase.clearAllTables()

Upgrade notes

  • Upgrading from v1.0.0: Room migrates automatically from schema 1 or 2 to 3.
  • Existing documents remain; they appear ungrouped until moved into a collection.
  • Upgrading to schema 5 (filter overhaul): MIGRATION_4_5 adds filterIntensity and remaps legacy presets.
  • No manual migration steps required.

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

View source on GitHub · Markdown