Install database extensions via Migrations
cshadek opened this issue · 2 comments
cshadek commented
Is your feature request related to a problem? Please describe.
I have a use case where I want to install an extension in a Postgres database like the following:
CREATE EXTENSION IF NOT EXISTS pg_trgm;
Is this possible today?
mkll commented
@cshadek Sure. Let's see an example of custom SQL operator (Migration
):
func prepare(on db: Database) -> EventLoopFuture<Void> {
let initialId = "123"
let rawSQL: SQLQueryString = "ALTER SEQUENCE \(raw: "auto_id")_id_seq RESTART WITH \(raw: initialId);"
return [
db.schema(LoadAutoID.schema)
.field("id", .sql(raw: "SERIAL NOT NULL PRIMARY KEY"))
.field("updatedAt", .datetime, .required)
.create(),
(db as! SQLDatabase)
.raw(rawSQL)
.run()
].sequencedFlatMapEach(on: db.eventLoop) { $0 }
}
mkll commented
@cshadek Also, you may look here for the similar usage example:
https://github.com/pgvector/pgvector-swift