Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions Examples/Examples.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
DCA44CFB2D5D9D21008D4E76 /* Exceptions for "SyncUps" folder in "SyncUps" target */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Info.plist,
README.md,
);
target = DCBE89CB2D483FB90071F499 /* SyncUps */;
Expand Down Expand Up @@ -884,11 +885,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = SyncUps/SyncUps.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"SyncUps/Preview Content\"";
DEVELOPMENT_TEAM = VFRXY8HC3H;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SyncUps/Info.plist;
INFOPLIST_KEY_NSSpeechRecognitionUsageDescription = "To transcribe meeting notes.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -900,7 +904,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.SyncUps;
PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.SQLiteData.SyncUps;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
TARGETED_DEVICE_FAMILY = "1,2";
Expand All @@ -912,11 +916,14 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = SyncUps/SyncUps.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"SyncUps/Preview Content\"";
DEVELOPMENT_TEAM = VFRXY8HC3H;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = SyncUps/Info.plist;
INFOPLIST_KEY_NSSpeechRecognitionUsageDescription = "To transcribe meeting notes.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
Expand All @@ -928,7 +935,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.SyncUps;
PRODUCT_BUNDLE_IDENTIFIER = co.pointfree.SQLiteData.SyncUps;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -1006,7 +1013,7 @@
/* Begin XCLocalSwiftPackageReference section */
DCD9AC892E02176700FB20F8 /* XCLocalSwiftPackageReference ".." */ = {
isa = XCLocalSwiftPackageReference;
relativePath = "..";
relativePath = ..;
};
/* End XCLocalSwiftPackageReference section */

Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion Examples/SyncUpTests/Internal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import SQLiteData
@testable import SyncUps

