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 thecommands
table and a snapshot in theversions
table.undo
: undoes a command. updates theanimations
table, and stores a snapshot in theversions
table.redo
: redoes a command. updates theanimations
table, and stores a snapshot in theversions
table.
Animations table
id
: primary keyuser_id
: referencesauth.users
name
: the name of the animationpointer
: the index of the last commanddata
:jsonb
inserted_at
updated_at
Commands table
This table is insert-only
id
: primary keyanimation_id
: referencesanimations
user_id
: referencesauth.users
index
: a number that represents the count of changestype
: the type of commandargs
: the argumens for the command injsonb
formatprevious
: any previous state that would needed to undo the commandinserted_at
Versions table
This table is insert-only
id
: primary keyanimation_id
: referencesanimations
user_id
: referencesauth.users
data
: a snapshot injsonb
formatinserted_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
);