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,11 +209,12 @@ func (db *DB) UpdatePlaylistBySection(sectionName string, tracks []string) (bool
209 209
 		return false, err
210 210
 	}
211 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 214
 	FROM public.round r 
215 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 218
 	res, err := db.database.Exec(query, sectionName, tracksJson)
218 219
 
219 220
 	if err != nil {

+ 3 - 1
sql/database.sql View File

@@ -87,4 +87,6 @@ CREATE TABLE public.round_playlist
87 87
     tracks text[],
88 88
     CONSTRAINT round_id FOREIGN KEY (round_id)
89 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,7 +71,7 @@
71 71
             <input type="password" name="password" class="form-control" placeholder="Password" required>
72 72
             <div class="checkbox">
73 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 75
                 </label>
76 76
             </div>
77 77
             <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>