The data will be stored in supabase.
There will be 3 tables:
animations: contains one record per animationcommands: contains a log of commands that were executed to produce the animationversions: contains the version history of each animation
There will be 3 stored procs OR lambda functions:
execute: executes a command, and store the command data in thecommandstable and a snapshot in theversionstable.undo: undoes a command. updates theanimationstable, and stores a snapshot in theversionstable.redo: redoes a command. updates theanimationstable, and stores a snapshot in theversionstable.
Animations table
id: primary keyuser_id: referencesauth.usersname: the name of the animationpointer: the index of the last commanddata:jsonbinserted_atupdated_at
Commands table
This table is insert-only
id: primary keyanimation_id: referencesanimationsuser_id: referencesauth.usersindex: a number that represents the count of changestype: the type of commandargs: the argumens for the command injsonbformatprevious: any previous state that would needed to undo the commandinserted_at
Versions table
This table is insert-only
id: primary keyanimation_id: referencesanimationsuser_id: referencesauth.usersdata: a snapshot injsonbformatinserted_at
Code
drop table if exists commands;
drop table if exists versions;
drop table if exists animations;
create table animations (
id serial primary key,
user_id uuid references auth.users not null default auth.uid(),
name varchar not null,
pointer bigint not null default 0,
data jsonb default '{}'::jsonb,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null,
updated_at timestamp with time zone default timezone('utc'::text, now()) not null
);
create table commands (
id serial primary key,
user_id uuid references auth.users not null default auth.uid(),
animation_id bigint references animations not null,
index bigint not null,
type varchar not null,
args jsonb default '{}'::jsonb,
previous jsonb default '{}'::jsonb,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);
create table versions (
id serial primary key,
user_id uuid references auth.users not null default auth.uid(),
animation_id bigint references animations not null,
data jsonb default '{}'::jsonb,
inserted_at timestamp with time zone default timezone('utc'::text, now()) not null
);