Make sure workouts table has all names from sets

This commit is contained in:
Brandon Presley 2022-09-18 18:30:06 +12:00
parent eddad49719
commit 562ee4f43e
1 changed files with 5 additions and 0 deletions

5
db.ts
View File

@ -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);
};