From 562ee4f43e953dd93a5f4b0e9fd6401a23c75663 Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sun, 18 Sep 2022 18:30:06 +1200 Subject: [PATCH] Make sure workouts table has all names from sets --- db.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db.ts b/db.ts index 67e488d..27a9b9a 100644 --- a/db.ts +++ b/db.ts @@ -75,6 +75,10 @@ const addSteps = ` ALTER TABLE workouts ADD COLUMN steps TEXT NULL; `; +const insertWorkouts = ` + INSERT INTO workouts (name) SELECT DISTINCT name FROM sets; +`; + export let db: SQLiteDatabase; export const migrations = async () => { @@ -89,6 +93,7 @@ export const migrations = async () => { await db.executeSql(addImage).catch(() => null); await db.executeSql(addImages).catch(() => null); await db.executeSql(addSteps).catch(() => null); + await db.executeSql(insertWorkouts).catch(() => null); const [result] = await db.executeSql(selectSettings); if (result.rows.length === 0) await db.executeSql(insertSettings); };