# Deleting a Stray Guide in Production

If a guide can't be deleted from the UI (e.g. it still appears on the share page or in the DB but not in the app), use one of these approaches.

## Option 1: Supabase SQL Editor (recommended)

1. Open your **Supabase project** → **SQL Editor**.
2. **Find the guide** (by name or ID):

```sql
-- List guides (replace with part of the name or the known id)
SELECT id, name, user_id, project_id, is_primary, show_on_share, created_at
FROM guides
WHERE name ILIKE '%your guide name%'   -- or: WHERE id = 'uuid-here'
ORDER BY created_at DESC;
```

3. **Delete it** using the guide `id` and the **correct** `user_id` (the row’s `user_id` from the query):

```sql
-- Replace GUIDE_ID and USER_ID with values from the SELECT above.
-- You must use the user_id that owns the row (RLS only allows that).
DELETE FROM guides
WHERE id = 'GUIDE_ID_HERE'
  AND user_id = 'USER_ID_HERE';
```

4. If the guide has a **wrong or NULL** `user_id` and you have **DB superuser / service role** access, you can delete by id only (bypasses RLS when run as postgres/service role):

```sql
-- Only use if the guide’s user_id is wrong or null and you have elevated access.
DELETE FROM guides WHERE id = 'GUIDE_ID_HERE';
```

## Option 2: Browser console (when signed in as the guide’s owner)

1. Open the **Blueprint app**, **sign in**, and open **DevTools → Console**.
2. List your guides and get the guide id:

```javascript
(function() {
  var client = window.Blueprint?.supabaseClient || window.supabaseClient;
  if (!client) { console.error('No Supabase client'); return; }
  client.auth.getUser().then(function(r) {
    var uid = r.data?.user?.id;
    if (!uid) { console.error('Not signed in'); return; }
    client.from('guides').select('id, name, project_id').eq('user_id', uid).then(function(res) {
      console.log('Your guides:', res.data);
      if (res.data?.length) console.log('To delete one: client.from("guides").delete().eq("id", "' + res.data[0].id + '").eq("user_id", "' + uid + '")');
    });
  });
})();
```

3. Delete the stray guide (use the `id` and your user id from the output):

```javascript
client.from('guides').delete().eq('id', 'GUIDE_UUID_HERE').eq('user_id', 'YOUR_USER_UUID_HERE');
```

## Option 3: Existing maintenance script

From the repo you can run the console script that lists and deletes by criteria:

- **scripts/maintenance/delete-guide-console.js** – paste into the browser console on the app page while signed in. It lists your guides and can delete those that are not primary and not shown on share; you can change the filter to target one guide by name or id.

## Why the UI might not delete it

- **RLS**: Deletes only succeed when `auth.uid()` matches the row’s `user_id`. If the guide has a different or null `user_id`, the app (and Option 2) cannot delete it; use Option 1 with the correct `user_id` or with elevated DB access.
- **Not in sync**: The guide might exist only in the DB and not in the in-memory/local list the UI uses, so the Delete button never targets it. Deleting in SQL or via the console (Option 1 or 2) removes it in the DB; the next load or share fetch will no longer see it.
