Skip to content

Database Schema

Dave Walker edited this page Nov 3, 2026 · 7 revisions

ReefTag stores image references, species and individual fish identifications in a local SQLite database. The application uses yoyo-migrations for initial schema creation and subsequent changes. Pending migrations are automatically applied when the application starts.

Entity relationship diagram

ReefTag database entity relationship diagram

The model contains three principal entities:

  • IMAGE: a photograph for which observations are stored, including its footage date
  • SPECIES: a reusable species-catalogue entry, with common and scientific names
  • IDENTIFICATION: one identified fish at a recorded position within one photograph

An IMAGE can have many IDENTIFICATION records, and a SPECIES can be referred to by many IDENTIFICATION records. Each IDENTIFICATION references exactly one IMAGE and one SPECIES.

IMAGE

Field Meaning
id SQLite-generated integer primary ke.
Name Filename, including extension; used as the image's identity
Date Original footage date, recorded as a date value (ISO YYYY-MM-DD was specified in the brief)

Important: The applications stores only the filename. Matching filenames in different folders therefore refer to the same IMAGE record. This simplifies the model but requires unique filenames for distinct photographs that should not share observations.

SPECIES

Field Meaning
id SQLite-generated integer primary key
CommonName Common name supplied by the observer
ScientificName Scientific name supplied by the observer

The species catalogue is shared across all images. A single species can be used for any number of identifications. Names are not automatically verified against an external taxonomy.

IDENTIFICATION

Field Meaning
id SQLite-generated integer primary key
ImageId Integer foreign key referencing IMAGE.id
SpeciesId Integer foreign key referencing SPECIES.id
Number Number shown beside the fish marker; scoped to an individual image
X Horizontal pixel coordinate in the original photograph
Y Vertical pixel coordinate in the original photograph

An identification represents one observed individual in one photograph. Several IDENTIFICATION records can point to the same SPECIES record, even in the same IMAGE.

Coordinates and Marker Numbering

Coordinates are stored against the original photograph, not the size or position of the preview displayed on screen:

  • Origin: the upper-left corner, (0, 0)
  • X increases from left to right
  • Y increases from top to bottom
  • Zooming, panning and brightness adjustments do not modify the stored coordinates or source image

Relationships and Integrity

The intended relationships are:

Relationship Cardinality Purpose
IMAGE → IDENTIFICATION One to many A photograph may contain several annotated fish
SPECIES → IDENTIFICATION One to many One species may appear in many observations

Database configuration and migrations

The path to the SQLite file is supplied via the REEFTAG_DB_PATH environment variable. This should be an absolute file path, for example:

export REEFTAG_DB_PATH="$HOME/Documents/ReefTag/reeftag.db"

The application creates and migrates the schema as needed on startup using yoyo-migrations. Users should not need to run SQL scripts to initialise a new installation.

SQLite contains references and observations, not copies of the source images. Back up the database separately from the image files.

Clone this wiki locally