Skip to content

Database Schema

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

ReefTag stores image references, species, identified species and locations of animals awaiting identification 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 five principal entities:

Table Name Description
IMAGE a image with saved observations or examination status, including its footage date
SPECIES a reusable species-catalogue entry, with common and scientific names and an optional category
CATEGORY a named category that may be assigned to multiple species
IDENTIFICATION one identified individual at a recorded position within one image
PENDING_IDENTIFICATION one animal that has been marked in a image but not yet identified
  • An IMAGE can have many IDENTIFICATION and PENDING_IDENTIFICATION records
  • A SPECIES can be referred to by many IDENTIFICATION records
  • A CATEGORY can be associated with many SPECIES records, though the association is optional for each species
  • Each IDENTIFICATION references exactly one IMAGE and one SPECIES
  • Each PENDING_IDENTIFICATION references one IMAGE and has no species assigned

IMAGE

Field Meaning
id SQLite-generated integer primary key
Name Resolved absolute image path, including filename and extension; the image's identity
Date Original footage date, recorded as a date value (ISO YYYY-MM-DD was specified in the brief)
FurtherExamination 0 or 1, indicating whether the image has been flagged for further examination
  • Images with matching filenames in different folders have separate IMAGE records
  • Adding a pending identification sets FurtherExamination to 1
  • An image with one or more pending identifications cannot have this flag switched off through the UI
  • Once no pending identifications remain, the flag can again be changed manually
  • Clearing the last pending identification restores manual control of the flag

SPECIES

Field Meaning
id SQLite-generated integer primary key
CommonName Common name supplied by the observer
ScientificName Scientific name supplied by the observer
CategoryId Nullable integer foreign key referencing CATEGORY.Id
  • 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
  • A species may have no category
  • Categories are managed separately and reused across the species catalogue

CATEGORY

Field Meaning
Id SQLite-generated integer primary key
Name Category name; cannot be empty
  • Category names must be unique
  • A category can only be deleted when no species references it
  • Changing a category name leaves the associated species in that category

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 image
Y Vertical pixel coordinate in the original image
  • An identification represents one observed individual in one image
  • Several IDENTIFICATION records can point to the same SPECIES record, even in the same IMAGE

PENDING_IDENTIFICATION

This table was introduced in v1.2.0 to store fish locations awaiting species identification.

Field Meaning
id SQLite-generated integer primary key
ImageId Integer foreign key referencing IMAGE.id
X Horizontal pixel coordinate in the original image
Y Vertical pixel coordinate in the original image
  • A pending identification represents a single unknown fish at a recorded position in one image
  • It does not reference SPECIES and does not have a marker number
  • Deleting an unknown marker removes its PENDING_IDENTIFICATION record
  • Identifying that fish removes the pending record and creates an IDENTIFICATION record using the normal identified-fish workflow

Coordinates and Marker Numbering

Coordinates are stored against the original image, 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

Both identified and pending markers use these original-image coordinates. Only identified markers have per-image numbers; pending markers are shown as unnumbered red question marks.

Relationships and Integrity

The intended relationships are:

Relationship Cardinality Purpose
IMAGE → IDENTIFICATION One to many A image may contain several annotated fish
SPECIES → IDENTIFICATION One to many One species may appear in many observations
CATEGORY → SPECIES One to many (optional on species) A category can classify many species; a species can have no category
IMAGE → PENDING_IDENTIFICATION One to many A image may contain several fish awaiting identification

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 so users should not need to run SQL scripts to initialise a new installation or apply schema changes.

Clone this wiki locally