Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.
feat(db): add mcp_access_tokens for personal access tokens
spacesdrive5162bdba44e6
diff --git a/supabase/migrations/20261104212657_create_mcp_access_tokens.sql b/supabase/migrations/20261104212657_create_mcp_access_tokens.sqlnew file mode 100644index 0000000..0538053--- /dev/null+++ b/supabase/migrations/20261104212657_create_mcp_access_tokens.sql@@ -0,0 +1,21 @@+-- creates mcp_access_tokens, which holds the hashes of the personal access tokens Claude clients sign in with+create table public.mcp_access_tokens (+ id text primary key,+ user_id uuid not null references auth.users (id) on delete cascade,+ label text not null,+ -- SHA-256 of the token; the token itself is shown once and never stored+ token_hash text not null,+ -- the last four characters, so a person can tell their tokens apart+ token_hint text not null,+ permission text not null,+ last_used_at timestamptz,+ expires_at timestamptz,+ revoked_at timestamptz,+ created_at timestamptz not null default now(),+ updated_at timestamptz not null default now(),+ constraint mcp_access_tokens_token_hash_key unique (token_hash),+ constraint mcp_access_tokens_permission_check check (permission in ('read', 'write')),+ constraint mcp_access_tokens_label_check check (char_length(label) between 1 and 80),+ constraint mcp_access_tokens_token_hash_check check (token_hash ~ '^[0-9a-f]{64}$'),+ constraint mcp_access_tokens_token_hint_check check (char_length(token_hint) = 4)+);diff --git a/supabase/migrations/20261104212702_revoke_browser_access_mcp_access_tokens.sql b/supabase/migrations/20261104212702_revoke_browser_access_mcp_access_tokens.sqlnew file mode 100644index 0000000..74a8cfb--- /dev/null+++ b/supabase/migrations/20261104212702_revoke_browser_access_mcp_access_tokens.sql@@ -0,0 +1,3 @@+-- turns on row level security and removes browser access to mcp_access_tokens+alter table public.mcp_access_tokens enable row level security;+revoke all on table public.mcp_access_tokens from anon, authenticated;diff --git a/supabase/migrations/20261104212709_add_mcp_access_tokens_updated_at_trigger.sql b/supabase/migrations/20261104212709_add_mcp_access_tokens_updated_at_trigger.sqlnew file mode 100644index 0000000..c336547--- /dev/null+++ b/supabase/migrations/20261104212709_add_mcp_access_tokens_updated_at_trigger.sql@@ -0,0 +1,3 @@+-- adds the trigger that keeps updated_at current on mcp_access_tokens+create trigger mcp_access_tokens_set_updated_at before update on public.mcp_access_tokens+ for each row execute function public.set_updated_at();diff --git a/supabase/migrations/20261104212713_index_mcp_access_tokens_user_created.sql b/supabase/migrations/20261104212713_index_mcp_access_tokens_user_created.sqlnew file mode 100644index 0000000..87f6bcb--- /dev/null+++ b/supabase/migrations/20261104212713_index_mcp_access_tokens_user_created.sql@@ -0,0 +1,2 @@+-- adds an index that lists a person's access tokens newest first+create index mcp_access_tokens_user_created_idx on public.mcp_access_tokens (user_id, created_at desc);diff --git a/supabase/rollbacks/20261104212657_create_mcp_access_tokens.sql b/supabase/rollbacks/20261104212657_create_mcp_access_tokens.sqlnew file mode 100644index 0000000..4e5078e--- /dev/null+++ b/supabase/rollbacks/20261104212657_create_mcp_access_tokens.sql@@ -0,0 +1,2 @@+-- removes mcp_access_tokens, which signs out every Claude client that used a personal access token+drop table if exists public.mcp_access_tokens;diff --git a/supabase/rollbacks/20261104212702_revoke_browser_access_mcp_access_tokens.sql b/supabase/rollbacks/20261104212702_revoke_browser_access_mcp_access_tokens.sqlnew file mode 100644index 0000000..87164b3--- /dev/null+++ b/supabase/rollbacks/20261104212702_revoke_browser_access_mcp_access_tokens.sql@@ -0,0 +1,2 @@+-- turns row level security off on mcp_access_tokens; it had no browser grants to give back+alter table public.mcp_access_tokens disable row level security;diff --git a/supabase/rollbacks/20261104212709_add_mcp_access_tokens_updated_at_trigger.sql b/supabase/rollbacks/20261104212709_add_mcp_access_tokens_updated_at_trigger.sqlnew file mode 100644index 0000000..2682f1b--- /dev/null+++ b/supabase/rollbacks/20261104212709_add_mcp_access_tokens_updated_at_trigger.sql@@ -0,0 +1,2 @@+-- removes the trigger that keeps updated_at current on mcp_access_tokens+drop trigger if exists mcp_access_tokens_set_updated_at on public.mcp_access_tokens;diff --git a/supabase/rollbacks/20261104212713_index_mcp_access_tokens_user_created.sql b/supabase/rollbacks/20261104212713_index_mcp_access_tokens_user_created.sqlnew file mode 100644index 0000000..2e1f0fa--- /dev/null+++ b/supabase/rollbacks/20261104212713_index_mcp_access_tokens_user_created.sql@@ -0,0 +1,2 @@+-- removes the index that lists a person's access tokens+drop index if exists public.mcp_access_tokens_user_created_idx;diff --git a/supabase/schemas/public/tables/mcp_access_tokens.sql b/supabase/schemas/public/tables/mcp_access_tokens.sqlnew file mode 100644index 0000000..26412df--- /dev/null+++ b/supabase/schemas/public/tables/mcp_access_tokens.sql@@ -0,0 +1,38 @@+CREATE TABLE "public"."mcp_access_tokens" (+ "id" text NOT NULL,+ "user_id" uuid NOT NULL,+ "label" text NOT NULL,+ "token_hash" text NOT NULL,+ "token_hint" text NOT NULL,+ "permission" text NOT NULL,+ "last_used_at" timestamp with time zone,+ "expires_at" timestamp with time zone,+ "revoked_at" timestamp with time zone,+ "created_at" timestamp with time zone NOT NULL DEFAULT now(),+ "updated_at" timestamp with time zone NOT NULL DEFAULT now(),+ CONSTRAINT "mcp_access_tokens_label_check" CHECK (((char_length(label) >= 1) AND (char_length(label) <= 80))),+ CONSTRAINT "mcp_access_tokens_permission_check" CHECK ((permission = ANY (ARRAY['read'::text, 'write'::text]))),+ CONSTRAINT "mcp_access_tokens_pkey" PRIMARY KEY (id),+ CONSTRAINT "mcp_access_tokens_token_hash_check" CHECK ((token_hash ~ '^[0-9a-f]{64}$'::text)),+ CONSTRAINT "mcp_access_tokens_token_hash_key" UNIQUE (token_hash),+ CONSTRAINT "mcp_access_tokens_token_hint_check" CHECK ((char_length(token_hint) = 4)),+ CONSTRAINT "mcp_access_tokens_user_id_fkey" FOREIGN KEY (user_id) REFERENCES auth.users(id) ON DELETE CASCADE+);++ALTER TABLE "public"."mcp_access_tokens"+ ENABLE ROW LEVEL SECURITY;++CREATE INDEX mcp_access_tokens_user_created_idx ON public.mcp_access_tokens USING btree (user_id, created_at DESC);++CREATE TRIGGER mcp_access_tokens_set_updated_at+ BEFORE UPDATE ON public.mcp_access_tokens+ FOR EACH ROW+ EXECUTE FUNCTION public.set_updated_at();++GRANT DELETE, INSERT, MAINTAIN, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON TABLE "public"."mcp_access_tokens" TO "service_role";++REVOKE ALL ON TABLE "public"."mcp_access_tokens" FROM "postgres";++GRANT DELETE, INSERT, MAINTAIN, REFERENCES, SELECT, TRIGGER, TRUNCATE, UPDATE ON TABLE "public"."mcp_access_tokens" TO "postgres";++REVOKE ALL ON TABLE "public"."mcp_access_tokens" FROM "anon", "authenticated";