Skip to content

Instantly share code, notes, and snippets.

@yifanzz
yifanzz / rules.md
Created March 27, 2025 20:59
YouTube Episode Supabase

Database

  • Use supabase for database queries and schema
  • Before performing any database related tasks, make sure to read the database.types.ts first for existing database schema
  • Always use migrations to update the database schema, create them using the command npx supabase migration new <migration-name>
  • Afer creating a migration file, run npx supabase migration up to apply the migration and run npx supabase gen types typescript --local > src/types/database.types.ts to generate the type file
  • When creating a new table, it must have columns for created_at and updated_at and the values should be set automatically via triggers using public.handle_created_at() and public.handle_updated_at()
  • Always enable Row Level Security (RLS) on newly create tables via ALTER TABLE <table_name> ENABLE ROW LEVEL SECURITY; in migration files and add reasonable policies
  • Always use await createServerClient() in the @/utils/supabase/server to create supabase client in server components and `createBrow