Since we're now using **@supabase/stripe-sync-engine**, we need to remove the custom webhook handler functions that were created by the old `sql/36_stripe_webhooks.sql` file.
## ✅ What's Been Done
### Files Deleted
- ✅ `api/src/stripe-webhook.ts` - Custom webhook handler (replaced by library)
- ✅ `sql/35_stripe_wrappers.sql` - Uses `stripe` schema, updated function references
## 🗑️ Cleanup Database Functions
Run this SQL to remove the old custom functions:
```sql
\i sql/cleanup_old_stripe_functions.sql
```
Or run manually:
```sql
-- Drop old custom webhook handler functions
drop function if exists public.handle_stripe_customer_created(text, text, uuid);
drop function if exists public.handle_stripe_customer_updated(text, text);
drop function if exists public.handle_stripe_customer_deleted(text);
drop function if exists public.handle_stripe_product_upsert(text, text, text, boolean, text, jsonb);
drop function if exists public.handle_stripe_product_deleted(text);
drop function if exists public.handle_stripe_price_upsert(text, text, boolean, text, bigint, text, integer, integer, jsonb);
drop function if exists public.handle_stripe_price_deleted(text);
drop function if exists public.handle_stripe_subscription_upsert(text, text, text, text, integer, boolean, timestamp with time zone, timestamp with time zone, timestamp with time zone, timestamp with time zone, timestamp with time zone);
drop function if exists public.handle_stripe_subscription_deleted(text);
```
## ✅ Verify Cleanup
Run this to check if old functions are gone:
```sql
SELECT routine_name
FROM information_schema.routines
WHERE routine_schema = 'public'
AND routine_name LIKE 'handle_stripe_%';
```
Should return **0 rows**.
## ✅ Verify Kept Functions
These functions are still needed and should exist:
```sql
SELECT
routine_schema,
routine_name
FROM information_schema.routines
WHERE routine_schema IN ('public', 'stripe')
AND routine_name IN (
'is_paying_user',
'get_user_subscription_status',
'get_user_stripe_customer_id',
'sync_subscription_user_id',
'update_profile_subscription_status',
'update_updated_at_column'
)
ORDER BY routine_name;
```
Should return **6 rows** (all the functions we still use).
## 📋 Migration Order
For a fresh setup:
1.**Run stripe-sync-engine migrations**
```typescript
import { runMigrations } from '@supabase/stripe-sync-engine';