From 267e1ea5a6620ed9237b3d5356f007810de611d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Rou=C3=A9?= Date: Fri, 3 Oct 2025 09:32:10 +0200 Subject: [PATCH 01/22] Add failing test for merged migration that merges itself --- Tests/GRDBTests/DatabaseMigratorTests.swift | 116 ++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/Tests/GRDBTests/DatabaseMigratorTests.swift b/Tests/GRDBTests/DatabaseMigratorTests.swift index 1d94465c5..da0922508 100644 --- a/Tests/GRDBTests/DatabaseMigratorTests.swift +++ b/Tests/GRDBTests/DatabaseMigratorTests.swift @@ -1282,6 +1282,122 @@ class DatabaseMigratorTests : GRDBTestCase { } } + func test_merged_migrations_named_like_the_last_that_includes_itself_in_the_list_of_merged_migrations() throws { + // Original migrator + var oldMigrator = DatabaseMigrator() + oldMigrator.registerMigration("v1") { db in + try db.execute(sql: "CREATE TABLE t1(a)") + } + oldMigrator.registerMigration("v2") { db in + try db.execute(sql: "CREATE TABLE t2(a)") + } + oldMigrator.registerMigration("v3") { db in + try db.execute(sql: "CREATE TABLE t3(a)") + } + oldMigrator.registerMigration("v4") { db in + try db.execute(sql: "CREATE TABLE t4(a)") + } + oldMigrator.registerMigration("v5") { db in + try db.execute(sql: "CREATE TABLE t5(a)") + } + + // New migrator merges v2, v3, and v4 into v4 + var newMigrator = DatabaseMigrator() + newMigrator.registerMigration("v1") { db in + try db.execute(sql: "CREATE TABLE t1(a)") + } + // SUT: the migration identifier is included in the list of merged identifiers. + newMigrator.registerMigration("v4", merging: ["v2", "v3", "v4"]) { db, appliedIDs in + if !appliedIDs.contains("v2") { + try db.execute(sql: "CREATE TABLE t2(a)") + } + if !appliedIDs.contains("v3") { + try db.execute(sql: "CREATE TABLE t3(a)") + } + try db.execute(sql: "CREATE TABLE t4(a)") + } + newMigrator.registerMigration("v5") { db in + try db.execute(sql: "CREATE TABLE t5(a)") + } + + do { + let dbQueue = try makeDatabaseQueue() + + try newMigrator.migrate(dbQueue) + try dbQueue.read { db in + try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"]) + try XCTAssertTrue(String + .fetchSet(db, sql: "SELECT name FROM sqlite_master") + .isSuperset(of: ["t1", "t2", "t3", "t4", "t5"])) + } + } + + do { + let dbQueue = try makeDatabaseQueue() + try oldMigrator.migrate(dbQueue, upTo: "v1") + + try newMigrator.migrate(dbQueue) + try dbQueue.read { db in + try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"]) + try XCTAssertTrue(String + .fetchSet(db, sql: "SELECT name FROM sqlite_master") + .isSuperset(of: ["t1", "t2", "t3", "t4", "t5"])) + } + } + + do { + let dbQueue = try makeDatabaseQueue() + try oldMigrator.migrate(dbQueue, upTo: "v2") + + try newMigrator.migrate(dbQueue) + try dbQueue.read { db in + try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"]) + try XCTAssertTrue(String + .fetchSet(db, sql: "SELECT name FROM sqlite_master") + .isSuperset(of: ["t1", "t2", "t3", "t4", "t5"])) + } + } + + do { + let dbQueue = try makeDatabaseQueue() + try oldMigrator.migrate(dbQueue, upTo: "v3") + + try newMigrator.migrate(dbQueue) + try dbQueue.read { db in + try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"]) + try XCTAssertTrue(String + .fetchSet(db, sql: "SELECT name FROM sqlite_master") + .isSuperset(of: ["t1", "t2", "t3", "t4", "t5"])) + } + } + + do { + let dbQueue = try makeDatabaseQueue() + try oldMigrator.migrate(dbQueue, upTo: "v4") + + try newMigrator.migrate(dbQueue) + try dbQueue.read { db in + try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"]) + try XCTAssertTrue(String + .fetchSet(db, sql: "SELECT name FROM sqlite_master") + .isSuperset(of: ["t1", "t2", "t3", "t4", "t5"])) + } + } + + do { + let dbQueue = try makeDatabaseQueue() + try oldMigrator.migrate(dbQueue, upTo: "v5") + + try newMigrator.migrate(dbQueue) + try dbQueue.read { db in + try XCTAssertEqual(newMigrator.appliedIdentifiers(db), ["v1", "v4", "v5"]) + try XCTAssertTrue(String + .fetchSet(db, sql: "SELECT name FROM sqlite_master") + .isSuperset(of: ["t1", "t2", "t3", "t4", "t5"])) + } + } + } + func test_merged_migrations_with_a_new_name() throws { // Original migrator var oldMigrator = DatabaseMigrator() From ab0907884261081052c180780d673a517df31218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Rou=C3=A9?= Date: Fri, 3 Oct 2025 09:36:22 +0200 Subject: [PATCH 02/22] Fix failing test for merged migration that merges itself --- GRDB/Migration/DatabaseMigrator.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index 3ff634488..f90ebb902 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -327,6 +327,13 @@ public struct DatabaseMigrator: Sendable { case .immediate: migrationChecks = .immediate } + + // Remove the migration identifier from the list of merged identifiers. + // Arguably, the semantics are ambiguous. And raising a fatal error + // is a high price when we can just fix the input. + var mergedIdentifiers = mergedIdentifiers + mergedIdentifiers.remove(identifier) + registerMigration(Migration( identifier: identifier, mergedIdentifiers: mergedIdentifiers, From edc1d646f0181fe1d4fd5d230ac4cafdeb5acbe2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Sat, 4 Oct 2025 12:58:08 +0200 Subject: [PATCH 03/22] [BREAKING] Bump minimum Swift version to 6.1 --- .spi.yml | 2 +- .../GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj | 8 ++++---- GRDB.swift.podspec | 2 +- GRDB/Record/FetchableRecord+Decodable.swift | 6 +----- Package.swift | 2 +- README.md | 4 ++-- SQLiteCustom/GRDB.xcconfig | 2 +- Support/GRDB.xcconfig | 2 +- Tests/GRDBTests/AssociationAggregateTests.swift | 4 ---- ...ssociationBelongsToDecodableRecordTests.swift | 4 ---- .../AssociationBelongsToSQLDerivationTests.swift | 6 ------ .../AssociationHasOneSQLDerivationTests.swift | 4 ---- ...ociationHasOneThroughSQLDerivationTests.swift | 4 ---- .../AssociationTableAliasTestsSQLTests.swift | 2 -- Tests/GRDBTests/CommonTableExpressionTests.swift | 16 ---------------- Tests/GRDBTests/GRDBTestCase.swift | 5 ----- .../QueryInterfaceExpressionsTests.swift | 2 -- Tests/GRDBTests/QueryInterfaceRequestTests.swift | 16 ---------------- .../TableRecord+QueryInterfaceRequestTests.swift | 14 -------------- Tests/GRDBTests/ValueObservationTests.swift | 12 ------------ Tests/SPM/PlainPackage/Package.swift | 2 +- Tests/Swift6Migration/LanguageMode6.xcconfig | 2 +- 22 files changed, 14 insertions(+), 107 deletions(-) diff --git a/.spi.yml b/.spi.yml index 672a6aac0..d72ab58e9 100644 --- a/.spi.yml +++ b/.spi.yml @@ -2,4 +2,4 @@ version: 1 builder: configs: - documentation_targets: [GRDB] - swift_version: 6.0 + swift_version: 6.1 diff --git a/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj b/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj index 6edc31973..599df31db 100644 --- a/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj +++ b/Documentation/DemoApps/GRDBDemo/GRDBDemo.xcodeproj/project.pbxproj @@ -382,7 +382,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 6.0; + SWIFT_VERSION = 6.1; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -411,7 +411,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemo; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; - SWIFT_VERSION = 6.0; + SWIFT_VERSION = 6.1; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -427,7 +427,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 6.0; + SWIFT_VERSION = 6.1; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GRDBDemo.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/GRDBDemo"; }; @@ -444,7 +444,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.github.groue.GRDBDemoTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = NO; - SWIFT_VERSION = 6.0; + SWIFT_VERSION = 6.1; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GRDBDemo.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/GRDBDemo"; }; diff --git a/GRDB.swift.podspec b/GRDB.swift.podspec index 70065f822..a58b8eea3 100644 --- a/GRDB.swift.podspec +++ b/GRDB.swift.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/groue/GRDB.swift.git', :tag => "v#{s.version}" } s.module_name = 'GRDB' - s.swift_versions = ['6'] + s.swift_versions = ['6.1'] s.ios.deployment_target = '13.0' s.osx.deployment_target = '10.15' s.watchos.deployment_target = '7.0' diff --git a/GRDB/Record/FetchableRecord+Decodable.swift b/GRDB/Record/FetchableRecord+Decodable.swift index 3edf3611c..99c2c0475 100644 --- a/GRDB/Record/FetchableRecord+Decodable.swift +++ b/GRDB/Record/FetchableRecord+Decodable.swift @@ -519,20 +519,16 @@ private struct SingleValueRowDecoder: SingleValueDecodingCon func decode(_ type: Int16.Type) throws -> Int16 { try columnDecoder.decode(type) } func decode(_ type: Int32.Type) throws -> Int32 { try columnDecoder.decode(type) } func decode(_ type: Int64.Type) throws -> Int64 { try columnDecoder.decode(type) } -#if compiler(>=6) @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) func decode(_ type: Int128.Type) throws -> Int128 { try columnDecoder.decode(type) } -#endif func decode(_ type: UInt.Type) throws -> UInt { try columnDecoder.decode(type) } func decode(_ type: UInt8.Type) throws -> UInt8 { try columnDecoder.decode(type) } func decode(_ type: UInt16.Type) throws -> UInt16 { try columnDecoder.decode(type) } func decode(_ type: UInt32.Type) throws -> UInt32 { try columnDecoder.decode(type) } func decode(_ type: UInt64.Type) throws -> UInt64 { try columnDecoder.decode(type) } -#if compiler(>=6) @available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) func decode(_ type: UInt128.Type) throws -> UInt128 { try columnDecoder.decode(type) } -#endif - + func decode(_ type: T.Type) throws -> T where T: Decodable { if let type = T.self as? any FetchableRecord.Type { // Prefer FetchableRecord decoding over Decodable. diff --git a/Package.swift b/Package.swift index 36937d039..72875fe2d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:6.0 +// swift-tools-version:6.1 // The swift-tools-version declares the minimum version of Swift required to build this package. import Foundation diff --git a/README.md b/README.md index 920bd6069..4261c65e8 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@
- +