Skip to content

Commit cb88dfc

Browse files
authored
Adding support for Postgres Extensions (#1443)
1 parent ed3be9c commit cb88dfc

File tree

32 files changed

+1305
-30
lines changed

32 files changed

+1305
-30
lines changed

waspc/ChangeLog.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

33
## 0.11.4
44

5+
### 🎉 [New Feature] Support for PostgreSQL Extensions
6+
7+
Wasp now supports PostgreSQL extensions! You can enable them in your `main.wasp` file:
8+
9+
```wasp
10+
app todoApp {
11+
// ...
12+
db: {
13+
system: PostgreSQL,
14+
prisma: {
15+
clientPreviewFeatures: ["postgresqlExtensions"],
16+
dbExtensions: [{
17+
name: "pgvector",
18+
// map: "vector", (optional)
19+
// schema: "public", (optional)
20+
// version: "0.1.0", (optiona)
21+
}]
22+
}
23+
}
24+
}
25+
```
26+
27+
This will add the necessary Prisma configuration to your `schema.prisma` file. Keep in mind that your database needs to support the extension you want to use. For example, if you want to use the `pgvector` extension, you need to install it in your database first.
28+
529
### 🎉 [New Feature] Added Typescript support for Jobs
630

731
Now you can type your async jobs better and receive all the benefits of Typescript. When you define a job, Wasp will generate a generic type which you can use to type your job function:

waspc/data/Generator/templates/db/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
datasource db {
44
provider = "{= datasourceProvider =}"
55
url = {=& datasourceUrl =}
6+
{=# dbExtensions =}
7+
extensions = {=& . =}
8+
{=/ dbExtensions =}
69
}
710

811
generator client {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/.wasp/
2+
3+
# We ignore env files recognized and used by Wasp.
4+
.env.server
5+
.env.client
6+
7+
# To be extra safe, we by default ignore any files with `.env` extension in them.
8+
# If this is too agressive for you, consider allowing specific files with `!` operator,
9+
# or modify/delete these two lines.
10+
*.env
11+
*.env.*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
File marking the root of Wasp project.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
OPENAI_API_KEY=
2+
# If ran run_db.sh:
3+
DATABASE_URL=postgresql://postgres:devpass@localhost:5432/postgres
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
app pgVectorExample {
2+
wasp: {
3+
version: "^0.11.3"
4+
},
5+
title: "PG Vector Example",
6+
dependencies: [
7+
("openai", "^4.5.0"),
8+
("react-hook-form", "^7.43.1"),
9+
("@nextui-org/react", "^2.1.10"),
10+
("framer-motion", "^10.16.4"),
11+
("pgvector", "0.1.5"),
12+
("cheerio", "1.0.0-rc.12"),
13+
("axios", "^1.4.0"),
14+
("react-markdown", "^8.0.7")
15+
],
16+
client: {
17+
rootComponent: import { Layout } from "@client/Layout.tsx",
18+
},
19+
db: {
20+
system: PostgreSQL,
21+
prisma: {
22+
clientPreviewFeatures: ["postgresqlExtensions"],
23+
dbExtensions: [{
24+
name: "pgvector",
25+
map: "vector"
26+
}]
27+
}
28+
}
29+
}
30+
31+
route RootRoute { path: "/", to: MainPage }
32+
page MainPage {
33+
component: import { Main } from "@client/pages/MainPage.tsx"
34+
}
35+
36+
action embedDocument {
37+
fn: import { embedDocument } from "@server/documents.js",
38+
entities: [Document],
39+
}
40+
41+
action getScrapeCandidates {
42+
fn: import { getScrapeCandidates } from "@server/documents.js",
43+
entities: [Document],
44+
}
45+
46+
query getDocuments {
47+
fn: import { getDocuments } from "@server/documents.js",
48+
entities: [Document]
49+
}
50+
51+
action searchDocuments {
52+
fn: import { searchDocuments } from "@server/documents.js",
53+
entities: [Document]
54+
}
55+
56+
action askDocuments {
57+
fn: import { askDocuments } from "@server/documents.js",
58+
entities: [Document]
59+
}
60+
61+
action deleteDocument {
62+
fn: import { deleteDocument } from "@server/documents.js",
63+
entities: [Document]
64+
}
65+
66+
entity Document {=psl
67+
id String @id @default(uuid())
68+
title String
69+
url String @unique
70+
content String
71+
embedding Unsupported("vector(1536)")
72+
createdAt DateTime @default(now())
73+
updatedAt DateTime @updatedAt
74+
psl=}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- CreateExtension
2+
CREATE EXTENSION IF NOT EXISTS "vector";
3+
4+
-- CreateTable
5+
CREATE TABLE "Document" (
6+
"id" TEXT NOT NULL,
7+
"title" TEXT NOT NULL,
8+
"content" TEXT NOT NULL,
9+
"embedding" vector(1536) NOT NULL,
10+
11+
CONSTRAINT "Document_pkey" PRIMARY KEY ("id")
12+
);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[url]` on the table `Document` will be added. If there are existing duplicate values, this will fail.
5+
- Added the required column `updatedAt` to the `Document` table without a default value. This is not possible if the table is not empty.
6+
- Added the required column `url` to the `Document` table without a default value. This is not possible if the table is not empty.
7+
8+
*/
9+
-- AlterTable
10+
ALTER TABLE "Document" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
11+
ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL,
12+
ADD COLUMN "url" TEXT NOT NULL;
13+
14+
-- CreateIndex
15+
CREATE UNIQUE INDEX "Document_url_key" ON "Document"("url");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "postgresql"
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

0 commit comments

Comments
 (0)