From e29c0c0c5758f77f5d20fdd8e0f3a6ef03a81ea9 Mon Sep 17 00:00:00 2001 From: bwdmr Date: Fri, 8 Aug 2025 11:54:40 +0200 Subject: [PATCH 1/2] Add PostGIS extension migration and configuration - Add EnablePostGISMigration to automatically create/drop PostGIS extension - Include EnablePostGISMigration as first migration in test suite - Add SQLKit import for raw SQL execution - Define FluentPostGISSrid constant (4326) for spatial reference - Fix trailing comma in migrations array Signed-off-by: bwdmr --- .../FluentPostGISTestCase.swift | 3 ++- Tests/FluentPostGISTests/TestModels.swift | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Tests/FluentPostGISTests/FluentPostGISTestCase.swift b/Tests/FluentPostGISTests/FluentPostGISTestCase.swift index 91fcad1..8c632a9 100644 --- a/Tests/FluentPostGISTests/FluentPostGISTestCase.swift +++ b/Tests/FluentPostGISTests/FluentPostGISTestCase.swift @@ -37,10 +37,11 @@ class FluentPostGISTestCase: XCTestCase { } private let migrations: [any AsyncMigration] = [ + EnablePostGISMigration(), UserLocationMigration(), CityMigration(), UserPathMigration(), UserAreaMigration(), - UserCollectionMigration(), + UserCollectionMigration() ] } diff --git a/Tests/FluentPostGISTests/TestModels.swift b/Tests/FluentPostGISTests/TestModels.swift index 3a86028..47a917c 100644 --- a/Tests/FluentPostGISTests/TestModels.swift +++ b/Tests/FluentPostGISTests/TestModels.swift @@ -1,3 +1,4 @@ +import SQLKit import FluentKit import FluentPostGIS @@ -146,3 +147,27 @@ struct UserCollectionMigration: AsyncMigration { try await database.schema(UserCollection.schema).delete() } } + +public struct EnablePostGISMigration: AsyncMigration, Sendable { + public init() {} + + public enum EnablePostGISMigrationError: Error, Sendable { + case notSqlDatabase + } + + public func prepare(on database: any Database) async throws { + guard let db = database as? any SQLDatabase else { + throw EnablePostGISMigrationError.notSqlDatabase + } + try await db.raw("CREATE EXTENSION IF NOT EXISTS \"postgis\"").run() + } + + public func revert(on database: any Database) async throws { + guard let db = database as? any SQLDatabase else { + throw EnablePostGISMigrationError.notSqlDatabase + } + try await db.raw("DROP EXTENSION IF EXISTS \"postgis\"").run() + } +} + +public let FluentPostGISSrid: UInt = 4326 From dd0fd5329c3bd9d17ce6633bbc72f2f6604ec585 Mon Sep 17 00:00:00 2001 From: bwdmr Date: Fri, 8 Aug 2025 13:00:32 +0200 Subject: [PATCH 2/2] Move PostGIS utilities to main library and add missing import - Remove EnablePostGISMigration and FluentPostGISSrid from test models - Add FluentPostGIS import to test case (now using library's utilities) --- .../FluentPostGISTestCase.swift | 1 + Tests/FluentPostGISTests/TestModels.swift | 23 ------------------- 2 files changed, 1 insertion(+), 23 deletions(-) diff --git a/Tests/FluentPostGISTests/FluentPostGISTestCase.swift b/Tests/FluentPostGISTests/FluentPostGISTestCase.swift index 8c632a9..344b88f 100644 --- a/Tests/FluentPostGISTests/FluentPostGISTestCase.swift +++ b/Tests/FluentPostGISTests/FluentPostGISTestCase.swift @@ -1,4 +1,5 @@ import FluentKit +import FluentPostGIS import FluentPostgresDriver import PostgresKit import XCTest diff --git a/Tests/FluentPostGISTests/TestModels.swift b/Tests/FluentPostGISTests/TestModels.swift index 47a917c..e9fa8ac 100644 --- a/Tests/FluentPostGISTests/TestModels.swift +++ b/Tests/FluentPostGISTests/TestModels.swift @@ -148,26 +148,3 @@ struct UserCollectionMigration: AsyncMigration { } } -public struct EnablePostGISMigration: AsyncMigration, Sendable { - public init() {} - - public enum EnablePostGISMigrationError: Error, Sendable { - case notSqlDatabase - } - - public func prepare(on database: any Database) async throws { - guard let db = database as? any SQLDatabase else { - throw EnablePostGISMigrationError.notSqlDatabase - } - try await db.raw("CREATE EXTENSION IF NOT EXISTS \"postgis\"").run() - } - - public func revert(on database: any Database) async throws { - guard let db = database as? any SQLDatabase else { - throw EnablePostGISMigrationError.notSqlDatabase - } - try await db.raw("DROP EXTENSION IF EXISTS \"postgis\"").run() - } -} - -public let FluentPostGISSrid: UInt = 4326