This repository has been archived by the owner on Aug 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Log key activities in SQLite #1067
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
34661f2
Create activity table
bfollington bbdab43
Working examples of various activity logs
bfollington 79f59bc
Rework naming and remove hardcoded names
bfollington 2c8e578
Update naming convention
bfollington dd25df1
Do not log sync failures
bfollington 1ee52c6
Refactoring
bfollington 07b7574
Exercise app migrations in tests
bfollington 8d18a87
Implement deserialization and testing for ActivityEvents
bfollington 8c3167c
Ensure records are saved in order
bfollington a8fef4e
Remove async element of test
bfollington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// ActivityEvent.swift | ||
// Subconscious (iOS) | ||
// | ||
// Created by Ben Follington on 10/1/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct ActivityEvent<Metadata: Codable>: Codable { | ||
let category: ActivityEventCategory | ||
let event: String | ||
let message: String | ||
let metadata: Metadata? | ||
} | ||
|
||
enum ActivityEventCategory: String, Codable { | ||
case system = "system" | ||
case deck = "deck" | ||
case note = "note" | ||
case addressBook = "addressBook" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1338,7 +1338,8 @@ final class DatabaseService { | |
|
||
let dids = [ | ||
Did.local.description, | ||
owner.description] | ||
owner.description | ||
] | ||
|
||
return try? database.execute( | ||
sql: """ | ||
|
@@ -1371,9 +1372,27 @@ final class DatabaseService { | |
}) | ||
.first | ||
} | ||
|
||
func writeActivity<Data: Codable>(event: ActivityEvent<Data>) throws { | ||
guard self.state == .ready else { | ||
return | ||
} | ||
|
||
try database.execute( | ||
sql: """ | ||
INSERT INTO activity (category, event, message, metadata) | ||
VALUES (?, ?, ?, ?) | ||
""", | ||
parameters: [ | ||
.text(event.category.rawValue), | ||
.text(event.event), | ||
.text(event.message), | ||
.json(event.metadata, or: "{}") | ||
] | ||
) | ||
} | ||
} | ||
|
||
|
||
// MARK: Migrations | ||
extension Config { | ||
static let migrations = Migrations([ | ||
|
@@ -1555,6 +1574,21 @@ extension Config { | |
); | ||
END; | ||
""" | ||
), | ||
SQLMigration( | ||
version: Int.from(iso8601String: "2024-01-10T11:59:00")!, | ||
sql: """ | ||
/* Tracks `ActivityEvent`s in a queryable stream */ | ||
CREATE TABLE activity | ||
( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
category TEXT NOT NULL, | ||
event TEXT NOT NULL, | ||
message TEXT DEFAULT '' NOT NULL, | ||
metadata TEXT DEFAULT '{}' NOT NULL, | ||
created TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL | ||
); | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to also add a test for these migrations using a fresh in-memory SQL DB? This is a question. I don't recall if I put together the code to make that work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
) | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test for this method using in-memory SQL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep 👍