AOSSIE-Org / AOSSIE-Org/NeuroTrack

BUG: Creating tables fails with incorrect schema.sql

Abierto
#155 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Dart
Estrellas
29
Forks
50
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

> This issue and related PR were fully identified and analyzed by myself. Claude was only used to assist with writing descriptions in English.

## 📌 Issue Overview

`schema.sql` fails to execute when copied into the Supabase SQL Editor due to multiple syntax errors, missing table definitions, and incorrect table declaration order.

Previous PR #146 also indicates syntax error, and I found more errors.

## 🔍 Steps to Reproduce

1. Go to Supabase Dashboard → SQL Editor
2. Copy and paste the entire contents of `supabase/schemas/schema.sql` guided by README
3. Click Run
4. See the error:
```
ERROR: 42601: syntax error at or near ")"
ERROR: 42P01: relation "therapist" does not exist
ERROR: 42P01: relation "therapy_type" does not exist
```

## 🎯 Expected Behavior

The full `schema.sql` should execute in a single run, creating all tables and indexes without errors.

## 🚨 Actual Behavior

Execution fails due to the following issues:

1. **Table declaration order**: `patient` is declared before `therapist`, but `patient.therapist_id` references `therapist(id)`. Similarly, `therapy_goal` references `therapy_type(id)` which is declared later.
2. **Trailing commas**: `therapist`, `session`, `observation_master`, `activity_master`, `daily_activities`, and `daily_activity_logs` have a trailing comma after the last column definition.
3. **Missing comma**: `daily_activity_logs` is missing a comma after `activity_items JSONB NOT NULL`.
4. **Missing table**: `therapy_goal.therapy_type_id` references `therapy_type(id)`, but the `therapy_type` table is not defined in the schema.
5. **Dead column**: `therapy_goal.therapy_type INT2` is not used anywhere in the codebase.

## 📷 Screenshot

N/A

## 💡 Suggested Improvements

All fixes have already been applied to `schema.sql` and verified by successfully executing the full script in the Supabase SQL Editor without errors. A PR is ready to be submitted with the following changes:

- Reordered table declarations to respect FK dependencies (`therapist` before `patient`, `therapy`/`therapy_type` before `therapy_goal`)
- Added `therapy_type` table matching the `TherapyTypeModel` in the codebase (`id`, `created_at`, `name`, `description`)
- Removed all trailing commas
- Added the missing comma in `daily_activity_logs`
- Removed the unused `therapy_goal.therapy_type INT2` column

> Have same concern with issue #153 , but this is currently occurring error, so it should be fixed whether we use Supabase as backend or not.

### Record

- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.