@@ -459,6 +459,86 @@ class FluentPostgreSQLTests: XCTestCase {
459459 defer { try ? C . revert ( on: conn) . wait ( ) }
460460 }
461461
462+ // https://github.com/vapor/fluent-postgresql/issues/85
463+ func testGH85( ) throws {
464+ enum Availability : UInt8 , PostgreSQLRawEnum {
465+ static var allCases : [ Availability ] = [ . everyday, . sunday, . monday, . tuesday, . wednesday, . thursday, . friday, . saturday]
466+
467+ case everyday
468+ case sunday
469+ case monday
470+ case tuesday
471+ case wednesday
472+ case thursday
473+ case friday
474+ case saturday
475+ }
476+
477+ struct Foo : PostgreSQLModel , Migration {
478+ var id : Int ?
479+ var availability : Availability
480+ }
481+
482+ let conn = try benchmarker. pool. requestConnection ( ) . wait ( )
483+ conn. logger = DatabaseLogger ( database: . psql, handler: PrintLogHandler ( ) )
484+ defer { benchmarker. pool. releaseConnection ( conn) }
485+
486+ try Foo . prepare ( on: conn) . wait ( )
487+ defer { try ? Foo . revert ( on: conn) . wait ( ) }
488+
489+ let a = Foo ( id: nil , availability: . everyday)
490+ _ = try a. save ( on: conn) . wait ( )
491+ }
492+
493+ // https://github.com/vapor/fluent-postgresql/issues/35
494+ func testGH35( ) throws {
495+ struct Game : PostgreSQLModel , Migration {
496+ var id : Int ?
497+ var tags : [ Int64 ] ?
498+ }
499+
500+ let conn = try benchmarker. pool. requestConnection ( ) . wait ( )
501+ conn. logger = DatabaseLogger ( database: . psql, handler: PrintLogHandler ( ) )
502+ defer { benchmarker. pool. releaseConnection ( conn) }
503+
504+ try Game . prepare ( on: conn) . wait ( )
505+ defer { try ? Game . revert ( on: conn) . wait ( ) }
506+
507+ var a = Game ( id: nil , tags: [ 1 , 2 , 3 ] )
508+ a = try a. save ( on: conn) . wait ( )
509+ }
510+
511+ // https://github.com/vapor/fluent-postgresql/issues/54
512+ func testGH54( ) throws {
513+ struct User : PostgreSQLModel , Migration {
514+ var id : Int ?
515+ var username : String
516+ }
517+
518+ struct AddUserIndex : PostgreSQLMigration {
519+ static func prepare( on conn: PostgreSQLConnection ) -> Future < Void > {
520+ return Database . update ( User . self, on: conn) { builder in
521+ builder. unique ( on: \. username)
522+ }
523+ }
524+
525+ static func revert( on conn: PostgreSQLConnection ) -> Future < Void > {
526+ return Database . update ( User . self, on: conn) { builder in
527+ builder. deleteUnique ( from: \. username)
528+ }
529+ }
530+ }
531+
532+ let conn = try benchmarker. pool. requestConnection ( ) . wait ( )
533+ conn. logger = DatabaseLogger ( database: . psql, handler: PrintLogHandler ( ) )
534+ defer { benchmarker. pool. releaseConnection ( conn) }
535+
536+ try User . prepare ( on: conn) . wait ( )
537+ defer { try ? User . revert ( on: conn) . wait ( ) }
538+ try AddUserIndex . prepare ( on: conn) . wait ( )
539+ defer { try ? AddUserIndex . revert ( on: conn) . wait ( ) }
540+ }
541+
462542 static let allTests = [
463543 ( " testBenchmark " , testBenchmark) ,
464544 ( " testNestedStruct " , testNestedStruct) ,
@@ -475,6 +555,8 @@ class FluentPostgreSQLTests: XCTestCase {
475555 ( " testCustomFilter " , testCustomFilter) ,
476556 ( " testCreateOrUpdate " , testCreateOrUpdate) ,
477557 ( " testEnumArray " , testEnumArray) ,
558+ ( " testGH85 " , testGH85) ,
559+ ( " testGH35 " , testGH35) ,
478560 ]
479561}
480562
0 commit comments