Skip to content

Database Schema

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

ReefTag stores image references, footage dates, geographical locations, species, identified individuals and locations of animals awaiting identification in a local SQLite database.

Entity relationship diagram

ReefTag database entity relationship diagram

The model contains seven principal entities:

Table Name Description
LOCATION A named geographical location with region, country and optional coordinates
FOLDER A folder containing images, with footage date and optional geographical location
IMAGE An image with saved observations or examination status; its date comes from its folder
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
  • A LOCATION can be assigned to multiple FOLDER records; a folder can have no location
  • A FOLDER can contain many IMAGE records; its date and location is shared by all associated images
  • 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

LOCATION

Field Meaning
Id SQLite-generated integer primary key
Name Name of the location
Region Administrative region
Country Country of the location
Latitude Optional latitude in decimal degrees
Longitude Optional longitude in decimal degrees

FOLDER

Field Meaning
Id SQLite-generated integer primary key
Path Full path to the folder
Date Footage date shared by images in this folder, in YYYY-MM-DD format
LocationId Nullable foreign key referencing LOCATION.Id
  • The folder is the source of both the observation date and geographical location for its images
  • Changing either property changes the value attributed to all images in that folder

IMAGE

Field Meaning
Id SQLite-generated integer primary key
Name Image filename and extension
FurtherExamination 0 or 1, indicating whether the image has been flagged for further examination
FolderId Integer foreign key referencing FOLDER.Id and identifying its containing folder
  • An image is identified by its parent folder path, name and extension
  • Images with matching filenames in different folders have separate IMAGE records

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

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

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 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

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 animal at a recorded position in one image
  • Deleting an unknown marker removes its PENDING_IDENTIFICATION record

Coordinates and Marker Numbering

Coordinates for identifications and unknown markers 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

Relationships and Integrity

Relationship Cardinality Purpose
LOCATION → FOLDER One to many (optional on folder) One location may be associated with several folders
FOLDER → IMAGE One to many A folder supplies the date and location of its images
IMAGE → IDENTIFICATION One to many A image may contain several annotated animals
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 animals 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