diff --git a/apps/mcp/src/__tests__/tools.test.ts b/apps/mcp/src/__tests__/tools.test.ts index 57ee249..60c7755 100644 --- a/apps/mcp/src/__tests__/tools.test.ts +++ b/apps/mcp/src/__tests__/tools.test.ts @@ -228,7 +228,7 @@ describe("Plant tools", () => { it("list_plants output has correct shape", async () => { const { mockClient } = createMockDb(); const { data } = await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("*") .eq("user_id", userId) .is("deleted_at", null) @@ -288,7 +288,7 @@ describe("Plant tools", () => { it("list_plants queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("*") .eq("user_id", userId) .is("deleted_at", null) @@ -300,7 +300,7 @@ describe("Plant tools", () => { it("get_plant queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("*") .eq("id", "plant-1") .eq("user_id", userId) @@ -332,7 +332,7 @@ describe("Plant tools", () => { // Simulate the handler logic const { data: plant, error: plantError } = await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", "plant-1") .eq("user_id", userId) @@ -363,7 +363,7 @@ describe("Plant tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: plant, error: checkError } = await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", "plant-1") .eq("user_id", userId) @@ -568,7 +568,7 @@ describe("Care tools", () => { it("list_care_schedules queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); let query = (mockClient as any) - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("user_id", userId) .eq("active", true) @@ -583,7 +583,7 @@ describe("Care tools", () => { it("list_care_logs queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); await (mockClient as any) - .from("care_logs") + .from("opensprout_care_logs") .select("*") .eq("user_id", userId) .eq("plant_id", "plant-1") @@ -597,7 +597,7 @@ describe("Care tools", () => { it("list_task_instances queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); await (mockClient as any) - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("user_id", userId) .is("deleted_at", null) @@ -625,7 +625,7 @@ describe("Care tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: plant, error: plantError } = await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", "plant-1") .eq("user_id", userId) @@ -655,7 +655,7 @@ describe("Care tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: plant, error: plantError } = await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", "plant-1") .eq("user_id", userId) @@ -685,7 +685,7 @@ describe("Care tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: task, error: taskError } = await (mockClient as any) - .from("task_instances") + .from("opensprout_task_instances") .select("id") .eq("id", "task-1") .eq("user_id", userId) @@ -715,7 +715,7 @@ describe("Care tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: task, error: taskError } = await (mockClient as any) - .from("task_instances") + .from("opensprout_task_instances") .select("id") .eq("id", "task-1") .eq("user_id", userId) @@ -843,7 +843,7 @@ describe("Journal tools", () => { it("list_journal_entries queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); await (mockClient as any) - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("user_id", userId) .eq("plant_id", "plant-1") @@ -857,7 +857,7 @@ describe("Journal tools", () => { it("get_journal_entry queries with .eq('user_id', userId)", async () => { const { mockClient, mockQuery } = createMockDb(); await (mockClient as any) - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("id", "entry-1") .eq("user_id", userId) @@ -886,7 +886,7 @@ describe("Journal tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: plant, error: plantError } = await (mockClient as any) - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", "plant-1") .eq("user_id", userId) @@ -916,7 +916,7 @@ describe("Journal tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: entry, error: checkError } = await (mockClient as any) - .from("journal_entries") + .from("opensprout_journal_entries") .select("id") .eq("id", "entry-1") .eq("user_id", userId) @@ -946,7 +946,7 @@ describe("Journal tools", () => { (mockClient as any).from.mockReturnValue(ownershipChain); const { data: entry, error: checkError } = await (mockClient as any) - .from("journal_entries") + .from("opensprout_journal_entries") .select("id") .eq("id", "entry-1") .eq("user_id", userId) diff --git a/apps/mcp/src/supabase.ts b/apps/mcp/src/supabase.ts index 2a9524a..066e953 100644 --- a/apps/mcp/src/supabase.ts +++ b/apps/mcp/src/supabase.ts @@ -71,7 +71,7 @@ export async function authenticateToken( // Look up the token hash const { data: records, error: lookupError } = await (admin - .from("mcp_tokens") as any) + .from("opensprout_mcp_tokens") as any) .select("user_id, id, revoked_at") .eq("token_hash", tokenHash); @@ -94,7 +94,7 @@ export async function authenticateToken( } // Update last_used_at - await (admin.from("mcp_tokens") as any) + await (admin.from("opensprout_mcp_tokens") as any) .update({ last_used_at: new Date().toISOString() } as any) .eq("id", record.id); diff --git a/apps/mcp/src/tools/care.ts b/apps/mcp/src/tools/care.ts index 0de5e13..20de132 100644 --- a/apps/mcp/src/tools/care.ts +++ b/apps/mcp/src/tools/care.ts @@ -29,7 +29,7 @@ export function registerCareTools( }, async ({ plantId }) => { let query = getClient() - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("user_id", userId) .eq("active", true) @@ -63,7 +63,7 @@ export function registerCareTools( }, async ({ plantId, limit }) => { const { data, error } = await getClient() - .from("care_logs") + .from("opensprout_care_logs") .select("*") .eq("user_id", userId) .eq("plant_id", plantId) @@ -95,7 +95,7 @@ export function registerCareTools( }, async ({ plantId, status }) => { let query = getClient() - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("user_id", userId) .is("deleted_at", null); @@ -137,7 +137,7 @@ export function registerCareTools( // Ownership check: verify plant belongs to this user const { data: plant, error: plantError } = await c - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -146,7 +146,7 @@ export function registerCareTools( if (plantError || !plant) throw new Error("Plant not found or access denied"); const { data: log, error: logError } = await c - .from("care_logs") + .from("opensprout_care_logs") .insert({ plant_id: plantId, user_id: userId, @@ -161,7 +161,7 @@ export function registerCareTools( if (taskInstanceId) { await c - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "done", completed_at: new Date().toISOString(), @@ -188,7 +188,7 @@ export function registerCareTools( const c = getClient() as any; const { data: tasks, error: taskError } = await c - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("id", taskId) .eq("user_id", userId) @@ -203,7 +203,7 @@ export function registerCareTools( const now = new Date().toISOString(); const { data: log, error: logError } = await c - .from("care_logs") + .from("opensprout_care_logs") .insert({ plant_id: task.plant_id, user_id: userId, @@ -217,7 +217,7 @@ export function registerCareTools( if (logError) throw new Error("Failed to create care log for task completion: " + logError.message); await c - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "done", completed_at: now, @@ -258,7 +258,7 @@ export function registerCareTools( // Verify plant ownership const { data: plant, error: plantError } = await c - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -270,7 +270,7 @@ export function registerCareTools( } const { data, error } = await c - .from("care_schedules") + .from("opensprout_care_schedules") .insert({ plant_id: plantId, user_id: userId, @@ -306,7 +306,7 @@ export function registerCareTools( // Ownership check const { data: task, error: taskError } = await c - .from("task_instances") + .from("opensprout_task_instances") .select("id") .eq("id", taskId) .eq("user_id", userId) @@ -318,7 +318,7 @@ export function registerCareTools( } const { error } = await c - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "skipped", skipped_at: new Date().toISOString(), @@ -351,8 +351,8 @@ export function registerCareTools( async ({ days }) => { const futureDate = new Date(Date.now() + days * 86400000).toISOString(); const { data, error } = await getClient() - .from("task_instances") - .select("*, plants!inner(name, location)") + .from("opensprout_task_instances") + .select("*, opensprout_plants!inner(name, location)") .eq("user_id", userId) .eq("status", "pending") .is("deleted_at", null) @@ -381,7 +381,7 @@ export function registerCareTools( // Ownership check const { data: task, error: taskError } = await c - .from("task_instances") + .from("opensprout_task_instances") .select("id") .eq("id", taskId) .eq("user_id", userId) @@ -393,7 +393,7 @@ export function registerCareTools( } const { error } = await c - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "snoozed", snoozed_until: until, diff --git a/apps/mcp/src/tools/export.ts b/apps/mcp/src/tools/export.ts index a4b5b45..0cc30f8 100644 --- a/apps/mcp/src/tools/export.ts +++ b/apps/mcp/src/tools/export.ts @@ -16,27 +16,27 @@ export function registerExportTools( const [plants, careSchedules, careLogs, taskInstances, journalEntries] = await Promise.all([ c - .from("plants") + .from("opensprout_plants") .select("*") .eq("user_id", userId) .is("deleted_at", null), c - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("user_id", userId) .is("deleted_at", null), c - .from("care_logs") + .from("opensprout_care_logs") .select("*") .eq("user_id", userId) .is("deleted_at", null), c - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("user_id", userId) .is("deleted_at", null), c - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("user_id", userId) .is("deleted_at", null), diff --git a/apps/mcp/src/tools/journal.ts b/apps/mcp/src/tools/journal.ts index 3c1a876..d586a06 100644 --- a/apps/mcp/src/tools/journal.ts +++ b/apps/mcp/src/tools/journal.ts @@ -20,7 +20,7 @@ export function registerJournalTools( }, async ({ plantId, limit }) => { const { data, error } = await getClient() - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("user_id", userId) .eq("plant_id", plantId) @@ -45,7 +45,7 @@ export function registerJournalTools( }, async ({ entryId }) => { const { data, error } = await getClient() - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("id", entryId) .eq("user_id", userId) @@ -90,7 +90,7 @@ export function registerJournalTools( // Ownership check: verify plant belongs to this user const { data: plant, error: plantError } = await c - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -99,7 +99,7 @@ export function registerJournalTools( if (plantError || !plant) throw new Error("Plant not found or access denied"); const { data, error } = await c - .from("journal_entries") + .from("opensprout_journal_entries") .insert({ plant_id: plantId, user_id: userId, @@ -145,7 +145,7 @@ export function registerJournalTools( // Ownership check const { data: entry, error: checkError } = await c - .from("journal_entries") + .from("opensprout_journal_entries") .select("id") .eq("id", entryId) .eq("user_id", userId) @@ -163,7 +163,7 @@ export function registerJournalTools( if (tags !== undefined) updates.tags = tags; const { data, error } = await c - .from("journal_entries") + .from("opensprout_journal_entries") .update(updates) .eq("id", entryId) .select() @@ -190,7 +190,7 @@ export function registerJournalTools( // Ownership check const { data: entry, error: checkError } = await c - .from("journal_entries") + .from("opensprout_journal_entries") .select("id") .eq("id", entryId) .eq("user_id", userId) @@ -202,7 +202,7 @@ export function registerJournalTools( } const { error } = await c - .from("journal_entries") + .from("opensprout_journal_entries") .update({ deleted_at: new Date().toISOString() }) .eq("id", entryId); diff --git a/apps/mcp/src/tools/knowledge.ts b/apps/mcp/src/tools/knowledge.ts index b6f1bbb..91dda75 100644 --- a/apps/mcp/src/tools/knowledge.ts +++ b/apps/mcp/src/tools/knowledge.ts @@ -18,7 +18,7 @@ export function registerKnowledgeTools( }, async ({ query, category }) => { let dbQuery = getClient() - .from("knowledge_articles") + .from("opensprout_knowledge_articles") .select("*") .or(`title.ilike.%${query}%,body.ilike.%${query}%`); @@ -47,7 +47,7 @@ export function registerKnowledgeTools( }, async ({ symptom }) => { const { data, error } = await getClient() - .from("diagnosis_entries") + .from("opensprout_diagnosis_entries") .select("*") .or(`symptom.ilike.%${symptom}%,cause.ilike.%${symptom}%`) .order("sort_order") diff --git a/apps/mcp/src/tools/plants.ts b/apps/mcp/src/tools/plants.ts index cc9df7b..022e255 100644 --- a/apps/mcp/src/tools/plants.ts +++ b/apps/mcp/src/tools/plants.ts @@ -13,7 +13,7 @@ export function registerPlantTools( {}, async () => { const { data, error } = await getClient() - .from("plants") + .from("opensprout_plants") .select("*") .eq("user_id", userId) .is("deleted_at", null) @@ -35,7 +35,7 @@ export function registerPlantTools( }, async ({ query }) => { const { data, error } = await getClient() - .from("plants") + .from("opensprout_plants") .select("*") .eq("user_id", userId) .or(`name.ilike.%${query}%,location.ilike.%${query}%,species.ilike.%${query}%`) @@ -58,7 +58,7 @@ export function registerPlantTools( }, async ({ plantId }) => { const { data, error } = await getClient() - .from("plants") + .from("opensprout_plants") .select("*") .eq("id", plantId) .eq("user_id", userId) @@ -109,7 +109,7 @@ export function registerPlantTools( // Ownership check: verify plant belongs to this user const { data: plant, error: plantError } = await getClient() - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -119,7 +119,7 @@ export function registerPlantTools( const c = getClient() as any; const { data, error } = await c - .from("plants") + .from("opensprout_plants") .update(updates) .eq("id", plantId) .is("deleted_at", null) @@ -155,7 +155,7 @@ export function registerPlantTools( async ({ name, speciesId, species, location, notes, healthStatus, nickname, acquiredOn }) => { const c = getClient() as any; const { data, error } = await c - .from("plants") + .from("opensprout_plants") .insert({ name, user_id: userId, @@ -191,7 +191,7 @@ export function registerPlantTools( // Ownership check const { data: plant, error: checkError } = await c - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -203,7 +203,7 @@ export function registerPlantTools( } const { error } = await c - .from("plants") + .from("opensprout_plants") .update({ deleted_at: new Date().toISOString() }) .eq("id", plantId); @@ -228,7 +228,7 @@ export function registerPlantTools( // Ownership check const { data: plant, error: checkError } = await c - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -240,7 +240,7 @@ export function registerPlantTools( } const { error } = await c - .from("plants") + .from("opensprout_plants") .update({ archived_at: new Date().toISOString() }) .eq("id", plantId); @@ -265,7 +265,7 @@ export function registerPlantTools( // Ownership check const { data: plant, error: checkError } = await c - .from("plants") + .from("opensprout_plants") .select("id") .eq("id", plantId) .eq("user_id", userId) @@ -277,7 +277,7 @@ export function registerPlantTools( } const { error } = await c - .from("plants") + .from("opensprout_plants") .update({ archived_at: null }) .eq("id", plantId); diff --git a/apps/mcp/src/tools/species.ts b/apps/mcp/src/tools/species.ts index e8788bd..9cc5e70 100644 --- a/apps/mcp/src/tools/species.ts +++ b/apps/mcp/src/tools/species.ts @@ -14,7 +14,7 @@ export function registerSpeciesTools( }, async ({ query }) => { const { data, error } = await getClient() - .from("plant_species") + .from("opensprout_plant_species") .select("*") .or(`common_name.ilike.%${query}%,scientific_name.ilike.%${query}%`) .limit(20); @@ -37,7 +37,7 @@ export function registerSpeciesTools( async ({ speciesId }) => { const client = getClient(); const { data: species, error: speciesError } = await client - .from("plant_species") + .from("opensprout_plant_species") .select("*") .eq("id", speciesId) .single(); @@ -50,7 +50,7 @@ export function registerSpeciesTools( } const { data: articles } = await client - .from("knowledge_articles") + .from("opensprout_knowledge_articles") .select("*") .eq("species_id", speciesId) .order("sort_order"); diff --git a/apps/mcp/src/types.ts b/apps/mcp/src/types.ts index a39b07d..85e471e 100644 --- a/apps/mcp/src/types.ts +++ b/apps/mcp/src/types.ts @@ -26,7 +26,7 @@ export type CareType = export type Database = { public: { Tables: { - plants: { + opensprout_plants: { Row: { id: string; user_id: string; @@ -74,7 +74,7 @@ export type Database = { updated_at?: string; }; }; - plant_species: { + opensprout_plant_species: { Row: { id: string; common_name: string; @@ -106,7 +106,7 @@ export type Database = { updated_at: string; }; }; - care_schedules: { + opensprout_care_schedules: { Row: { id: string; user_id: string; @@ -132,7 +132,7 @@ export type Database = { updated_at: string; }; }; - care_logs: { + opensprout_care_logs: { Row: { id: string; user_id: string; @@ -163,7 +163,7 @@ export type Database = { task_instance_id?: string | null; }; }; - task_instances: { + opensprout_task_instances: { Row: { id: string; user_id: string; @@ -188,7 +188,7 @@ export type Database = { updated_at: string; }; }; - journal_entries: { + opensprout_journal_entries: { Row: { id: string; user_id: string; @@ -216,7 +216,7 @@ export type Database = { tags?: string[]; }; }; - knowledge_articles: { + opensprout_knowledge_articles: { Row: { id: string; species_id: string; @@ -231,7 +231,7 @@ export type Database = { updated_at: string; }; }; - diagnosis_entries: { + opensprout_diagnosis_entries: { Row: { id: string; species_id: string; diff --git a/apps/web/src/app/(authenticated)/calendar/page.tsx b/apps/web/src/app/(authenticated)/calendar/page.tsx index d4c5427..05615af 100644 --- a/apps/web/src/app/(authenticated)/calendar/page.tsx +++ b/apps/web/src/app/(authenticated)/calendar/page.tsx @@ -96,7 +96,7 @@ async function fetchMonthTasks( const endStr = `${year}-${String(month + 1).padStart(2, "0")}-${String(daysInMonth).padStart(2, "0")}T23:59:59`; const { data: plants } = await client - .from("plants") + .from("opensprout_plants") .select("id, name, location") .eq("user_id", userId) .is("deleted_at", null); @@ -106,7 +106,7 @@ async function fetchMonthTasks( ); const { data: tasks, error } = await client - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("user_id", userId) .in("status", ["pending", "snoozed"]) diff --git a/apps/web/src/app/api/mcp/tokens/[id]/route.ts b/apps/web/src/app/api/mcp/tokens/[id]/route.ts index da3c05d..8fc77a9 100644 --- a/apps/web/src/app/api/mcp/tokens/[id]/route.ts +++ b/apps/web/src/app/api/mcp/tokens/[id]/route.ts @@ -30,7 +30,7 @@ export async function DELETE( // Verify the token belongs to the current user const admin = createAdminClient(); // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { data: existing, error: lookupError } = await (admin.from("mcp_tokens") as any) + const { data: existing, error: lookupError } = await (admin.from("opensprout_mcp_tokens") as any) .select("id, user_id, revoked_at") .eq("id", id) .single(); @@ -58,7 +58,7 @@ export async function DELETE( } // eslint-disable-next-line @typescript-eslint/no-explicit-any - await (admin.from("mcp_tokens") as any) + await (admin.from("opensprout_mcp_tokens") as any) .update({ revoked_at: new Date().toISOString() }) .eq("id", id); diff --git a/apps/web/src/app/api/mcp/tokens/route.ts b/apps/web/src/app/api/mcp/tokens/route.ts index 5784ec2..6b96891 100644 --- a/apps/web/src/app/api/mcp/tokens/route.ts +++ b/apps/web/src/app/api/mcp/tokens/route.ts @@ -62,7 +62,7 @@ export async function POST(request: Request) { // Store hash + prefix const admin = createAdminClient(); // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { error: insertError } = await (admin.from("mcp_tokens") as any) + const { error: insertError } = await (admin.from("opensprout_mcp_tokens") as any) .insert({ name, user_id: user.id, @@ -102,7 +102,7 @@ export async function GET() { const admin = createAdminClient(); // eslint-disable-next-line @typescript-eslint/no-explicit-any - const { data, error } = await (admin.from("mcp_tokens") as any) + const { data, error } = await (admin.from("opensprout_mcp_tokens") as any) .select("id, name, token_prefix, last_used_at, created_at, revoked_at") .eq("user_id", user.id) .order("created_at", { ascending: false }); diff --git a/apps/web/src/lib/data/db.ts b/apps/web/src/lib/data/db.ts index 1457bfa..f6a58c3 100644 --- a/apps/web/src/lib/data/db.ts +++ b/apps/web/src/lib/data/db.ts @@ -12,12 +12,12 @@ const DB_VERSION = 1; * They use the record's `id` as the key path. */ const CACHE_STORES = [ - "plants", - "schedules", - "tasks", - "logs", - "journalEntries", - "journalPhotos", + "opensprout_plants", + "opensprout_care_schedules", + "opensprout_task_instances", + "opensprout_care_logs", + "opensprout_journal_entries", + "opensprout_journal_photos", ] as const; diff --git a/apps/web/src/lib/data/identify-history.ts b/apps/web/src/lib/data/identify-history.ts index 99c8788..ccdb8d0 100644 --- a/apps/web/src/lib/data/identify-history.ts +++ b/apps/web/src/lib/data/identify-history.ts @@ -28,15 +28,15 @@ export async function saveIdentification( }, ): Promise { const { data: inserted, error } = await supabase - .from("identifications") + .from("opensprout_identifications") .insert({ user_id: userId, photo_path: data.photo_path, - results: data.results as Database["public"]["Tables"]["identifications"]["Insert"]["results"], + results: data.results as Database["public"]["Tables"]["opensprout_identifications"]["Insert"]["results"], selected_species_id: data.selected_species_id ?? null, selected_name: data.selected_name ?? null, confidence: data.confidence ?? null, - diagnosis: (data.diagnosis as Database["public"]["Tables"]["identifications"]["Insert"]["diagnosis"]) ?? null, + diagnosis: (data.diagnosis as Database["public"]["Tables"]["opensprout_identifications"]["Insert"]["diagnosis"]) ?? null, }) .select("id") .single(); @@ -54,7 +54,7 @@ export async function listIdentifications( limit?: number, ): Promise { let query = supabase - .from("identifications") + .from("opensprout_identifications") .select("*") .eq("user_id", userId) .order("created_at", { ascending: false }); @@ -78,7 +78,7 @@ export async function getIdentification( id: string, ): Promise { const { data, error } = await supabase - .from("identifications") + .from("opensprout_identifications") .select("*") .eq("id", id) .eq("user_id", userId) @@ -99,7 +99,7 @@ export async function updateIdentificationSelection( name: string | null, ): Promise { const { error } = await supabase - .from("identifications") + .from("opensprout_identifications") .update({ selected_species_id: speciesId, selected_name: name, @@ -110,7 +110,7 @@ export async function updateIdentificationSelection( if (error) throw error; } -type IdentificationsRow = Database["public"]["Tables"]["identifications"]["Row"]; +type IdentificationsRow = Database["public"]["Tables"]["opensprout_identifications"]["Row"]; /** * Maps a raw Supabase row to our IdentificationRecord type. diff --git a/apps/web/src/lib/data/identify.ts b/apps/web/src/lib/data/identify.ts index 3197ab7..547a3ea 100644 --- a/apps/web/src/lib/data/identify.ts +++ b/apps/web/src/lib/data/identify.ts @@ -115,7 +115,7 @@ export async function diagnoseFromPhotoAndSymptoms( let speciesId: string | undefined; if (identifyResult.bestMatch) { const { data: speciesRows } = await supabase - .from("plant_species") + .from("opensprout_plant_species") .select("id") .or( `scientific_name.eq.${identifyResult.bestMatch.scientificName},common_name.eq.${identifyResult.bestMatch.scientificName}`, diff --git a/apps/web/src/lib/data/import.ts b/apps/web/src/lib/data/import.ts index 312ad88..0d86a49 100644 --- a/apps/web/src/lib/data/import.ts +++ b/apps/web/src/lib/data/import.ts @@ -223,7 +223,7 @@ export async function executeImport( })); const { data: plantsResult, error: plantsError } = await supabase - .from("plants") + .from("opensprout_plants") .upsert(plantRecords as never, { onConflict: "client_id", ignoreDuplicates: false, @@ -247,7 +247,7 @@ export async function executeImport( if (clientIds.length > 0) { const { data: fetched } = await supabase - .from("plants") + .from("opensprout_plants") .select("id, client_id") .eq("user_id", userId) .in("client_id", clientIds); @@ -286,7 +286,7 @@ export async function executeImport( }); const { data: schedulesResult, error: schedulesError } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .upsert(scheduleRecords as never, { onConflict: "client_id", ignoreDuplicates: false, @@ -312,7 +312,7 @@ export async function executeImport( }); const { data: logsResult, error: logsError } = await supabase - .from("care_logs") + .from("opensprout_care_logs") .upsert(logRecords as never, { onConflict: "client_id", ignoreDuplicates: false, diff --git a/apps/web/src/lib/data/journal.ts b/apps/web/src/lib/data/journal.ts index 5f63d7c..e6c7367 100644 --- a/apps/web/src/lib/data/journal.ts +++ b/apps/web/src/lib/data/journal.ts @@ -58,7 +58,7 @@ export async function createJournalEntry( ): Promise { const timestamp = nowIso(); const { data, error } = await supabase - .from("journal_entries") + .from("opensprout_journal_entries") .insert({ user_id: userId, plant_id: input.plant_id, @@ -86,7 +86,7 @@ export async function updateJournalEntry( ): Promise { const timestamp = nowIso(); const { data, error } = await supabase - .from("journal_entries") + .from("opensprout_journal_entries") .update({ title: input.title?.trim() ?? undefined, body: input.body?.trim() ?? undefined, @@ -111,7 +111,7 @@ export async function deleteJournalEntry( ): Promise { // Soft delete — mark deleted_at const { error } = await supabase - .from("journal_entries") + .from("opensprout_journal_entries") .update({ deleted_at: nowIso() }) .eq("id", entryId) .eq("user_id", userId); @@ -125,7 +125,7 @@ export async function getJournalEntry( entryId: string, ): Promise { const { data: entry, error: entryError } = await supabase - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("id", entryId) .eq("user_id", userId) @@ -136,7 +136,7 @@ export async function getJournalEntry( if (!entry) return null; const { data: photos, error: photosError } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .select("*") .eq("journal_entry_id", entryId) .eq("user_id", userId) @@ -157,7 +157,7 @@ export async function listJournalEntries( filter?: JournalFilter, ): Promise { let query = supabase - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("user_id", userId) .is("deleted_at", null); @@ -182,7 +182,7 @@ export async function listJournalEntries( // Fetch photos for all entries in one query const entryIds = entries.map((e) => e.id); const { data: allPhotos, error: photosError } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .select("*") .eq("user_id", userId) .in("journal_entry_id", entryIds) diff --git a/apps/web/src/lib/data/knowledge.ts b/apps/web/src/lib/data/knowledge.ts index 89e1631..1f242d3 100644 --- a/apps/web/src/lib/data/knowledge.ts +++ b/apps/web/src/lib/data/knowledge.ts @@ -8,7 +8,7 @@ export async function getSpeciesById( id: string, ): Promise { const { data, error } = await supabase - .from("plant_species") + .from("opensprout_plant_species") .select("*") .eq("id", id) .maybeSingle(); @@ -27,7 +27,7 @@ export async function searchSpecies( const lowered = trimmed.toLowerCase(); const { data, error } = await supabase - .from("plant_species") + .from("opensprout_plant_species") .select("*") .limit(50); @@ -69,7 +69,7 @@ export async function getKnowledgeArticles( speciesId: string, ): Promise { const { data, error } = await supabase - .from("knowledge_articles") + .from("opensprout_knowledge_articles") .select("*") .eq("species_id", speciesId) .order("sort_order", { ascending: true }); @@ -83,7 +83,7 @@ export async function getDiagnosisEntries( speciesId?: string, ): Promise { let query = supabase - .from("diagnosis_entries") + .from("opensprout_diagnosis_entries") .select("*") .order("sort_order", { ascending: true }); @@ -106,7 +106,7 @@ export async function getDiagnosisByCategory( category: DiagnosisEntryRow["category"], ): Promise { const { data, error } = await supabase - .from("diagnosis_entries") + .from("opensprout_diagnosis_entries") .select("*") .eq("category", category) .order("sort_order", { ascending: true }); diff --git a/apps/web/src/lib/data/mcp-tokens.ts b/apps/web/src/lib/data/mcp-tokens.ts index d57eed2..cd20fd3 100644 --- a/apps/web/src/lib/data/mcp-tokens.ts +++ b/apps/web/src/lib/data/mcp-tokens.ts @@ -45,7 +45,7 @@ export async function listMcpTokens( userId: string, ): Promise { const { data, error } = await supabase - .from("mcp_tokens") + .from("opensprout_mcp_tokens") .select("id, user_id, name, token_prefix, last_used_at, created_at, revoked_at") .eq("user_id", userId) .order("created_at", { ascending: false }); @@ -64,7 +64,7 @@ export async function createMcpToken( const prefix = getTokenPrefix(rawToken); const { data, error } = await (supabase as any) // eslint-disable-line @typescript-eslint/no-explicit-any - .from("mcp_tokens") + .from("opensprout_mcp_tokens") .insert({ user_id: userId, name, @@ -85,7 +85,7 @@ export async function revokeMcpToken( userId: string, ): Promise { const { error } = await (supabase as any) // eslint-disable-line @typescript-eslint/no-explicit-any - .from("mcp_tokens") + .from("opensprout_mcp_tokens") .update({ revoked_at: new Date().toISOString() }) .eq("id", tokenId) .eq("user_id", userId); diff --git a/apps/web/src/lib/data/photos.ts b/apps/web/src/lib/data/photos.ts index 7c68209..a577618 100644 --- a/apps/web/src/lib/data/photos.ts +++ b/apps/web/src/lib/data/photos.ts @@ -65,7 +65,7 @@ export async function uploadPlantPhoto( // Save metadata to journal_photos const { data: photoRow, error: insertError } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .insert({ user_id: userId, plant_id: plantId, @@ -169,7 +169,7 @@ export async function setPlantCoverPhoto( coverObjectPath: string | null, ): Promise { const { error } = await supabase - .from("plants") + .from("opensprout_plants") .update({ cover_photo_path: coverObjectPath }) .eq("id", plantId) .eq("user_id", userId); @@ -205,7 +205,7 @@ export async function deletePhoto( ): Promise { // Fetch photo to get object path const { data: photo, error: fetchError } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .select("object_path") .eq("id", photoId) .eq("user_id", userId) @@ -223,7 +223,7 @@ export async function deletePhoto( // Soft delete metadata const { error: deleteError } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .update({ deleted_at: nowIso() }) .eq("id", photoId) .eq("user_id", userId); @@ -240,7 +240,7 @@ export async function listPlantPhotos( plantId: string, ): Promise { const { data, error } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .select("*") .eq("user_id", userId) .eq("plant_id", plantId) diff --git a/apps/web/src/lib/data/plants.ts b/apps/web/src/lib/data/plants.ts index cff18c8..5481093 100644 --- a/apps/web/src/lib/data/plants.ts +++ b/apps/web/src/lib/data/plants.ts @@ -38,7 +38,7 @@ export async function createPlantSchedules( const timestamp = nowIso(); const schedules = presets.map((p) => buildSchedule(userId, plantId, p.careType, p.cadenceDays, timestamp)); - const { error } = await supabase.from("care_schedules").insert(schedules); + const { error } = await supabase.from("opensprout_care_schedules").insert(schedules); if (error) throw error; } @@ -49,7 +49,7 @@ export async function updateCareSchedule( input: ScheduleUpdateInput, ): Promise { const { error } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .update({ ...input, client_updated_at: nowIso(), @@ -66,7 +66,7 @@ export async function deleteCareSchedule( scheduleId: string, ): Promise { const { error } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .update({ deleted_at: new Date().toISOString(), active: false, client_updated_at: nowIso() }) .eq("id", scheduleId) .eq("user_id", userId); @@ -100,20 +100,20 @@ function cleanText(value?: string) { export async function listDashboardData(supabase: Client, userId: string): Promise { const [plantsResult, schedulesResult, logsResult] = await Promise.all([ supabase - .from("plants") + .from("opensprout_plants") .select("*") .eq("user_id", userId) .is("deleted_at", null) .order("updated_at", { ascending: false }), supabase - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("user_id", userId) .is("deleted_at", null) .eq("active", true) .order("next_due_at", { ascending: true, nullsFirst: false }), supabase - .from("care_logs") + .from("opensprout_care_logs") .select("*") .eq("user_id", userId) .is("deleted_at", null) @@ -136,7 +136,7 @@ export async function createPlant(supabase: Client, userId: string, values: Plan const validated = validatePlantValues(values); const timestamp = nowIso(); const { data: plant, error } = await supabase - .from("plants") + .from("opensprout_plants") .insert({ user_id: userId, name: validated.name, @@ -159,7 +159,7 @@ export async function createPlant(supabase: Client, userId: string, values: Plan export async function updatePlant(supabase: Client, userId: string, plantId: string, values: PlantFormValues) { const validated = validatePlantValues(values); const { data, error } = await supabase - .from("plants") + .from("opensprout_plants") .update({ name: validated.name, species_id: cleanText(validated.species_id), @@ -180,7 +180,7 @@ export async function updatePlant(supabase: Client, userId: string, plantId: str export async function deletePlant(supabase: Client, userId: string, plantId: string) { const { error } = await supabase - .from("plants") + .from("opensprout_plants") .update({ deleted_at: new Date().toISOString() }) .eq("id", plantId) .eq("user_id", userId); @@ -191,7 +191,7 @@ export async function deletePlant(supabase: Client, userId: string, plantId: str export async function archivePlant(supabase: Client, userId: string, plantId: string) { const { error } = await supabase - .from("plants") + .from("opensprout_plants") .update({ archived_at: new Date().toISOString() }) .eq("id", plantId) .eq("user_id", userId) @@ -201,7 +201,7 @@ export async function archivePlant(supabase: Client, userId: string, plantId: st export async function restorePlant(supabase: Client, userId: string, plantId: string) { const { error } = await supabase - .from("plants") + .from("opensprout_plants") .update({ archived_at: null }) .eq("id", plantId) .eq("user_id", userId); @@ -210,7 +210,7 @@ export async function restorePlant(supabase: Client, userId: string, plantId: st export async function toggleFavorite(supabase: Client, userId: string, plantId: string, isFavorite: boolean) { const { error } = await supabase - .from("plants") + .from("opensprout_plants") .update({ is_favorite: isFavorite }) .eq("id", plantId) .eq("user_id", userId); @@ -238,7 +238,7 @@ export async function listPlantLocations( userId: string, ): Promise { const { data, error } = await supabase - .from("plants") + .from("opensprout_plants") .select("location") .eq("user_id", userId) .is("deleted_at", null) @@ -257,7 +257,7 @@ export async function getPlantHealthCounts( userId: string, ): Promise> { const { data, error } = await supabase - .from("plants") + .from("opensprout_plants") .select("health_status") .eq("user_id", userId) .is("deleted_at", null); @@ -350,7 +350,7 @@ export function sortAndFilterPlants( export async function markCareDone(supabase: Client, userId: string, plantId: string, careType: CareType) { const { data: schedule } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("user_id", userId) .eq("plant_id", plantId) @@ -373,7 +373,7 @@ export async function markCareDone(supabase: Client, userId: string, plantId: st custom: "Marked cared for", }; const { data: log, error: logError } = await supabase - .from("care_logs") + .from("opensprout_care_logs") .insert({ user_id: userId, plant_id: plantId, @@ -398,7 +398,7 @@ export async function markCareDone(supabase: Client, userId: string, plantId: st : schedule.cadence_value; const { error: scheduleError } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .update({ last_completed_at: timestamp, next_due_at: addDaysIso(days), diff --git a/apps/web/src/lib/data/species.ts b/apps/web/src/lib/data/species.ts index eb3deeb..dfb0bc9 100644 --- a/apps/web/src/lib/data/species.ts +++ b/apps/web/src/lib/data/species.ts @@ -5,7 +5,7 @@ type Client = SupabaseClient; export async function listPlantSpecies(supabase: Client): Promise { const { data, error } = await supabase - .from("plant_species") + .from("opensprout_plant_species") .select("*") .order("common_name", { ascending: true }); @@ -31,7 +31,7 @@ export async function searchPlantSpecies(supabase: Client, query: string): Promi export async function getPlantSpeciesById(supabase: Client, id: string): Promise { const { data, error } = await supabase - .from("plant_species") + .from("opensprout_plant_species") .select("*") .eq("id", id) .maybeSingle(); diff --git a/apps/web/src/lib/data/sync.ts b/apps/web/src/lib/data/sync.ts index 58bcfd2..6ceed4b 100644 --- a/apps/web/src/lib/data/sync.ts +++ b/apps/web/src/lib/data/sync.ts @@ -42,24 +42,24 @@ export type SyncStats = { * Maps Supabase table names to local IndexedDB cache store names. */ const TABLE_TO_CACHE: Record = { - plants: "plants", - care_schedules: "schedules", - care_logs: "logs", - task_instances: "tasks", - journal_entries: "journalEntries", - journal_photos: "journalPhotos", + plants: "opensprout_plants", + care_schedules: "opensprout_care_schedules", + care_logs: "opensprout_care_logs", + task_instances: "opensprout_task_instances", + journal_entries: "opensprout_journal_entries", + journal_photos: "opensprout_journal_photos", }; /** * The tables that are pulled during a fresh sync. */ const PULL_TABLES = [ - "plants", - "care_schedules", - "care_logs", - "task_instances", - "journal_entries", - "journal_photos", + "opensprout_plants", + "opensprout_care_schedules", + "opensprout_care_logs", + "opensprout_task_instances", + "opensprout_journal_entries", + "opensprout_journal_photos", ] as const; const SUPABASE_URL = diff --git a/apps/web/src/lib/data/tasks.ts b/apps/web/src/lib/data/tasks.ts index b62370b..246da53 100644 --- a/apps/web/src/lib/data/tasks.ts +++ b/apps/web/src/lib/data/tasks.ts @@ -55,7 +55,7 @@ export async function ensureTaskInstances( ): Promise { // Fetch active schedules const { data: schedules, error: schedError } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("user_id", userId) .is("deleted_at", null) @@ -70,7 +70,7 @@ export async function ensureTaskInstances( for (const schedule of schedules) { // Find existing pending/snoozed instances for this schedule const { data: existing } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .select("id, due_at") .eq("user_id", userId) .eq("schedule_id", schedule.id) @@ -92,7 +92,7 @@ export async function ensureTaskInstances( // Check if one was already completed today const { data: completed } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .select("id") .eq("user_id", userId) .eq("schedule_id", schedule.id) @@ -106,7 +106,7 @@ export async function ensureTaskInstances( // Create a new task instance const timestamp = nowIso(); const { error: insertError } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .insert({ user_id: userId, plant_id: schedule.plant_id, @@ -143,7 +143,7 @@ export async function listTasks( }> { // Fetch plants for name resolution const { data: plants } = await supabase - .from("plants") + .from("opensprout_plants") .select("id, name, location") .eq("user_id", userId) .is("deleted_at", null); @@ -157,7 +157,7 @@ export async function listTasks( const todayEnd = now.toISOString().slice(0, 10) + "T23:59:59"; const { data: tasks, error } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("user_id", userId) .in("status", ["pending", "snoozed"]) @@ -214,7 +214,7 @@ export async function completeTask( ): Promise { // Fetch the task const { data: task, error: taskError } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .select("*") .eq("id", taskId) .eq("user_id", userId) @@ -228,7 +228,7 @@ export async function completeTask( let schedule: CareScheduleRow | null = null; if (taskRow.schedule_id) { const { data: sched } = await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .select("*") .eq("id", taskRow.schedule_id as string) .eq("user_id", userId) @@ -241,7 +241,7 @@ export async function completeTask( // Create care log const { data: log, error: logError } = await supabase - .from("care_logs") + .from("opensprout_care_logs") .insert({ user_id: userId, plant_id: taskRow.plant_id, @@ -264,7 +264,7 @@ export async function completeTask( // Mark task as done const { error: updateError } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "done", completed_log_id: log.id, @@ -291,7 +291,7 @@ export async function completeTask( nextDue.setDate(nextDue.getDate() + days); await supabase - .from("care_schedules") + .from("opensprout_care_schedules") .update({ last_completed_at: timestamp, next_due_at: nextDue.toISOString(), @@ -315,7 +315,7 @@ export async function skipTask( ): Promise { const timestamp = nowIso(); const { error } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "skipped", client_updated_at: timestamp, @@ -340,7 +340,7 @@ export async function snoozeTask( ): Promise { const timestamp = nowIso(); const { error } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .update({ status: "snoozed", snoozed_until: snoozeUntil, @@ -366,7 +366,7 @@ export async function rescheduleTask( ): Promise { const timestamp = nowIso(); const { error } = await supabase - .from("task_instances") + .from("opensprout_task_instances") .update({ due_at: newDueAt, status: "pending", @@ -417,7 +417,7 @@ export async function listPlantTimeline( ): Promise { // Fetch care logs const { data: logs, error: logError } = await supabase - .from("care_logs") + .from("opensprout_care_logs") .select("*") .eq("user_id", userId) .eq("plant_id", plantId) @@ -429,7 +429,7 @@ export async function listPlantTimeline( // Fetch journal entries with their photos const { data: entries, error: entryError } = await supabase - .from("journal_entries") + .from("opensprout_journal_entries") .select("*") .eq("user_id", userId) .eq("plant_id", plantId) @@ -444,7 +444,7 @@ export async function listPlantTimeline( if (entries && entries.length > 0) { const entryIds = entries.map((e) => e.id); const { data: photos, error: photosError } = await supabase - .from("journal_photos") + .from("opensprout_journal_photos") .select("journal_entry_id, object_path, content_type") .eq("user_id", userId) .in("journal_entry_id", entryIds) @@ -555,8 +555,8 @@ export async function listJournalFeed( // Fetch care logs with plant name const logResponse = await supabase - .from("care_logs") - .select("*, plants!inner(name)") + .from("opensprout_care_logs") + .select("*, opensprout_plants!inner(name)") .eq("user_id", userId) .is("deleted_at", null) .order("occurred_at", { ascending: false }) @@ -567,8 +567,8 @@ export async function listJournalFeed( // Fetch journal entries with plant name const entryResponse = await supabase - .from("journal_entries") - .select("*, plants!inner(name)") + .from("opensprout_journal_entries") + .select("*, opensprout_plants!inner(name)") .eq("user_id", userId) .is("deleted_at", null) .order("observed_at", { ascending: false }) diff --git a/apps/web/src/lib/data/types.ts b/apps/web/src/lib/data/types.ts index e43094e..fd03529 100644 --- a/apps/web/src/lib/data/types.ts +++ b/apps/web/src/lib/data/types.ts @@ -9,7 +9,7 @@ export type TaskStatus = "pending" | "done" | "skipped" | "snoozed" | "cancelled export type Database = { public: { Tables: { - plants: { + opensprout_plants: { Row: { id: string; user_id: string; @@ -58,10 +58,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - plant_species: { + opensprout_plant_species: { Row: { id: string; common_name: string; @@ -122,10 +122,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - care_schedules: { + opensprout_care_schedules: { Row: { id: string; user_id: string; @@ -174,10 +174,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - care_logs: { + opensprout_care_logs: { Row: { id: string; user_id: string; @@ -220,10 +220,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - profiles: { + opensprout_profiles: { Row: { id: string; display_name: string | null; @@ -240,10 +240,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - task_instances: { + opensprout_task_instances: { Row: { id: string; user_id: string; @@ -290,10 +290,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - journal_entries: { + opensprout_journal_entries: { Row: { id: string; user_id: string; @@ -330,10 +330,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - journal_photos: { + opensprout_journal_photos: { Row: { id: string; user_id: string; @@ -382,10 +382,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - data_transfers: { + opensprout_data_transfers: { Row: { id: string; user_id: string; @@ -424,10 +424,10 @@ export type Database = { finished_at?: string | null; created_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - sync_devices: { + opensprout_sync_devices: { Row: { id: string; user_id: string; @@ -452,10 +452,10 @@ export type Database = { last_pushed_at?: string | null; created_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - knowledge_articles: { + opensprout_knowledge_articles: { Row: { id: string; species_id: string; @@ -482,10 +482,10 @@ export type Database = { created_at?: string; updated_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - diagnosis_entries: { + opensprout_diagnosis_entries: { Row: { id: string; species_id: string; @@ -508,10 +508,10 @@ export type Database = { sort_order?: number; created_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; - identifications: { + opensprout_identifications: { Row: { id: string; user_id: string; @@ -536,7 +536,7 @@ export type Database = { source?: string; created_at?: string; }; - Update: Partial; + Update: Partial; Relationships: []; }; }; @@ -550,26 +550,26 @@ export type Database = { }; }; -export type PlantRow = Database["public"]["Tables"]["plants"]["Row"]; -export type PlantInsert = Database["public"]["Tables"]["plants"]["Insert"]; -export type PlantUpdate = Database["public"]["Tables"]["plants"]["Update"]; -export type PlantSpeciesRow = Database["public"]["Tables"]["plant_species"]["Row"]; -export type CareScheduleRow = Database["public"]["Tables"]["care_schedules"]["Row"]; -export type CareLogRow = Database["public"]["Tables"]["care_logs"]["Row"]; -export type TaskInstanceRow = Database["public"]["Tables"]["task_instances"]["Row"]; -export type JournalEntryRow = Database["public"]["Tables"]["journal_entries"]["Row"]; -export type JournalEntryInsert = Database["public"]["Tables"]["journal_entries"]["Insert"]; -export type JournalEntryUpdate = Database["public"]["Tables"]["journal_entries"]["Update"]; -export type JournalPhotoRow = Database["public"]["Tables"]["journal_photos"]["Row"]; -export type JournalPhotoInsert = Database["public"]["Tables"]["journal_photos"]["Insert"]; -export type KnowledgeArticleRow = Database["public"]["Tables"]["knowledge_articles"]["Row"]; -export type KnowledgeArticleInsert = Database["public"]["Tables"]["knowledge_articles"]["Insert"]; -export type KnowledgeArticleUpdate = Database["public"]["Tables"]["knowledge_articles"]["Update"]; -export type DiagnosisEntryRow = Database["public"]["Tables"]["diagnosis_entries"]["Row"]; -export type DiagnosisEntryInsert = Database["public"]["Tables"]["diagnosis_entries"]["Insert"]; -export type DiagnosisEntryUpdate = Database["public"]["Tables"]["diagnosis_entries"]["Update"]; -export type IdentificationRow = Database["public"]["Tables"]["identifications"]["Row"]; -export type IdentificationInsert = Database["public"]["Tables"]["identifications"]["Insert"]; -export type IdentificationUpdate = Database["public"]["Tables"]["identifications"]["Update"]; +export type PlantRow = Database["public"]["Tables"]["opensprout_plants"]["Row"]; +export type PlantInsert = Database["public"]["Tables"]["opensprout_plants"]["Insert"]; +export type PlantUpdate = Database["public"]["Tables"]["opensprout_plants"]["Update"]; +export type PlantSpeciesRow = Database["public"]["Tables"]["opensprout_plant_species"]["Row"]; +export type CareScheduleRow = Database["public"]["Tables"]["opensprout_care_schedules"]["Row"]; +export type CareLogRow = Database["public"]["Tables"]["opensprout_care_logs"]["Row"]; +export type TaskInstanceRow = Database["public"]["Tables"]["opensprout_task_instances"]["Row"]; +export type JournalEntryRow = Database["public"]["Tables"]["opensprout_journal_entries"]["Row"]; +export type JournalEntryInsert = Database["public"]["Tables"]["opensprout_journal_entries"]["Insert"]; +export type JournalEntryUpdate = Database["public"]["Tables"]["opensprout_journal_entries"]["Update"]; +export type JournalPhotoRow = Database["public"]["Tables"]["opensprout_journal_photos"]["Row"]; +export type JournalPhotoInsert = Database["public"]["Tables"]["opensprout_journal_photos"]["Insert"]; +export type KnowledgeArticleRow = Database["public"]["Tables"]["opensprout_knowledge_articles"]["Row"]; +export type KnowledgeArticleInsert = Database["public"]["Tables"]["opensprout_knowledge_articles"]["Insert"]; +export type KnowledgeArticleUpdate = Database["public"]["Tables"]["opensprout_knowledge_articles"]["Update"]; +export type DiagnosisEntryRow = Database["public"]["Tables"]["opensprout_diagnosis_entries"]["Row"]; +export type DiagnosisEntryInsert = Database["public"]["Tables"]["opensprout_diagnosis_entries"]["Insert"]; +export type DiagnosisEntryUpdate = Database["public"]["Tables"]["opensprout_diagnosis_entries"]["Update"]; +export type IdentificationRow = Database["public"]["Tables"]["opensprout_identifications"]["Row"]; +export type IdentificationInsert = Database["public"]["Tables"]["opensprout_identifications"]["Insert"]; +export type IdentificationUpdate = Database["public"]["Tables"]["opensprout_identifications"]["Update"]; export type Client = SupabaseClient; diff --git a/supabase/migrations/20260628000000_prefix_opensprout_tables.sql b/supabase/migrations/20260628000000_prefix_opensprout_tables.sql new file mode 100644 index 0000000..4a5c0b0 --- /dev/null +++ b/supabase/migrations/20260628000000_prefix_opensprout_tables.sql @@ -0,0 +1,63 @@ +-- Rename OpenSprout primary tables to opensprout_ prefix +-- These share the project with OpenSend (which already uses opensend_ prefix) + +ALTER TABLE IF EXISTS public.profiles RENAME TO opensprout_profiles; +ALTER TABLE IF EXISTS public.plants RENAME TO opensprout_plants; +ALTER TABLE IF EXISTS public.care_schedules RENAME TO opensprout_care_schedules; +ALTER TABLE IF EXISTS public.task_instances RENAME TO opensprout_task_instances; +ALTER TABLE IF EXISTS public.care_logs RENAME TO opensprout_care_logs; +ALTER TABLE IF EXISTS public.journal_entries RENAME TO opensprout_journal_entries; +ALTER TABLE IF EXISTS public.journal_photos RENAME TO opensprout_journal_photos; +ALTER TABLE IF EXISTS public.data_transfers RENAME TO opensprout_data_transfers; +ALTER TABLE IF EXISTS public.sync_devices RENAME TO opensprout_sync_devices; +ALTER TABLE IF EXISTS public.plant_species RENAME TO opensprout_plant_species; +ALTER TABLE IF EXISTS public.knowledge_articles RENAME TO opensprout_knowledge_articles; +ALTER TABLE IF EXISTS public.diagnosis_entries RENAME TO opensprout_diagnosis_entries; +ALTER TABLE IF EXISTS public.identifications RENAME TO opensprout_identifications; +ALTER TABLE IF EXISTS public.mcp_tokens RENAME TO opensprout_mcp_tokens; + +-- Update table comments +COMMENT ON TABLE public.opensprout_profiles IS 'OpenSprout: user profiles'; +COMMENT ON TABLE public.opensprout_plants IS 'OpenSprout: user-owned plant records'; +COMMENT ON TABLE public.opensprout_care_schedules IS 'OpenSprout: recurring care rules'; +COMMENT ON TABLE public.opensprout_task_instances IS 'OpenSprout: generated care-task due-dates'; +COMMENT ON TABLE public.opensprout_care_logs IS 'OpenSprout: completed care actions'; +COMMENT ON TABLE public.opensprout_journal_entries IS 'OpenSprout: plant journal entries'; +COMMENT ON TABLE public.opensprout_journal_photos IS 'OpenSprout: photo metadata'; +COMMENT ON TABLE public.opensprout_data_transfers IS 'OpenSprout: export/import job tracking'; +COMMENT ON TABLE public.opensprout_sync_devices IS 'OpenSprout: offline-sync device registry'; +COMMENT ON TABLE public.opensprout_plant_species IS 'OpenSprout: species knowledge base'; +COMMENT ON TABLE public.opensprout_knowledge_articles IS 'OpenSprout: care/diagnosis articles'; +COMMENT ON TABLE public.opensprout_diagnosis_entries IS 'OpenSprout: symptom→cause→solution'; +COMMENT ON TABLE public.opensprout_identifications IS 'OpenSprout: AI identification results'; +COMMENT ON TABLE public.opensprout_mcp_tokens IS 'OpenSprout: MCP server auth tokens'; + +-- Update the delete_account() function to use new table names +-- Table RENAME does not update hardcoded table names in function bodies +CREATE OR REPLACE FUNCTION public.delete_account() +RETURNS void +LANGUAGE plpgsql +SECURITY DEFINER +SET search_path = public +AS $$ +DECLARE + v_user_id uuid; +BEGIN + v_user_id := auth.uid(); + IF v_user_id IS NULL THEN + RAISE EXCEPTION 'Not authenticated'; + END IF; + + DELETE FROM public.opensprout_journal_photos WHERE user_id = v_user_id; + DELETE FROM public.opensprout_journal_entries WHERE user_id = v_user_id; + DELETE FROM public.opensprout_care_logs WHERE user_id = v_user_id; + DELETE FROM public.opensprout_task_instances WHERE user_id = v_user_id; + DELETE FROM public.opensprout_care_schedules WHERE user_id = v_user_id; + DELETE FROM public.opensprout_identifications WHERE user_id = v_user_id; + DELETE FROM public.opensprout_mcp_tokens WHERE user_id = v_user_id; + DELETE FROM public.opensprout_sync_devices WHERE user_id = v_user_id; + DELETE FROM public.opensprout_data_transfers WHERE user_id = v_user_id; + DELETE FROM public.opensprout_plants WHERE user_id = v_user_id; + DELETE FROM public.opensprout_profiles WHERE id = v_user_id; +END; +$$;