extension Database {
func seedSyncUpFormTests() throws {
func seed() throws {
try seed {
SyncUp(id: UUID(1), seconds: 60, theme: .appOrange, title: "Design")
SyncUp(id: UUID(2), seconds: 60 * 10, theme: .periwinkle, title: "Engineering")
Expand Down
6 changes: 4 additions & 2 deletions Examples/SyncUpTests/SyncUpFormTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import Testing

@Suite(
.dependencies {
$0.defaultDatabase = try! SyncUps.appDatabase()
try! $0.defaultDatabase.write { try $0.seedSyncUpFormTests() }
try $0.bootstrapDatabase()
try $0.defaultDatabase.write { db in
try db.seed()
}
$0.uuid = .incrementing
}
)
Expand Down
4 changes: 1 addition & 3 deletions Examples/SyncUps/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ struct AppView: View {
}

#Preview("Happy path") {
let _ = try! prepareDependencies {
$0.defaultDatabase = try SyncUps.appDatabase()
}
let _ = try! prepareDependencies { try $0.bootstrapDatabase() }
AppView(model: AppModel())
}
10 changes: 10 additions & 0 deletions Examples/SyncUps/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
</dict>
</plist>
121 changes: 62 additions & 59 deletions Examples/SyncUps/Schema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,73 +75,76 @@ extension Int {
}
}

func appDatabase() throws -> any DatabaseWriter {
@Dependency(\.context) var context
var configuration = Configuration()
configuration.foreignKeysEnabled = true
configuration.prepareDatabase { db in
#if DEBUG
db.trace(options: .profile) {
if context == .preview {
print("\($0.expandedDescription)")
} else {
logger.debug("\($0.expandedDescription)")
extension DependencyValues {
mutating func bootstrapDatabase() throws {
@Dependency(\.context) var context
var configuration = Configuration()
configuration.foreignKeysEnabled = true
configuration.prepareDatabase { db in
#if DEBUG
db.trace(options: .profile) {
if context == .preview {
print("\($0.expandedDescription)")
} else {
logger.debug("\($0.expandedDescription)")
}
}
}
#endif
}
let database = try SQLiteData.defaultDatabase(configuration: configuration)
logger.debug(
"""
App database:
open "\(database.path)"
"""
)
var migrator = DatabaseMigrator()
#if DEBUG
migrator.eraseDatabaseOnSchemaChange = true
#endif
migrator.registerMigration("Create initial tables") { db in
try #sql(
#endif
}
let database = try SQLiteData.defaultDatabase(configuration: configuration)
logger.debug(
"""
CREATE TABLE "syncUps" (
"id" TEXT PRIMARY KEY NOT NULL ON CONFLICT REPLACE DEFAULT (uuid()),
"seconds" INTEGER NOT NULL DEFAULT 300,
"theme" TEXT NOT NULL DEFAULT \(raw: Theme.bubblegum.rawValue),
"title" TEXT NOT NULL
)
App database:
open "\(database.path)"
"""
)
.execute(db)
try #sql(
"""
CREATE TABLE "attendees" (
"id" TEXT PRIMARY KEY NOT NULL ON CONFLICT REPLACE DEFAULT (uuid()),
"name" TEXT NOT NULL,
"syncUpID" INTEGER NOT NULL,

FOREIGN KEY("syncUpID") REFERENCES "syncUps"("id") ON DELETE CASCADE
var migrator = DatabaseMigrator()
#if DEBUG
migrator.eraseDatabaseOnSchemaChange = true
#endif
migrator.registerMigration("Create initial tables") { db in
try #sql(
"""
CREATE TABLE "syncUps" (
"id" TEXT PRIMARY KEY NOT NULL ON CONFLICT REPLACE DEFAULT (uuid()),
"seconds" INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT 300,
"theme" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT \(raw: Theme.bubblegum.rawValue),
"title" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT ''
) STRICT
"""
)
"""
)
.execute(db)
try #sql(
"""
CREATE TABLE "meetings" (
"id" TEXT PRIMARY KEY NOT NULL ON CONFLICT REPLACE DEFAULT (uuid()),
"date" TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP UNIQUE,
"syncUpID" INTEGER NOT NULL,
"transcript" TEXT NOT NULL,

FOREIGN KEY("syncUpID") REFERENCES "syncUps"("id") ON DELETE CASCADE
.execute(db)
try #sql(
"""
CREATE TABLE "attendees" (
"id" TEXT PRIMARY KEY NOT NULL ON CONFLICT REPLACE DEFAULT (uuid()),
"name" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT '',
"syncUpID" TEXT NOT NULL REFERENCES "syncUps"("id") ON DELETE CASCADE
) STRICT
"""
)
"""
.execute(db)
try #sql(
"""
CREATE TABLE "meetings" (
"id" TEXT PRIMARY KEY NOT NULL ON CONFLICT REPLACE DEFAULT (uuid()),
"date" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT CURRENT_TIMESTAMP,
"syncUpID" TEXT NOT NULL REFERENCES "syncUps"("id") ON DELETE CASCADE,
"transcript" TEXT NOT NULL ON CONFLICT REPLACE DEFAULT ''
) STRICT
"""
)
.execute(db)
}
try migrator.migrate(database)
defaultDatabase = database
defaultSyncEngine = try SyncEngine(
for: database,
tables: SyncUp.self,
Attendee.self,
Meeting.self
)
.execute(db)
}

try migrator.migrate(database)
return database
}

private let logger = Logger(subsystem: "SyncUps", category: "Database")
Expand Down
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUpDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ struct MeetingView: View {

#Preview {
let syncUp = try! prepareDependencies {
$0.defaultDatabase = try SyncUps.appDatabase()
try $0.bootstrapDatabase()
return try $0.defaultDatabase.read { db in
try SyncUp.limit(1).fetchOne(db)!
}
Expand Down
16 changes: 16 additions & 0 deletions Examples/SyncUps/SyncUps.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
<key>com.apple.developer.icloud-container-identifiers</key>
<array>
<string>iCloud.co.pointfree.SQLiteData.SyncUps</string>
</array>
<key>com.apple.developer.icloud-services</key>
<array>
<string>CloudKit</string>
</array>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUpsApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct SyncUpsApp: App {
init() {
if !isTesting {
try! prepareDependencies {
$0.defaultDatabase = try SyncUps.appDatabase()
try $0.bootstrapDatabase()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUpsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private struct SeedDatabaseTip: Tip {

#Preview {
let _ = try! prepareDependencies {
$0.defaultDatabase = try SyncUps.appDatabase()
try $0.bootstrapDatabase()
}
NavigationStack {
SyncUpsList(model: SyncUpsListModel())
Expand Down