agentleFS
tapiotorstitapiotorsti/torsti-tapiola-website/.agents/skills/database-change/SKILL.md

database-change

Skill0 starsChanged 3 days agoMITView on GitHub

Add or change a Supabase/Postgres table, column, constraint or RLS policy for this project, and wire it through types, server functions, query options and the admin UI. Use for any schema or data-access change.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Any other agent: write the migration SQL and the app code, but do not try to connect to the database or invent a connection string.

    line 15
  2. Very specific:

    Create drizzle/migrations/NNNN_<short_description>.sql, where NNNN is the next number.

    line 31
  3. Very specific:

    Every table gets RLS, REVOKE ALL … FROM PUBLIC, anon, authenticated followed by explicit grants, and the "Admins manage" policy.

    line 60
  4. Very specific:

    Add "Public read" only for data the public site shows.

    line 62
  5. Very specific:

    Never grant anon anything beyond SELECT.

    line 67
  6. Very specific:

    Add or extend the app-level interface in src/data/types.ts.

    line 75
  7. Very specific:

    Use publicClient() and select an explicit column list.

    line 80
  8. Very specific:

    If the admin table needs raw rows, use a sub-key such as ["things", "rows"] so that invalidating ["things"] refreshes both.

    line 85
  9. Very specific:

    Run the portfolio-security-check skill on the migration, then verify-changes.

    line 95

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Database change

The database is Supabase, managed through Lovable Cloud. Schema history is the numbered SQL files in drizzle/migrations/. Applied migrations are never edited.

Who applies migrations

  • Inside Lovable: Lovable Cloud writes and applies the migration and regenerates src/integrations/supabase/types.ts and drizzle/migrations/meta/*.
  • Any other agent: write the migration SQL and the app code, but do not try to connect to the database or invent a connection string. In your report, say that the owner must apply the migration in Lovable, or in the Supabase SQL editor for a fork, before the code works.
  • Don't add entries to drizzle/migrations/meta/_journal.json yourself. A migration that is listed in the journal but was not applied by Lovable's migrator breaks it: with 0008_chat_rate_limit Lovable had to comment the file out and re-apply the same SQL as 0009. Add only the .sql file and ask the owner to have Lovable apply it ("Apply the database migration drizzle/migrations/NNNN_….sql"). Lovable then registers it, sometimes as a new file with the same SQL (e.g. 0010_apply_courses.sql). In that case, delete your unregistered original so a fresh replay does not create the table twice, and number your next migration after Lovable's.

1. Write the migration

Create drizzle/migrations/NNNN_<short_description>.sql, where NNNN is the next number. Template for a new public-read, admin-write table:

CREATE TABLE public.talks (
  id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
  title text NOT NULL,
  url text CHECK (url IS NULL OR url ~* '^https://'),
  sort_order int NOT NULL DEFAULT 0,
  created_at timestamptz NOT NULL DEFAULT now()
);

-- Supabase's default privileges grant ALL (including TRUNCATE, which ignores
-- RLS) on new tables to anon and authenticated. Revoke first, then grant.
REVOKE ALL ON public.talks FROM PUBLIC, anon, authenticated;
GRANT SELECT ON public.talks TO anon;
GRANT SELECT, INSERT, UPDATE, DELETE ON public.talks TO authenticated;
GRANT ALL ON public.talks TO service_role;

ALTER TABLE public.talks ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Public read" ON public.talks
  FOR SELECT TO anon, authenticated USING (true);
CREATE POLICY "Admins manage" ON public.talks
  FOR ALL TO authenticated
  USING (public.has_role(auth.uid(), 'admin'))
  WITH CHECK (public.has_role(auth.uid(), 'admin'));

Rules:

  • Every table gets RLS, REVOKE ALL … FROM PUBLIC, anon, authenticated followed by explicit grants, and the "Admins manage" policy. Add "Public read" only for data the public site shows.
  • New columns on existing tables need a DEFAULT or must be nullable, so existing rows still work.
  • URL columns get an https:// CHECK constraint, like projects in 0005_security_hardening.sql.
  • Never grant anon anything beyond SELECT. Never weaken has_role grants.

2. Types

  • src/integrations/supabase/types.ts is generated. Outside Lovable, leave it alone and say in your report that it must be regenerated. If the type check fails because the table is missing, note this instead of hand-editing the generated file.
  • Add or extend the app-level interface in src/data/types.ts.

3. Server function and query

In src/data/portfolio.functions.ts, copy fetchSkills:

  • Use publicClient() and select an explicit column list.
  • .order("sort_order").
  • On error, throw new Error("Could not load <thing>"). Never pass the raw error on.

In src/data/index.ts, add export const thingsQuery = queryOptions({ queryKey: ["things"], queryFn: ... }). If the admin table needs raw rows, use a sub-key such as ["things", "rows"] so that invalidating ["things"] refreshes both.

4. Admin UI (if editable)

Extend the Table union in src/components/admin/useAdminCrud.ts, then build src/routes/admin.<things>.tsx by following admin.skills.tsx.

5. Verify

Run the portfolio-security-check skill on the migration, then verify-changes.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.