vapor / fluent-postgres-driver

🐘 PostgreSQL driver for Fluent.
MIT License
146 stars 53 forks source link

No DEFERRABLE Constraint option #209

Open anonymouz4 opened 1 year ago

anonymouz4 commented 1 year ago

Currently it isn't possible to declare a constraint, while making it DEFERRABLE or set a initial deferred state.

Workaround 1:

guard let db = database as? PostgresDatabase else {
    throw Abort(.internalServerError)
}
try db.simpleQuery("ALTER TABLE waitlist ADD  CONSTRAINT no_duplicate_ranks UNIQUE(waitlist_rank) DEFERRABLE;").wait()

Workaround 2:

// In create migration
.constraint(.custom("CONSTRAINT \"no_duplicate_ranks\" UNIQUE(waitlist_rank) DEFERRABLE"))