Skip to content

Conversation

@TriptiMirani
Copy link
Contributor

@TriptiMirani TriptiMirani commented Mar 26, 2025

Closes #87

📝 Description

This PR fixes an issue where users encountered an error after signing in with Google because the patient table was missing in Supabase. Previously, after a successful Google Sign-In, users saw:

"Signed in as FirstName LastName" (Success message)
"An error occurred, please try again." (Failure message due to missing database table)

The root cause of this issue was the patient table not being created automatically in new deployments, leading to a PostgrestException (relation does not exist - SQLSTATE 42P01) when checking if a patient exists.

This PR ensures that the database schema is set up automatically using Supabase migrations, so developers no longer need to manually create the patient table.


🔧 Changes Made

  • Added Supabase migration to create the patient table automatically.
  • Enabled Row-Level Security (RLS) for controlled database access.
  • Added policies to allow authenticated users to read, insert, update, and delete their own data.
  • Updated checkIfPatientExists() function to handle missing table errors gracefully.
  • Improved error handling to display a more informative message when the table is missing.

📷 Screenshots or Visual Changes (if applicable)

Before (Error in Logs & Red Pop-Up Message):

I/flutter (21358): Error checking patient existence: 
PostgrestException(message: {"code":"42P01","message":"relation \"public.patient\" does not exist"}, code: 404)

"An error occurred, please try again."

After (Database Auto-Creation & Fix Applied):

🎉 No error pop-ups! The app correctly proceeds to the next screen.

image

✅ Standard Database Schema created in Supabase.


🤝 Collaboration

None


✅ Checklist

  • I have read the contributing guidelines.
  • I have tested that Supabase migrations run successfully.
  • I have verified that users can sign in and proceed without errors.
  • I have added documentation on setting up the database automatically.
  • Any dependent changes have been merged and published in downstream modules.

✨ Final Notes

This PR improves the developer experience by making database setup seamless and ensures a smooth onboarding process for new contributors.

Note: After this PR is implemented correctly we will have to update the README.md for supabase cli installation and other commands.

@@ -0,0 +1,37 @@
-- Create patient table if it does not exist
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we have a similar thing for first time setup? I don't think running this file will setup all the tables, it will only create a patient table. Maybe have all the tables with the exact schema so that we can run a command to setup all the tables?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right—this file currently sets up only the patient table. We can extend it to include all tables with their exact schemas to ensure a complete first-time setup. I'll update the script to create all necessary tables so that a single command initializes the entire database. Let me know if you have any specific requirements or constraints for the schema.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great! No specific requirements or constraints as long as it's the same as the schema file

@TriptiMirani
Copy link
Contributor Author

@mdmohsin7 Sorry about the mention, please review the changes.

);

-- Create assessment_questions table if it does not exist
CREATE TABLE IF NOT EXISTS public.assessment_questions (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have assessment_questions and assessment_options tables. Pls check the schema file once

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right—I overlooked that. Apologies for the confusion, and thank you for pointing it out. I’ll fix it shortly.

@TriptiMirani
Copy link
Contributor Author

Hi @mdmohsin7 ,
I’ve been working on this and I ran into a roadblock with the illustrations on the assessment list screen not showing up. I spent the past 2–3 days trying different approaches to get the SVGs to render properly, but after thorough testing, I’ve come to the conclusion that using SVGs won’t work as expected in this case.

It seems the best solution is to switch the illustrations to PNG format. With your permission, can I go ahead and make this change within the same PR?
Also, just to mention, I had previously worked on Issue #96 (which has since been merged), and it appears that may have contributed to this issue.

Thanks for your time and sorry for the mistake!

@mdmohsin7
Copy link
Member

No worries @TriptiMirani, if they don't work in svg, you can use png, and personally I suggest doing them in a new PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: "An error occurred, please try again" After Google Sign-In

2 participants