UI verbessert, 2. PDF als kompakte Variante
This commit is contained in:
1 parent
1bf3283029
commit
f9e3e94629
23 files changed
+1009
-146
No files matched your search
@@ -10,7 +10,11 @@ public final class AppDatabase {
|
||||
self.path = path
|
||||
self.database = try SQLiteDatabase(path: path)
|
||||
try migrate()
|
||||
if seedDemo, try churchCount() == 0 {
|
||||
// Only seed on a genuinely fresh install. After the user explicitly
|
||||
// deletes all data we persist a marker so demo data does not reappear.
|
||||
if seedDemo,
|
||||
try churchCount() == 0,
|
||||
setting("suppressDemoSeed") != "1" {
|
||||
try DemoData.seed(into: self)
|
||||
}
|
||||
}
|
||||
@@ -91,6 +95,7 @@ public final class AppDatabase {
|
||||
CREATE TABLE IF NOT EXISTS services (
|
||||
id TEXT PRIMARY KEY,
|
||||
church_id TEXT NOT NULL REFERENCES churches(id) ON DELETE CASCADE,
|
||||
location TEXT NOT NULL DEFAULT '',
|
||||
template_id TEXT REFERENCES service_templates(id) ON DELETE SET NULL,
|
||||
date TEXT NOT NULL,
|
||||
time_minutes INTEGER NOT NULL,
|
||||
@@ -142,7 +147,19 @@ public final class AppDatabase {
|
||||
);
|
||||
"""
|
||||
try database.execute(schema)
|
||||
try database.run("INSERT OR IGNORE INTO settings(key, value) VALUES('schemaVersion', '1')")
|
||||
// Older databases predate the free-text location for special services.
|
||||
try addColumnIfMissing(
|
||||
table: "services",
|
||||
column: "location",
|
||||
definition: "TEXT NOT NULL DEFAULT ''"
|
||||
)
|
||||
try database.run("INSERT OR REPLACE INTO settings(key, value) VALUES('schemaVersion', '2')")
|
||||
}
|
||||
|
||||
private func addColumnIfMissing(table: String, column: String, definition: String) throws {
|
||||
let columns = try database.query("PRAGMA table_info(\(table))")
|
||||
guard !columns.contains(where: { $0.string("name") == column }) else { return }
|
||||
try database.execute("ALTER TABLE \(table) ADD COLUMN \(column) \(definition);")
|
||||
}
|
||||
|
||||
// MARK: - Churches
|
||||
@@ -375,15 +392,17 @@ public final class AppDatabase {
|
||||
|
||||
public func upsert(_ service: ServiceOccurrence) throws {
|
||||
try database.run("""
|
||||
INSERT INTO services(id, church_id, template_id, date, time_minutes, title, lectors_needed,
|
||||
INSERT INTO services(id, church_id, location, template_id, date, time_minutes, title, lectors_needed,
|
||||
helpers_needed, kind, notes, locked, created_at)
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET church_id=excluded.church_id, template_id=excluded.template_id,
|
||||
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET church_id=excluded.church_id, location=excluded.location,
|
||||
template_id=excluded.template_id,
|
||||
date=excluded.date, time_minutes=excluded.time_minutes, title=excluded.title,
|
||||
lectors_needed=excluded.lectors_needed, helpers_needed=excluded.helpers_needed,
|
||||
kind=excluded.kind, notes=excluded.notes, locked=excluded.locked
|
||||
""", [
|
||||
.text(service.id), .text(service.churchID), service.templateID.map(SQLiteValue.text) ?? .null,
|
||||
.text(service.id), .text(service.churchID), .text(service.location ?? ""),
|
||||
service.templateID.map(SQLiteValue.text) ?? .null,
|
||||
.dateKey(service.date), .int(service.timeMinutes), .text(service.title),
|
||||
.int(service.lectorsNeeded), .int(service.helpersNeeded), .text(service.kind.rawValue),
|
||||
.text(service.notes), .bool(service.locked), .text(ISO8601DateFormatter().string(from: service.createdAt))
|
||||
@@ -401,6 +420,7 @@ public final class AppDatabase {
|
||||
return ServiceOccurrence(
|
||||
id: id,
|
||||
churchID: churchID,
|
||||
location: row.string("location", default: ""),
|
||||
templateID: row.string("template_id"),
|
||||
date: date,
|
||||
timeMinutes: row.int("time_minutes", default: 600),
|
||||
@@ -739,12 +759,25 @@ public final class AppDatabase {
|
||||
return value
|
||||
}
|
||||
|
||||
/// Removes all content while keeping application settings (range, preferences).
|
||||
/// By default a marker is stored so the demo dataset is not re-seeded on the
|
||||
/// next launch; resetting the demo clears that marker again.
|
||||
public func deleteAllData(markDemoSuppressed: Bool = true) throws {
|
||||
try database.transaction {
|
||||
try database.execute("""
|
||||
DELETE FROM assignments; DELETE FROM services; DELETE FROM service_exceptions;
|
||||
DELETE FROM service_templates; DELETE FROM absences; DELETE FROM people;
|
||||
DELETE FROM churches; DELETE FROM liturgical_days;
|
||||
""")
|
||||
if markDemoSuppressed {
|
||||
try database.run("INSERT OR REPLACE INTO settings(key, value) VALUES('suppressDemoSeed', '1')")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public func resetDemoData() throws {
|
||||
try database.execute("""
|
||||
DELETE FROM assignments; DELETE FROM services; DELETE FROM service_exceptions;
|
||||
DELETE FROM service_templates; DELETE FROM absences; DELETE FROM people;
|
||||
DELETE FROM churches; DELETE FROM liturgical_days;
|
||||
""")
|
||||
try deleteAllData(markDemoSuppressed: false)
|
||||
try database.run("DELETE FROM settings WHERE key='suppressDemoSeed'")
|
||||
try DemoData.seed(into: self)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user