Skip to content

Commit 65fc7d2

Browse files
committed
add CI test + fixes for v9
1 parent 521d99a commit 65fc7d2

File tree

6 files changed

+63
-34
lines changed

6 files changed

+63
-34
lines changed

Sources/FluentPostgreSQL/FluentPostgreSQLProvider.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,23 @@ public final class FluentPostgreSQLProvider: Provider {
1818

1919
/// See `Provider`.
2020
public func willBoot(_ worker: Container) throws -> Future<Void> {
21+
22+
return worker.withPooledConnection(to: .psql) { conn in
23+
return FluentPostgreSQLProvider._setup(on: conn)
24+
}
25+
}
26+
27+
public static func _setup(on conn: PostgreSQLConnection) -> Future<Void> {
2128
struct Setting: Codable {
2229
var version: String
2330
}
24-
25-
return worker.withPooledConnection(to: .psql) { conn in
26-
return conn.select().column(.function("current_setting", [.expression(.literal(.string("server_version")))], as: .identifier("version"))).all(decoding: Setting.self).map { rows in
27-
_serverVersion = rows[0].version
28-
if let versionString = _serverVersion {
29-
let pointIndex = versionString.index(of: ".") ?? versionString.endIndex
30-
let majorVersion = versionString[..<pointIndex]
31-
if let ver = Int(majorVersion) {
32-
_globalEnableIdentityColumns = ver < 10 ? false: _globalEnableIdentityColumns
33-
}
31+
return conn.select().column(.function("current_setting", [.expression(.literal(.string("server_version")))], as: .identifier("version"))).all(decoding: Setting.self).map { rows in
32+
_serverVersion = rows[0].version
33+
if let versionString = _serverVersion {
34+
let pointIndex = versionString.index(of: ".") ?? versionString.endIndex
35+
let majorVersion = versionString[..<pointIndex]
36+
if let ver = Int(majorVersion) {
37+
_globalEnableIdentityColumns = ver < 10 ? false: _globalEnableIdentityColumns
3438
}
3539
}
3640
}

Sources/FluentPostgreSQL/PostgreSQLDatabase+SchemaSupporting.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,32 @@ extension PostgreSQLDatabase: SchemaSupporting {
5454
}
5555

5656
if isIdentifier {
57+
let pkDefault: PostgreSQLPrimaryKeyDefault?
58+
// create a unique name for the primary key since it will be added
59+
// as a separate index.
60+
let unique: String
61+
if let table = column.table {
62+
unique = table.identifier.string + "." + column.identifier.string
63+
} else {
64+
unique = column.identifier.string
65+
}
5766
if _globalEnableIdentityColumns {
58-
let pkDefault: PostgreSQLPrimaryKeyDefault?
59-
// create a unique name for the primary key since it will be added
60-
// as a separate index.
61-
let unique: String
62-
if let table = column.table {
63-
unique = table.identifier.string + "." + column.identifier.string
64-
} else {
65-
unique = column.identifier.string
66-
}
6767
switch dataType {
6868
case .smallint, .integer, .bigint:
6969
pkDefault = .generated(.byDefault)
7070
default:
7171
pkDefault = nil
7272
}
73-
constraints.append(.primaryKey(default: pkDefault, identifier: .identifier("pk:\(unique)")))
7473
} else {
74+
pkDefault = nil
7575
switch dataType {
7676
case .smallint: dataType = .smallserial
7777
case .integer: dataType = .serial
7878
case .bigint: dataType = .bigserial
7979
default: break
8080
}
8181
}
82+
constraints.append(.primaryKey(default: pkDefault, identifier: .identifier("pk:\(unique)")))
8283
}
8384

8485
if isArray {

Sources/FluentPostgreSQL/PostgreSQLEnum.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
public protocol PostgreSQLEnum: PostgreSQLExpressionRepresentable, CaseIterable, Codable, ReflectionDecodable, PostgreSQLDataTypeStaticRepresentable, RawRepresentable where Self.RawValue: LosslessStringConvertible {
1+
public protocol PostgreSQLEnum: PostgreSQLExpressionRepresentable, Swift.CaseIterable, Codable, ReflectionDecodable, PostgreSQLDataTypeStaticRepresentable, RawRepresentable where Self.RawValue: LosslessStringConvertible {
22
static var postgreSQLEnumTypeName: String { get }
33
}
44

Tests/FluentPostgreSQLTests/FluentPostgreSQLTests.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ class FluentPostgreSQLTests: XCTestCase {
1111
var database: PostgreSQLDatabase!
1212

1313
override func setUp() {
14-
#if os(macOS)
1514
let hostname = "localhost"
16-
#else
17-
let hostname = "psql-cleartext"
18-
#endif
19-
15+
2016
let config: PostgreSQLDatabaseConfig = .init(
2117
hostname: hostname,
2218
port: 5432,
@@ -27,6 +23,9 @@ class FluentPostgreSQLTests: XCTestCase {
2723
database = PostgreSQLDatabase(config: config)
2824
let eventLoop = MultiThreadedEventLoopGroup(numberOfThreads: 1)
2925
benchmarker = try! Benchmarker(database, on: eventLoop, onFail: XCTFail)
26+
let conn = try! benchmarker.pool.requestConnection().wait()
27+
defer { benchmarker.pool.releaseConnection(conn) }
28+
try! FluentPostgreSQLProvider._setup(on: conn).wait()
3029
}
3130

3231
func testBenchmark() throws {
@@ -118,7 +117,7 @@ class FluentPostgreSQLTests: XCTestCase {
118117

119118
func testGH21() throws {
120119
/// - types
121-
enum PetType: Int, CaseIterable, ReflectionDecodable, Codable {
120+
enum PetType: Int, Swift.CaseIterable, ReflectionDecodable, Codable {
122121
static let allCases: [PetType] = [.cat, .dog]
123122
case cat = 0
124123
case dog = 1
@@ -131,7 +130,7 @@ class FluentPostgreSQLTests: XCTestCase {
131130

132131
static func prepare(on conn: PostgreSQLConnection) -> EventLoopFuture<Void> {
133132
return PostgreSQLDatabase.create(Pet.self, on: conn) { builder in
134-
builder.field(for: \.id, type: .bigint, .notNull, .primaryKey(default: .generated(.byDefault)))
133+
builder.field(for: \.id)
135134
builder.field(for: \.type, type: .bigint)
136135
builder.field(for: \.name, type: .text)
137136
}

circle.yml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,26 @@ jobs:
88
- checkout
99
- run: swift build
1010
- run: swift test
11-
linux:
11+
linux-10:
1212
docker:
1313
- image: codevapor/swift:4.1
1414
- image: circleci/postgres:latest
15-
name: psql-cleartext
15+
environment:
16+
POSTGRES_USER: vapor_username
17+
POSTGRES_DB: vapor_database
18+
POSTGRES_PASSWORD: vapor_password
19+
steps:
20+
- checkout
21+
- run:
22+
name: Compile code
23+
command: swift build
24+
- run:
25+
name: Run unit tests
26+
command: swift test
27+
linux-9:
28+
docker:
29+
- image: codevapor/swift:4.1
30+
- image: circleci/postgres:9
1631
environment:
1732
POSTGRES_USER: vapor_username
1833
POSTGRES_DB: vapor_database
@@ -37,7 +52,8 @@ workflows:
3752
version: 2
3853
tests:
3954
jobs:
40-
- linux
55+
- linux-10
56+
- linux-9
4157
- linux-release
4258
# - macos
4359
nightly:

docker-compose.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@ services:
66
context: .
77
dockerfile: test.Dockerfile
88
depends_on:
9-
- psql-cleartext
10-
psql-cleartext:
11-
image: postgres:latest
9+
- psql-10
10+
psql-10:
11+
image: postgres:10
1212
environment:
1313
POSTGRES_USER: vapor_username
1414
POSTGRES_DB: vapor_database
1515
POSTGRES_PASSWORD: vapor_password
1616
ports:
1717
- 5432:5432
18+
psql-9:
19+
image: postgres:9
20+
environment:
21+
POSTGRES_USER: vapor_username
22+
POSTGRES_DB: vapor_database
23+
POSTGRES_PASSWORD: vapor_password
24+
ports:
25+
- 5432:5432
26+

0 commit comments

Comments
 (0)