AOSSIE-Org / AOSSIE-Org/Ell-ena

BUG:Add missing indexes and constraints for tickets and ticket_comments tables

Aperta
#59 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Dart
Stelle
54
Fork
110
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### Is there an existing issue for this?

- [x] I have searched the existing issues

### What happened?

## Issue Overview
There are potential **security, validation, and performance issues** in the current schema:

1. Missing indexes on columns used in RLS policies:
- `tickets.team_id`
- `ticket_comments.ticket_id`
- `users.team_id` (for auth.uid() lookups)

2. Missing CHECK constraints to ensure consistency:
- `assigned_to` should belong to the same team as `tickets.team_id`
- `created_by` should belong to the same team as `tickets.team_id`

## Steps to Reproduce
1. Insert tickets and comments for multiple teams.
2. Run queries with RLS enabled.
3. Observe slower performance due to missing indexes or possible invalid assignments if constraints are not enforced.

## Expected Behavior
- Queries should be fast for RLS checks.
- Data integrity should prevent assigning tickets to users outside the team.

## Actual Behavior
- RLS policies may perform poorly due to missing indexes.
- Tickets/comments can be assigned to users not in the team, breaking integrity.

## File Location
`sqls/04_tickets_schema.sql`

## Suggested Fix
- Create indexes:
```sql
CREATE INDEX idx_tickets_team_id ON tickets(team_id);
CREATE INDEX idx_ticket_comments_ticket_id ON ticket_comments(ticket_id);
CREATE INDEX idx_users_team_id ON users(team_id);

### Record

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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.