Browse Source

Fix SQL queries for playlists

Toni Fadjukoff 6 years ago
parent
commit
efb10f180f
3 changed files with 8 additions and 5 deletions
  1. 4 3
      db.go
  2. 3 1
      sql/database.sql
  3. 1 1
      web/index.html

+ 4 - 3
db.go View File

209
 		return false, err
209
 		return false, err
210
 	}
210
 	}
211
 	query := `
211
 	query := `
212
-	INSERT INTO public.round_playlist pl
213
-	SELECT r.id, json_to_array($2)
212
+	INSERT INTO public.round_playlist
213
+	SELECT r.id, ARRAY(SELECT e::text FROM json_array_elements($2::json) e)
214
 	FROM public.round r 
214
 	FROM public.round r 
215
 	WHERE r.section = $1
215
 	WHERE r.section = $1
216
-	ON CONFLICT (pl.round_id) DO UPDATE SET tracks = EXCLUDED.tracks`
216
+	ON CONFLICT (round_id) DO UPDATE SET tracks = EXCLUDED.tracks`
217
+
217
 	res, err := db.database.Exec(query, sectionName, tracksJson)
218
 	res, err := db.database.Exec(query, sectionName, tracksJson)
218
 
219
 
219
 	if err != nil {
220
 	if err != nil {

+ 3 - 1
sql/database.sql View File

87
     tracks text[],
87
     tracks text[],
88
     CONSTRAINT round_id FOREIGN KEY (round_id)
88
     CONSTRAINT round_id FOREIGN KEY (round_id)
89
         REFERENCES public.round (id)
89
         REFERENCES public.round (id)
90
-);
90
+);
91
+ALTER TABLE public.round_playlist 
92
+ADD CONSTRAINT round_id_unique UNIQUE(round_id);

+ 1 - 1
web/index.html View File

71
             <input type="password" name="password" class="form-control" placeholder="Password" required>
71
             <input type="password" name="password" class="form-control" placeholder="Password" required>
72
             <div class="checkbox">
72
             <div class="checkbox">
73
                 <label>
73
                 <label>
74
-                    <input type="checkbox" name="remember-me" value="remember-me"> Remember me
74
+                    <input type="checkbox" name="remember-me" value="remember-me" checked> Remember me
75
                 </label>
75
                 </label>
76
             </div>
76
             </div>
77
             <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
77
             <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>