[FIX] Fix migration SQL syntax and add troubleshooting guide
- Fix 050_data_validation_constraints.sql: Replace IF NOT EXISTS with DO blocks - PostgreSQL doesn't support IF NOT EXISTS with ADD CONSTRAINT - Add quick troubleshooting guide (DEPANNAGE_RAPIDE.md) - Note: .env file is gitignored (as expected)
This commit is contained in:
parent
2a14fa89a9
commit
1a4f1f27d4
2 changed files with 396 additions and 61 deletions
135
DEPANNAGE_RAPIDE.md
Normal file
135
DEPANNAGE_RAPIDE.md
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
# 🔧 Dépannage Rapide - Veza Integration
|
||||
|
||||
## ✅ Problèmes Résolus
|
||||
|
||||
### 1. Migration SQL `050_data_validation_constraints.sql` ❌ → ✅
|
||||
|
||||
**Problème**: `syntax error at or near "NOT"` - PostgreSQL ne supporte pas `IF NOT EXISTS` avec `ADD CONSTRAINT`
|
||||
|
||||
**Solution**: Migration corrigée pour utiliser des blocs `DO $$` (comme dans `930_add_missing_foreign_keys.sql`)
|
||||
|
||||
**Status**: ✅ **CORRIGÉ**
|
||||
|
||||
---
|
||||
|
||||
### 2. Port Redis Occupé ❌ → ✅
|
||||
|
||||
**Problème**: `address already in use` sur port 6379
|
||||
|
||||
**Solution**:
|
||||
```bash
|
||||
# Arrêter l'instance existante
|
||||
docker stop veza_redis
|
||||
|
||||
# Redémarrer via docker-compose
|
||||
docker compose up -d redis
|
||||
```
|
||||
|
||||
**Status**: ✅ **RÉSOLU**
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Démarrage Rapide (Après Corrections)
|
||||
|
||||
### Option 1: Backend + Frontend Seulement (Recommandé pour tests)
|
||||
|
||||
```bash
|
||||
# Terminal 1: Infrastructure
|
||||
make infra-up
|
||||
|
||||
# Terminal 2: Backend
|
||||
cd veza-backend-api
|
||||
go run cmd/api/main.go
|
||||
|
||||
# Terminal 3: Frontend
|
||||
cd apps/web
|
||||
npm run dev
|
||||
```
|
||||
|
||||
**URLs**:
|
||||
- Frontend: http://localhost:3000
|
||||
- Backend: http://localhost:8080
|
||||
- Swagger: http://localhost:8080/docs
|
||||
|
||||
---
|
||||
|
||||
### Option 2: Tout-en-un (avec Makefile)
|
||||
|
||||
```bash
|
||||
# Ignorer les erreurs Rust (non bloquant)
|
||||
make dev 2>&1 | grep -v "libsqlite3-sys"
|
||||
```
|
||||
|
||||
**Note**: Les erreurs Rust (chat-server, stream-server) ne bloquent pas l'intégration backend/frontend.
|
||||
|
||||
---
|
||||
|
||||
## ⚙️ Configuration Backend
|
||||
|
||||
Le fichier `.env` a été créé automatiquement dans `veza-backend-api/.env`:
|
||||
|
||||
```bash
|
||||
APP_ENV=development
|
||||
JWT_SECRET=dev-secret-key-minimum-32-characters-long-for-testing
|
||||
DATABASE_URL=postgres://veza:password@localhost:5432/veza?sslmode=disable
|
||||
REDIS_URL=redis://localhost:6379
|
||||
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
|
||||
APP_PORT=8080
|
||||
LOG_LEVEL=INFO
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Test Rapide
|
||||
|
||||
```bash
|
||||
# 1. Vérifier infrastructure
|
||||
docker compose ps
|
||||
|
||||
# 2. Vérifier backend
|
||||
curl http://localhost:8080/health
|
||||
|
||||
# 3. Vérifier frontend
|
||||
curl http://localhost:3000
|
||||
|
||||
# 4. Ouvrir dans navigateur
|
||||
open http://localhost:3000
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🐛 Problèmes Connus (Non Bloquants)
|
||||
|
||||
### Erreur Rust `libsqlite3-sys`
|
||||
|
||||
**Message**: `failed to select a version for libsqlite3-sys`
|
||||
|
||||
**Impact**: ⚠️ **NON BLOQUANT** - Les serveurs Rust (chat, stream) ne sont pas nécessaires pour tester l'intégration backend/frontend.
|
||||
|
||||
**Solution**: Ignorer cette erreur ou corriger les dépendances Rust séparément.
|
||||
|
||||
---
|
||||
|
||||
### Go Version (air)
|
||||
|
||||
**Message**: `requires go >= 1.25 (running go 1.24.10)`
|
||||
|
||||
**Impact**: ⚠️ **NON BLOQUANT** - Le backend démarre avec `go run` même sans `air`.
|
||||
|
||||
**Solution**: Utiliser `go run cmd/api/main.go` au lieu de `air`.
|
||||
|
||||
---
|
||||
|
||||
## ✅ Checklist Avant Test
|
||||
|
||||
- [x] Migration SQL corrigée
|
||||
- [x] Redis démarré
|
||||
- [x] Backend `.env` configuré
|
||||
- [ ] Backend démarré (port 8080)
|
||||
- [ ] Frontend démarré (port 3000)
|
||||
- [ ] Test dans navigateur
|
||||
|
||||
---
|
||||
|
||||
**Guide complet**: Voir `GUIDE_DEMARRAGE_INTEGRATION.md`
|
||||
|
||||
|
|
@ -1,55 +1,146 @@
|
|||
-- 050_data_validation_constraints.sql
|
||||
-- Data Validation Constraints (BE-DB-011: Add database constraints for data validation)
|
||||
-- Add CHECK constraints for status values, enum constraints
|
||||
-- Note: PostgreSQL doesn't support IF NOT EXISTS with ADD CONSTRAINT, so we use DO blocks
|
||||
|
||||
-- === TRACKS STATUS CONSTRAINTS ===
|
||||
-- Constraint for track status (uploading, processing, completed, failed)
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_tracks_status_valid
|
||||
CHECK (status IN ('uploading', 'processing', 'completed', 'failed'));
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'tracks'
|
||||
AND constraint_name = 'chk_tracks_status_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT chk_tracks_status_valid
|
||||
CHECK (status IN ('uploading', 'processing', 'completed', 'failed'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for stream_status (pending, processing, ready, error)
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_tracks_stream_status_valid
|
||||
CHECK (stream_status IN ('pending', 'processing', 'ready', 'error'));
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'tracks'
|
||||
AND constraint_name = 'chk_tracks_stream_status_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT chk_tracks_stream_status_valid
|
||||
CHECK (stream_status IN ('pending', 'processing', 'ready', 'error'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for counts (non-negative)
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_tracks_counts_non_negative
|
||||
CHECK (play_count >= 0 AND like_count >= 0 AND comment_count >= 0 AND download_count >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'tracks'
|
||||
AND constraint_name = 'chk_tracks_counts_non_negative'
|
||||
) THEN
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT chk_tracks_counts_non_negative
|
||||
CHECK (play_count >= 0 AND like_count >= 0 AND comment_count >= 0 AND download_count >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for year (reasonable range)
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_tracks_year_valid
|
||||
CHECK (year >= 0 AND year <= EXTRACT(YEAR FROM CURRENT_DATE) + 10);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'tracks'
|
||||
AND constraint_name = 'chk_tracks_year_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.tracks
|
||||
ADD CONSTRAINT chk_tracks_year_valid
|
||||
CHECK (year >= 0 AND year <= EXTRACT(YEAR FROM CURRENT_DATE) + 10);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === PLAYLISTS CONSTRAINTS ===
|
||||
-- Constraint for counts (non-negative)
|
||||
ALTER TABLE public.playlists
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_playlists_counts_non_negative
|
||||
CHECK (track_count >= 0 AND follower_count >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'playlists'
|
||||
AND constraint_name = 'chk_playlists_counts_non_negative'
|
||||
) THEN
|
||||
ALTER TABLE public.playlists
|
||||
ADD CONSTRAINT chk_playlists_counts_non_negative
|
||||
CHECK (track_count >= 0 AND follower_count >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === PLAYLIST_TRACKS CONSTRAINTS ===
|
||||
-- Constraint for position (positive)
|
||||
ALTER TABLE public.playlist_tracks
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_playlist_tracks_position_positive
|
||||
CHECK (position >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'playlist_tracks'
|
||||
AND constraint_name = 'chk_playlist_tracks_position_positive'
|
||||
) THEN
|
||||
ALTER TABLE public.playlist_tracks
|
||||
ADD CONSTRAINT chk_playlist_tracks_position_positive
|
||||
CHECK (position >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === HLSTranscodeQueue CONSTRAINTS ===
|
||||
-- Constraint for queue status (pending, processing, completed, failed)
|
||||
ALTER TABLE public.hls_transcode_queue
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_hls_transcode_queue_status_valid
|
||||
CHECK (status IN ('pending', 'processing', 'completed', 'failed'));
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'hls_transcode_queue'
|
||||
AND constraint_name = 'chk_hls_transcode_queue_status_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.hls_transcode_queue
|
||||
ADD CONSTRAINT chk_hls_transcode_queue_status_valid
|
||||
CHECK (status IN ('pending', 'processing', 'completed', 'failed'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for retry counts (non-negative)
|
||||
ALTER TABLE public.hls_transcode_queue
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_hls_transcode_queue_retry_valid
|
||||
CHECK (retry_count >= 0 AND max_retries >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'hls_transcode_queue'
|
||||
AND constraint_name = 'chk_hls_transcode_queue_retry_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.hls_transcode_queue
|
||||
ADD CONSTRAINT chk_hls_transcode_queue_retry_valid
|
||||
CHECK (retry_count >= 0 AND max_retries >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for priority (reasonable range)
|
||||
ALTER TABLE public.hls_transcode_queue
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_hls_transcode_queue_priority_valid
|
||||
CHECK (priority >= 1 AND priority <= 10);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'hls_transcode_queue'
|
||||
AND constraint_name = 'chk_hls_transcode_queue_priority_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.hls_transcode_queue
|
||||
ADD CONSTRAINT chk_hls_transcode_queue_priority_valid
|
||||
CHECK (priority >= 1 AND priority <= 10);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === TRACK_COMMENTS CONSTRAINTS ===
|
||||
-- Constraint for content length (already exists, but ensure it's there)
|
||||
|
|
@ -57,65 +148,175 @@ CHECK (priority >= 1 AND priority <= 10);
|
|||
|
||||
-- === TRACK_PLAYS CONSTRAINTS ===
|
||||
-- Constraint for duration (non-negative)
|
||||
ALTER TABLE public.track_plays
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_track_plays_duration_non_negative
|
||||
CHECK (duration >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'track_plays'
|
||||
AND constraint_name = 'chk_track_plays_duration_non_negative'
|
||||
) THEN
|
||||
ALTER TABLE public.track_plays
|
||||
ADD CONSTRAINT chk_track_plays_duration_non_negative
|
||||
CHECK (duration >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === PLAYBACK_ANALYTICS CONSTRAINTS ===
|
||||
-- Constraint for completion_rate (0-100)
|
||||
ALTER TABLE public.playback_analytics
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_playback_analytics_completion_rate
|
||||
CHECK (completion_rate >= 0 AND completion_rate <= 100);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'playback_analytics'
|
||||
AND constraint_name = 'chk_playback_analytics_completion_rate'
|
||||
) THEN
|
||||
ALTER TABLE public.playback_analytics
|
||||
ADD CONSTRAINT chk_playback_analytics_completion_rate
|
||||
CHECK (completion_rate >= 0 AND completion_rate <= 100);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for counts (non-negative)
|
||||
ALTER TABLE public.playback_analytics
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_playback_analytics_counts_non_negative
|
||||
CHECK (play_time >= 0 AND pause_count >= 0 AND seek_count >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'playback_analytics'
|
||||
AND constraint_name = 'chk_playback_analytics_counts_non_negative'
|
||||
) THEN
|
||||
ALTER TABLE public.playback_analytics
|
||||
ADD CONSTRAINT chk_playback_analytics_counts_non_negative
|
||||
CHECK (play_time >= 0 AND pause_count >= 0 AND seek_count >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === PLAYLIST_VERSION CONSTRAINTS ===
|
||||
-- Constraint for version (positive)
|
||||
ALTER TABLE public.playlist_versions
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_playlist_versions_version_positive
|
||||
CHECK (version > 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'playlist_versions'
|
||||
AND constraint_name = 'chk_playlist_versions_version_positive'
|
||||
) THEN
|
||||
ALTER TABLE public.playlist_versions
|
||||
ADD CONSTRAINT chk_playlist_versions_version_positive
|
||||
CHECK (version > 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for action (created, updated, restored)
|
||||
ALTER TABLE public.playlist_versions
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_playlist_versions_action_valid
|
||||
CHECK (action IN ('created', 'updated', 'restored'));
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'playlist_versions'
|
||||
AND constraint_name = 'chk_playlist_versions_action_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.playlist_versions
|
||||
ADD CONSTRAINT chk_playlist_versions_action_valid
|
||||
CHECK (action IN ('created', 'updated', 'restored'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === TRACK_HISTORY CONSTRAINTS ===
|
||||
-- Constraint for action (created, updated, deleted, published, unpublished, restored)
|
||||
ALTER TABLE public.track_history
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_track_history_action_valid
|
||||
CHECK (action IN ('created', 'updated', 'deleted', 'published', 'unpublished', 'restored'));
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'track_history'
|
||||
AND constraint_name = 'chk_track_history_action_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.track_history
|
||||
ADD CONSTRAINT chk_track_history_action_valid
|
||||
CHECK (action IN ('created', 'updated', 'deleted', 'published', 'unpublished', 'restored'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === BITRATE_ADAPTATION CONSTRAINTS ===
|
||||
-- Constraint for reason (network_slow, network_fast, user_selected, buffer_low)
|
||||
ALTER TABLE public.bitrate_adaptation_logs
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_bitrate_adaptation_reason_valid
|
||||
CHECK (reason IN ('network_slow', 'network_fast', 'user_selected', 'buffer_low'));
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'bitrate_adaptation_logs'
|
||||
AND constraint_name = 'chk_bitrate_adaptation_reason_valid'
|
||||
) THEN
|
||||
ALTER TABLE public.bitrate_adaptation_logs
|
||||
ADD CONSTRAINT chk_bitrate_adaptation_reason_valid
|
||||
CHECK (reason IN ('network_slow', 'network_fast', 'user_selected', 'buffer_low'));
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for bitrates (positive)
|
||||
ALTER TABLE public.bitrate_adaptation_logs
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_bitrate_adaptation_bitrates_positive
|
||||
CHECK (old_bitrate > 0 AND new_bitrate > 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'bitrate_adaptation_logs'
|
||||
AND constraint_name = 'chk_bitrate_adaptation_bitrates_positive'
|
||||
) THEN
|
||||
ALTER TABLE public.bitrate_adaptation_logs
|
||||
ADD CONSTRAINT chk_bitrate_adaptation_bitrates_positive
|
||||
CHECK (old_bitrate > 0 AND new_bitrate > 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === NOTIFICATIONS CONSTRAINTS ===
|
||||
-- Constraint for type (reasonable length)
|
||||
ALTER TABLE public.notifications
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_notifications_type_length
|
||||
CHECK (LENGTH(type) >= 1 AND LENGTH(type) <= 50);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'notifications'
|
||||
AND constraint_name = 'chk_notifications_type_length'
|
||||
) THEN
|
||||
ALTER TABLE public.notifications
|
||||
ADD CONSTRAINT chk_notifications_type_length
|
||||
CHECK (LENGTH(type) >= 1 AND LENGTH(type) <= 50);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Constraint for title (reasonable length)
|
||||
ALTER TABLE public.notifications
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_notifications_title_length
|
||||
CHECK (LENGTH(title) >= 1 AND LENGTH(title) <= 255);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'notifications'
|
||||
AND constraint_name = 'chk_notifications_title_length'
|
||||
) THEN
|
||||
ALTER TABLE public.notifications
|
||||
ADD CONSTRAINT chk_notifications_title_length
|
||||
CHECK (LENGTH(title) >= 1 AND LENGTH(title) <= 255);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- === USER_PROFILES CONSTRAINTS ===
|
||||
-- Constraint for counts (non-negative)
|
||||
ALTER TABLE public.user_profiles
|
||||
ADD CONSTRAINT IF NOT EXISTS chk_user_profiles_counts_non_negative
|
||||
CHECK (follower_count >= 0 AND following_count >= 0 AND track_count >= 0 AND playlist_count >= 0);
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.table_constraints
|
||||
WHERE constraint_schema = 'public'
|
||||
AND table_name = 'user_profiles'
|
||||
AND constraint_name = 'chk_user_profiles_counts_non_negative'
|
||||
) THEN
|
||||
ALTER TABLE public.user_profiles
|
||||
ADD CONSTRAINT chk_user_profiles_counts_non_negative
|
||||
CHECK (follower_count >= 0 AND following_count >= 0 AND track_count >= 0 AND playlist_count >= 0);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
-- Comments
|
||||
COMMENT ON CONSTRAINT chk_tracks_status_valid ON public.tracks IS 'Validates track status values';
|
||||
|
|
@ -124,4 +325,3 @@ COMMENT ON CONSTRAINT chk_hls_transcode_queue_status_valid ON public.hls_transco
|
|||
COMMENT ON CONSTRAINT chk_playlist_versions_action_valid ON public.playlist_versions IS 'Validates playlist version action values';
|
||||
COMMENT ON CONSTRAINT chk_track_history_action_valid ON public.track_history IS 'Validates track history action values';
|
||||
COMMENT ON CONSTRAINT chk_bitrate_adaptation_reason_valid ON public.bitrate_adaptation_logs IS 'Validates bitrate adaptation reason values';
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue