mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 23:27:40 +01:00
- Replace console.error with structured logging using logger utility - Extract duplicate error handling into centralized utilities - Add constants for magic numbers and timeouts - Improve type safety by eliminating any types and adding proper interfaces - Standardize error response format across all wallet API endpoints - Fix timeout cleanup issues and memory leaks - Add comprehensive error handling for wallet operations
3.3 KiB
3.3 KiB
Database Migrations
created_date: 2024-03-24
last_modified_date: 2025-11-27
last_modified_summary: Documented profile contact_email field and schema extension pattern.
This directory contains SQL migration files that define the database schema and its evolution over time. Each migration file represents a specific change to the database structure.
File Structure
20240324000000_combined_setup.sql: The main migration file that sets up the initial database schema, including:- Enabling UUID extension
- Creating tables (profiles, funding_pages, transactions)
- Setting up Row Level Security (RLS) policies
- Creating triggers and functions
Migration Process
- Each migration file is named with a timestamp prefix (YYYYMMDDHHMMSS) to ensure they are applied in the correct order.
- Migrations are applied using the Supabase CLI or through direct SQL execution.
- Once a migration is applied, it should not be modified to maintain database consistency.
Current Schema
The schema has evolved beyond the original three-table MVP, but the core entities remain:
-
profiles
- Stores user profile information
- Links to
auth.usersviaid - Contains optional fields like
username,name,website,location_*, transparency fields, and contact details - Public contact email: the
contact_emailcolumn (added in20251124060022_add_contact_email.sql) is the public-facing email shown in the profile “Contact” section. It is separate from the private auth email.
-
projects
- Stores crowdfunding project information
- Links to profiles via
user_id - Tracks project status, goals, current funding and uses a
metadata JSONBcolumn for flexible, project-specific data
-
transactions
- Records donations and payments
- Links to projects and users
- Tracks transaction status and amounts
Extending the profile schema safely
To add new pieces of profile data (for example, new fields in the “Info / Contact” section), follow this pattern:
- Create a migration that adds a nullable column to
public.profiles(e.g.ALTER TABLE public.profiles ADD COLUMN IF NOT EXISTS contact_email TEXT;). - Update TypeScript types in
src/types/database.ts,src/types/profile.ts, and any related social/contact types. - Update validation and normalization in
src/lib/validation.ts(add the field toprofileSchemaand, if needed, tonormalizeProfileData). - Wire UI components (e.g.
ModernProfileEditor,ProfileInfoTab,ProfileOverviewTab) to read/write the new field. - Document the new field briefly in this guide (what it is used for, and whether it is public or private).
Security
- Row Level Security (RLS) is enabled on all tables
- Policies are defined to control access based on user authentication
- Users can only access and modify their own data
Usage
To apply migrations:
# Using Supabase CLI
npx supabase db push
# Or run the migration script directly
npx tsx src/scripts/apply-migrations.ts
Best Practices
- Always create new migration files for schema changes
- Never modify existing migration files
- Test migrations in a development environment before applying to production
- Keep migrations atomic and focused on a single change
- Document any complex changes in the migration file comments