MyKid

Backend: Supabase schema and API

Overview

Journal entries (date, text, and references to Immich assets) are stored in Supabase. Media files stay in the user’s Immich; we only store asset IDs.

Applying the schema

В Supabase Dashboard → SQL Editor вставьте и выполните содержимое docs/full_schema.sql. Схема создаётся за один запуск.

Table: children

Column Type Description
id uuid Primary key
user_id uuid References auth.users(id)
name text Child’s name
date_of_birth date Optional
immich_album_id uuid Optional; Immich album for this child (created by app)
created_at timestamptz  
updated_at timestamptz  

RLS: users can manage only their own rows. See migration 20250208100000_add_children_and_child_id.sql.

Table: journal_entries

Column Type Description
id uuid Primary key, default gen_random_uuid()
user_id uuid References auth.users(id)
date date Day of the entry (for grouping)
text text Free-form description
assets jsonb Array of { "immichAssetId": "uuid", "caption": "optional" }
child_id uuid Optional; references children(id)
location text Optional; place (e.g. from photo EXIF)
created_at timestamptz Set on insert
updated_at timestamptz Set on insert/update, used for sync conflict resolution

RLS (Row Level Security)

Indexes

API (Supabase client)

The app uses the Supabase Flutter client; no custom HTTP endpoints are required. All access goes through PostgREST with JWT from Supabase Auth.

Conflict resolution: when syncing, compare updated_at (last write wins) or merge strategy as needed.

Auth

Use Supabase Auth (e.g. email/password or OAuth). After sign-in, Supabase.instance.client.auth.currentUser?.id is the user_id for all journal_entries operations.

Households and family Immich (Vault)

To allow family members to share one Immich configuration, the app uses households and Supabase Vault for storing the API key encrypted.

Tables

RPCs (SECURITY DEFINER, use Vault)

Migrations: 20250208300000_households_and_members.sql, 20250208300001_household_settings_immich_vault.sql. Requires Supabase Vault extension (enabled by default on Supabase Cloud).