Ensure proper database initialization and new user registration.

Commit
c02ab01b2ff7c12d89b1d9110b8dee607d26d395
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
src/MyFitnessTracker/MFTSQLite3Database.class.st
index 5b129ec7..b285ce29 100644..100644
@@ -8,7 +8,7 @@
8 8 }
9 9
10 10 { #category : #'as yet unclassified' }
11 Removed: MFTSQLite3Database class >> dateTimeNow [
11 Added: MFTSQLite3Database class >> dateAndTimeNow [
12 12
13 13 ^ DateAndTime now asUTC rounded
14 14 ]
@@ -38,33 +38,39 @@
38 38 open;
39 39 execute: 'CREATE TABLE IF NOT EXISTS "prospects" (
40 40 "id" INTEGER,
41 Removed: "email" TEXT NOT NULL,
42 Removed: "date_time" TEXT NOT NULL,
41 Added: "email" TEXT NOT NULL,
42 Added: "date_time" TEXT NOT NULL,
43 43 PRIMARY KEY("id" AUTOINCREMENT)
44 44 )';
45 45 execute: 'CREATE TABLE IF NOT EXISTS "users" (
46 46 "id" INTEGER UNIQUE,
47 47 "username" TEXT NOT NULL,
48 Removed: "password_hash" BLOB NOT NULL,
49 Removed: "real_first_name" TEXT,
50 Removed: "real_last_name" TEXT,
51 Removed: "date_of_birth" TEXT,
48 Added: "password_hash" BLOB NOT NULL,
49 Added: "real_first_name" TEXT,
50 Added: "real_last_name" TEXT,
51 Added: "date_of_birth" TEXT,
52 52 PRIMARY KEY("id" AUTOINCREMENT)
53 53 )';
54 54 execute: 'CREATE TABLE IF NOT EXISTS "workouts" (
55 55 "id" INTEGER UNIQUE,
56 Removed: "username" TEXT NOT NULL,
57 Removed: "password_hash" BLOB NOT NULL,
58 Removed: "real_first_name" TEXT,
59 Removed: "real_last_name" TEXT,
60 Removed: "date_of_birth" TEXT,
56 Added: "user_id" INTEGER NOT NULL,
57 Added: "date" TEXT NOT NULL,
58 Added: "primary_muscle" TEXT,
59 Added: "secondary_muscles" TEXT,
61 60 PRIMARY KEY("id" AUTOINCREMENT)
62 61 )';
62 Added: execute: 'CREATE TABLE IF NOT EXISTS "exercises" (
63 Added: "id" INTEGER NOT NULL UNIQUE,
64 Added: "workout_id" INTEGER NOT NULL,
65 Added: "english_name" TEXT NOT NULL,
66 Added: "sets" TEXT,
67 Added: PRIMARY KEY("id" AUTOINCREMENT)
68 Added: )';
63 69 execute: 'CREATE TABLE IF NOT EXISTS "weights" (
64 70 "id" INTEGER UNIQUE,
65 71 "user_id" INTEGER NOT NULL,
66 Removed: "date" TEXT NOT NULL,
67 Removed: "value" NUMERIC NOT NULL,
72 Added: "date" TEXT NOT NULL,
73 Added: "value" NUMERIC NOT NULL,
68 74 PRIMARY KEY("id" AUTOINCREMENT)
69 75 )';
70 76 close
@@ -84,61 +90,37 @@
84 90 ]
85 91
86 92 { #category : #'class initialization' }
87 Removed: MFTSQLite3Database class >> populateDefaultWeights [
93 Added: MFTSQLite3Database class >> populatePlaceholderWeights [
88 94
89 Removed: self defaultConnection
90 Removed: open;
91 Removed: execute: 'INSERT INTO weights(user_id, date, value)
95 Added: | connection |
96 Added: connection := self defaultConnection open.
97 Added: MFTWeight placeholderCollection do: [ :weight |
98 Added: connection
99 Added: execute: 'INSERT INTO weights(user_id, date, value)
92 100 VALUES( ?, ?, ?)'
93 Removed: with: {
94 Removed: 7.
95 Removed: DateAndTime yesterday asUTC rounded.
96 Removed: 90.5 };
97 Removed: execute: 'INSERT INTO weights(user_id, date, value)
98 Removed: VALUES( ?, ?, ?)'
99 Removed: with: {
100 Removed: 7.
101 Removed: DateAndTime today asUTC rounded.
102 Removed: 101.3 };
103 Removed: execute: 'INSERT INTO weights(user_id, date, value)
104 Removed: VALUES( ?, ?, ?)'
105 Removed: with: {
106 Removed: 7.
107 Removed: DateAndTime now asUTC rounded.
108 Removed: 90.5 };
109 Removed: close
101 Added: with: {
102 Added: 1.
103 Added: weight date.
104 Added: weight value } ].
105 Added: connection close
110 106 ]
111 107
112 108 { #category : #'class initialization' }
113 Removed: MFTSQLite3Database class >> populateDefaultWorkouts [
109 Added: MFTSQLite3Database class >> populatePlaceholderWorkouts [
114 110
115 Removed: self defaultConnection
116 Removed: open;
117 Removed: execute:
118 Removed: 'INSERT INTO workouts(user_id, date, primary_muscle, secondary_muscles)
111 Added: | connection |
112 Added: connection := self defaultConnection open.
113 Added: MFTWorkout placeholderCollection do: [ :workout |
114 Added: connection
115 Added: execute:
116 Added: 'INSERT INTO workouts(user_id, date, primary_muscle, secondary_muscles)
119 117 VALUES( ?, ?, ?, ?)'
120 Removed: with: {
121 Removed: 7.
122 Removed: DateAndTime yesterday asUTC rounded.
123 Removed: MFTMuscle quadricepsFemoris latinName.
124 Removed: MFTMuscle hamstring englishName };
125 Removed: execute:
126 Removed: 'INSERT INTO workouts(user_id, date, primary_muscle, secondary_muscles)
127 Removed: VALUES( ?, ?, ?, ?)'
128 Removed: with: {
129 Removed: 7.
130 Removed: self dateTimeNow.
131 Removed: MFTMuscle latissimusDorsi latinName.
132 Removed: MFTMuscle erectorSpinae latinName };
133 Removed: execute:
134 Removed: 'INSERT INTO workouts(user_id, date, primary_muscle, secondary_muscles)
135 Removed: VALUES( ?, ?, ?, ?)'
136 Removed: with: {
137 Removed: 7.
138 Removed: self dateTimeNow.
139 Removed: MFTMuscle trapezius latinName.
140 Removed: MFTMuscle brachioRadialis latinName };
141 Removed: close
118 Added: with: {
119 Added: 1.
120 Added: workout date.
121 Added: workout primaryMuscle.
122 Added: workout secondaryMuscles } ].
123 Added: connection close
142 124 ]
143 125
144 126 { #category : #'as yet unclassified' }
@@ -148,7 +130,7 @@
148 130 self defaultConnection
149 131 open;
150 132 execute:
151 Removed: 'INSERT INTO users(username,password_hash,account_creation_date_time) VALUES (?, ?, ?);'
133 Added: 'INSERT INTO users(username,password_hash,account_register_date_time) VALUES (?, ?, ?);'
152 134 with: {
153 135 aMFTUser username.
154 136 aMFTUser passwordHash.