Ensure SQLite3 database is correctly created during class initialization.

Commit
17de902b479f417b39b7907a5da1f02bab0401ff
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
src/MyFitnessTracker/MFTSQLite3Database.class.st
index 0aa8ab58..1d542afd 100644..100644
@@ -34,6 +34,19 @@
34 34 ^ allMuscles
35 35 ]
36 36
37 Added: { #category : 'accessing' }
38 Added: MFTSQLite3Database class >> createDefaultDatabaseAt: aLocation [
39 Added:
40 Added: | schema command returnCode |
41 Added: schema := ((IceRepository repositoryNamed: 'my-fitness-tracker')
42 Added: location absolutePath / 'mft-schema.sql') pathString.
43 Added: command := 'sqlite3 ' , aLocation , ' < ' , schema.
44 Added: returnCode := LibC runCommand: command.
45 Added: returnCode ~= 0 ifTrue: [
46 Added: self error:
47 Added: 'Non-zero return code when attempting to create the MFT database.' ]
48 Added: ]
49 Added:
37 50 { #category : 'as yet unclassified' }
38 51 MFTSQLite3Database class >> defaultConnection [
39 52
@@ -181,15 +194,7 @@
181 194 defaultLocation := (Smalltalk imageDirectory / 'mft.sqlite3')
182 195 fullName.
183 196 (FileSystem / defaultLocation) exists ifFalse: [
184 Removed: | schema returnCode |
185 Removed: schema := (Smalltalk imageDirectory
186 Removed: / 'pharo-local/iceberg/my-fitness-tracker/mft-schema.sql')
187 Removed: fullName.
188 Removed: returnCode := LibC runCommand:
189 Removed: 'sqlite3 ' , defaultLocation , ' < ' , schema.
190 Removed: returnCode ~= 0 ifTrue: [
191 Removed: self error:
192 Removed: 'Non-zero return code when attempting to create the MFT database.' ] ].
197 Added: self createDefaultDatabaseAt: defaultLocation ].
193 198 allMuscles := self getAllMuscles.
194 199 allMuscleGroups := self getAllMuscleGroups.
195 200 allExercises := self getAllExercises.