AOSSIE-Org / AOSSIE-Org/Ell-ena

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

Offen
#59 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Dart
Sterne
54
Forks
110
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### 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

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.