Compare commits

...

3 Commits

Author SHA1 Message Date
Brandon Presley 93c5e26882 Set versionCode=36074 2022-10-29 16:44:10 +13:00
Brandon Presley 057c664366 Fix lint issues 2022-10-29 16:42:51 +13:00
Brandon Presley 88c1c629d5 Add days, plansDays, days tables
This is for the purpose of adding the following relationships:
- Plans <-> Sets
- Plans <-> Days

Related to #102
2022-10-29 16:39:27 +13:00
7 changed files with 98 additions and 9 deletions

View File

@ -47,7 +47,7 @@ export default function StartPlan() {
setCounts(newCounts);
console.log(`${StartPlan.name}.focus:`, {newCounts});
});
}, [params]),
}, [workouts]),
);
const handleSubmit = async () => {
@ -101,7 +101,7 @@ export default function StartPlan() {
setUnit(newBest.unit);
setBest(newBest);
},
[name, workouts],
[name, counts],
);
return (

View File

@ -43,8 +43,8 @@ android {
missingDimensionStrategy "RNNotifications.reactNativeVersion", "reactNative60"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 36073
versionName "1.47"
versionCode 36074
versionName "1.48"
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
if (isNewArchitectureEnabled()) {

54
db.ts
View File

@ -3,10 +3,12 @@ import {
openDatabase,
SQLiteDatabase,
} from 'react-native-sqlite-storage';
import {addPlanDays, addPlanSets, getPlans} from './plan.service';
import {DAYS} from './time';
enablePromise(true);
const migrations = [
const migrations: (string | Function)[] = [
`
CREATE TABLE IF NOT EXISTS sets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -123,12 +125,56 @@ const migrations = [
`
ALTER TABLE settings ADD COLUMN noSound BOOLEAN DEFAULT false
`,
`
CREATE TABLE days(
id INTEGER PRIMARY KEY,
name TEXT NOT NULL
)
`,
`
INSERT INTO days(name, id) VALUES
('Sunday', 0),
('Monday', 1),
('Tuesday', 2),
('Wednesday', 3),
('Thursday', 4),
('Friday', 5),
('Saturday', 6)
`,
`
CREATE TABLE plansDays(
planId INTEGER,
dayId INTEGER,
FOREIGN KEY(planId) REFERENCES plans(id)
FOREIGN KEY(dayId) REFERENCES days(id)
)
`,
`
CREATE TABLE plansSets(
setName TEXT,
planId INTEGER,
FOREIGN KEY(planId) REFERENCES plans(id)
FOREIGN KEY(setName) REFERENCES sets(name)
)
`,
async () => {
const plans = await getPlans('');
for (const plan of plans) {
const dayIds = plan.days.split(',').map(day => DAYS.indexOf(day));
await addPlanDays(plan.id, dayIds);
const setNames = plan.workouts.split(',');
await addPlanSets(plan.id, setNames);
}
},
];
export let db: SQLiteDatabase;
export const runMigrations = async () => {
db = await openDatabase({name: 'massive.db'});
await db.executeSql('DROP TABLE migrations');
await db.executeSql('DROP TABLE plansSets');
await db.executeSql('DROP TABLE plansDays');
await db.executeSql(`
CREATE TABLE IF NOT EXISTS migrations(
id INTEGER PRIMARY KEY AUTOINCREMENT,
@ -138,11 +184,13 @@ export const runMigrations = async () => {
const [result] = await db.executeSql(`SELECT * FROM migrations`);
const missing = migrations.slice(result.rows.length);
for (const command of missing) {
await db.executeSql(command).catch(console.error);
if (typeof command === 'string')
await db.executeSql(command).catch(console.error);
else await command(db);
const insert = `
INSERT INTO migrations (command)
VALUES (?)
`;
await db.executeSql(insert, [command]);
await db.executeSql(insert, [command.toString()]);
}
};

View File

@ -1,6 +1,6 @@
{
"name": "massive",
"version": "1.47",
"version": "1.48",
"private": true,
"license": "GPL-3.0-only",
"scripts": {
@ -22,6 +22,7 @@
"@types/react-native-svg-charts": "^5.0.12",
"@types/react-native-vector-icons": "^6.4.12",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint-plugin-flowtype": "^8.0.3",
"react": "^18.2.0",
"react-native": "^0.70.4",
"react-native-document-picker": "^8.1.2",

View File

@ -2,6 +2,24 @@ import {db} from './db';
import {Plan} from './plan';
import {DAYS} from './time';
export const addPlanSets = async (planId: number, setNames: string[]) => {
const values = setNames.map(setName => `(${planId}, '${setName}')`).join(',');
const insert = `
INSERT INTO plansSets(planId, setName)
VALUES ${values}
`;
return db.executeSql(insert);
};
export const addPlanDays = async (planId: number, dayIds: number[]) => {
const values = dayIds.map(dayId => `(${planId}, ${dayId})`).join(',');
const insert = `
INSERT INTO plansDays(planId, dayId)
VALUES ${values}
`;
return db.executeSql(insert);
};
export const getPlans = async (search: string): Promise<Plan[]> => {
const select = `
SELECT * from plans

View File

@ -1,5 +1,5 @@
export interface Plan {
id?: number;
id: number;
days: string;
workouts: string;
}

View File

@ -4556,6 +4556,20 @@ __metadata:
languageName: node
linkType: hard
"eslint-plugin-flowtype@npm:^8.0.3":
version: 8.0.3
resolution: "eslint-plugin-flowtype@npm:8.0.3"
dependencies:
lodash: ^4.17.21
string-natural-compare: ^3.0.1
peerDependencies:
"@babel/plugin-syntax-flow": ^7.14.5
"@babel/plugin-transform-react-jsx": ^7.14.9
eslint: ^8.1.0
checksum: 30e63c5357b0b5571f39afed51e59c140084f4aa53c106b1fd04f26da42b268908466daa6020b92943e71409bdaee1c67202515ed9012404d027cc92cb03cefa
languageName: node
linkType: hard
"eslint-plugin-jest@npm:22.4.1":
version: 22.4.1
resolution: "eslint-plugin-jest@npm:22.4.1"
@ -6483,6 +6497,7 @@ __metadata:
"@typescript-eslint/parser": ^5.29.0
babel-plugin-transform-remove-console: ^6.9.4
eslint: ^8.26.0
eslint-plugin-flowtype: ^8.0.3
metro-react-native-babel-preset: ^0.73.3
react: ^18.2.0
react-native: ^0.70.4
@ -8959,6 +8974,13 @@ __metadata:
languageName: node
linkType: hard
"string-natural-compare@npm:^3.0.1":
version: 3.0.1
resolution: "string-natural-compare@npm:3.0.1"
checksum: 65910d9995074086e769a68728395effbba9b7186be5b4c16a7fad4f4ef50cae95ca16e3e9086e019cbb636ae8daac9c7b8fe91b5f21865c5c0f26e3c0725406
languageName: node
linkType: hard
"string-width@npm:^1.0.2 || 2 || 3 || 4, string-width@npm:^4.1.0, string-width@npm:^4.2.0, string-width@npm:^4.2.3":
version: 4.2.3
resolution: "string-width@npm:4.2.3"