Created
March 27, 2025 20:59
-
-
Save yifanzz/78f9116ec381bdee9e079f214ac4ac75 to your computer and use it in GitHub Desktop.
Revisions
-
yifanzz created this gist
Mar 27, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ # 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 `createBrowserClient()` in the `@/utils/supabase/client` to create supabase client in client components - Always maintain backwards compatibility when generating migrations This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ supabase start supabase migration create <migration_name> supabase migration up supabase db diff -f <migration_name> supabase db reset supabase db dump --data-only --local -f seed.sql supabase db push