vapor / fluent

Vapor ORM (queries, models, and relations) for NoSQL and SQL databases
https://docs.vapor.codes/4.0/fluent/overview/
MIT License
1.32k stars 172 forks source link

Enum migration throws false Error #717

Closed fananek closed 3 years ago

fananek commented 3 years ago

Describe the bug

Enum migration misreports an error [ ERROR ] relation "_fluent_enums" does not exist (parserOpenTable) using Postgres DB. In fact the migration is successful and everything is created properly.

To Reproduce

  1. Define enum itself

    enum PostStatus: String, Codable, CaseIterable {
    case draft, published, archived
    }
  2. Setup migration

    struct CreatePostStatus: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        var enumBuilder = database.enum("post_status")
        for option in PostStatus.allCases {
            enumBuilder = enumBuilder.case(option.rawValue)
        }
        return enumBuilder.create().transform(to: ())
    }
    
    func revert(on database: Database) -> EventLoopFuture<Void> {
        database.enum("post_status").delete()
    }
    }
  3. Run migrate command swift run Run migrate

  4. Fluent throws the error followed by message Migration Successful [ ERROR ] relation "_fluent_enums" does not exist (parserOpenTable) Migration successful

  5. Check database. Table _fluent_enums is there as well as records corresponding to our enum.

Expected behavior

I do expect fluent not to throw an error if everything seems to be fine or make migration unsuccessful in case there is an error during execution.

Environment