-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link spans to Embrace session by id (#183)
- Loading branch information
1 parent
e1d6bc6
commit 3a12679
Showing
16 changed files
with
343 additions
and
20 deletions.
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
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
75 changes: 75 additions & 0 deletions
75
...Internal/Migration/Migrations/20250220_00_AddSessionIdentifierToSpanRecordMigration.swift
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,75 @@ | ||
// | ||
// Copyright © 2024 Embrace Mobile, Inc. All rights reserved. | ||
// | ||
|
||
import GRDB | ||
|
||
struct AddSessionIdentifierToSpanRecordMigration: Migration { | ||
static var identifier = "AddSessionIdentifierToSpanRecord" // DEV: Must not change | ||
|
||
private static var tempSpansTableName = "spans_temp_2" | ||
|
||
func perform(_ db: GRDB.Database) throws { | ||
|
||
// create copy of `spans` table in `spans_temp` | ||
// include new column 'process_identifier' | ||
try db.create(table: Self.tempSpansTableName) { t in | ||
|
||
t.column(SpanRecord.Schema.id.name, .text).notNull() | ||
t.column(SpanRecord.Schema.traceId.name, .text).notNull() | ||
t.primaryKey([SpanRecord.Schema.traceId.name, SpanRecord.Schema.id.name]) | ||
|
||
t.column(SpanRecord.Schema.name.name, .text).notNull() | ||
t.column(SpanRecord.Schema.type.name, .text).notNull() | ||
t.column(SpanRecord.Schema.startTime.name, .datetime).notNull() | ||
t.column(SpanRecord.Schema.endTime.name, .datetime) | ||
t.column(SpanRecord.Schema.data.name, .blob).notNull() | ||
|
||
t.column(SpanRecord.Schema.processIdentifier.name, .text).notNull() | ||
|
||
// include new column into `spans_temp_2` table | ||
t.column(SpanRecord.Schema.sessionIdentifier.name, .text) | ||
} | ||
|
||
// copy all existing data into temp table | ||
// include default value for `process_identifier` | ||
try db.execute(literal: """ | ||
INSERT INTO 'spans_temp_2' ( | ||
'id', | ||
'trace_id', | ||
'name', | ||
'type', | ||
'start_time', | ||
'end_time', | ||
'data', | ||
'process_identifier' | ||
) SELECT | ||
id, | ||
trace_id, | ||
name, | ||
type, | ||
start_time, | ||
end_time, | ||
data, | ||
process_identifier | ||
FROM 'spans' | ||
""") | ||
|
||
// drop original table | ||
try db.drop(table: SpanRecord.databaseTableName) | ||
|
||
// rename temp table to be original table | ||
try db.rename(table: Self.tempSpansTableName, to: SpanRecord.databaseTableName) | ||
|
||
// Create Trigger on new spans table to prevent endTime from being modified on SpanRecord | ||
try db.execute(sql: | ||
""" | ||
CREATE TRIGGER IF NOT EXISTS prevent_closed_span_modification | ||
BEFORE UPDATE ON \(SpanRecord.databaseTableName) | ||
WHEN OLD.end_time IS NOT NULL | ||
BEGIN | ||
SELECT RAISE(ABORT,'Attempted to modify an already closed span.'); | ||
END; | ||
""" ) | ||
} | ||
} |
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
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
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.