Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Prisma file alongside Wasp #2035

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ee55435
Using Prisma file alongside Wasp POC
infomiho May 16, 2024
34c53b2
Extend Prisma parser
infomiho May 23, 2024
a5de8ed
Update module names.
infomiho May 23, 2024
c6bb80b
Unit tests
infomiho May 23, 2024
5e0365f
Cleanup, fix tests.
infomiho May 24, 2024
b49cbb0
Fixes headless tests
infomiho May 24, 2024
df254bf
Fixes issue with parsing PSL types
infomiho May 24, 2024
7307d99
Update the crud-testing app
infomiho May 24, 2024
d13d53b
Updates todo-typescript to use a separate Prisma file
infomiho May 30, 2024
831c515
Cleanup
infomiho May 24, 2024
f80d02b
Cleanup
infomiho May 24, 2024
e70412b
Cleanup
infomiho May 24, 2024
9ddeb8d
Inject Prisma models into the Wasp AST
infomiho May 25, 2024
a465549
Upgrade Prisma enum parser
infomiho May 25, 2024
bcf7876
Fixes unit tests
infomiho May 27, 2024
dec346d
Handles optional lists In Prisma parser and validates them
infomiho May 28, 2024
e600db9
Handle commented out fields in config blocks
infomiho May 28, 2024
35ca110
Updates the way LS handles Prisma file updates
infomiho May 28, 2024
d078f20
Uses DB provider from Prisma file. Uses config blocks.
infomiho May 30, 2024
e80722a
Fixes headless tests
infomiho May 30, 2024
af96f07
Adds a TODO
infomiho Jun 4, 2024
df56853
Allow field names to be anything (no reserved names)
infomiho Jun 4, 2024
66cb823
Fixes tests
infomiho Jun 5, 2024
253925f
Merge branch 'main' into miho-prisma-file
infomiho Jun 10, 2024
b4e83d2
Remove string type annotation
infomiho Jun 10, 2024
c37fed3
Update basic template
infomiho Jun 10, 2024
02840a4
Updates Analyzer comments
infomiho Jun 10, 2024
04775f9
Update comment
infomiho Jun 10, 2024
5402a7e
Update Analyzer.Prisma
infomiho Jun 10, 2024
e186668
Remove needless AppSpec helpers
infomiho Jun 10, 2024
40d8da3
Throw if db system invalid
infomiho Jun 10, 2024
30a7619
Cleanup
infomiho Jun 10, 2024
ece0287
Update error message
infomiho Jun 10, 2024
64e3853
Cleanup Valid.hs
infomiho Jun 10, 2024
85e2182
Cleanup
infomiho Jun 10, 2024
a703317
Update comments
infomiho Jun 11, 2024
52bd255
Merge branch 'main' into miho-prisma-file
infomiho Jun 11, 2024
35e9cd2
Split Schema into multiple files. Upgrade AST tests
infomiho Jun 11, 2024
a78e6c2
Cleanup
infomiho Jun 11, 2024
4ce4ff4
Update waspc/waspls/src/Wasp/LSP/DynamicHandlers.hs
infomiho Jun 11, 2024
504fa4a
Updates naming. Clenaup
infomiho Jun 11, 2024
491e22e
Update naming
infomiho Jun 11, 2024
95db97b
Update types
infomiho Jun 11, 2024
143ada1
Rename param
infomiho Jun 11, 2024
d0bc020
Updates naming
infomiho Jun 12, 2024
40d89a2
PR comments
infomiho Jun 12, 2024
1ab56f3
PR comments
infomiho Jun 12, 2024
b958279
Unify ConfigBlock. Updates schema generation.
infomiho Jun 12, 2024
4fa4f79
Formatting
infomiho Jun 12, 2024
54e00a3
Uses Filepath </> for LSP path joining
infomiho Jun 12, 2024
780cb1e
Update waspc/src/Wasp/Psl/Ast/Enum.hs
infomiho Jun 18, 2024
c25d86d
PR comments
infomiho Jun 18, 2024
ade27d3
Updates fn to findPrismaConfigBlockKeyValuePair
infomiho Jun 18, 2024
a8e9e46
Updates naming
infomiho Jun 18, 2024
3751511
Use DATABASE_URL for Sqlite db
infomiho Jun 18, 2024
41e7f50
Make sure Prisma schema parsing fails
infomiho Jun 18, 2024
2a89d35
Cleanup
infomiho Jun 18, 2024
f8cd306
Validate DB url field. Upgrade Prisma schema parser.
infomiho Jun 18, 2024
6326639
Uses choice instead of <|>. Better schema parser typing.
infomiho Jun 18, 2024
df74926
Cleanup
infomiho Jun 18, 2024
77b52c5
Cleanup
infomiho Jun 18, 2024
1e881b3
Adds check for schema in node_modules
infomiho Jun 18, 2024
e377d70
Made docs for manual deployment of web client slightly cleaner.
Martinsos Jun 17, 2024
101a5d1
Made examples/todoApp more approachable (+ documented what it should …
Martinsos Jun 18, 2024
a021f2d
Cleanup validation. Cleanup comments.
infomiho Jun 19, 2024
16874d8
Update error message
infomiho Jun 19, 2024
8d1de68
erge branch 'main' into miho-prisma-file
infomiho Jun 19, 2024
a260b75
Whitespace update. Cleanup
infomiho Jun 20, 2024
bd01e0b
Auth Hooks (#1993)
infomiho Jun 21, 2024
a6979dc
Updates e2e tests to match output of Typescript 5.5 (#2111)
infomiho Jun 21, 2024
125557e
Fixes headless tests
infomiho Jun 21, 2024
39f1baa
Better unsupported db provider error message
infomiho Jun 21, 2024
944bfa6
Merge branch 'main' into miho-prisma-file
infomiho Jun 21, 2024
bff1f45
PR comments
infomiho Jun 21, 2024
7fdeb03
Merge branch 'main' into miho-prisma-file
infomiho Jun 25, 2024
fda2a9a
Update e2e tests to work with Prisma file (#2095)
infomiho Jun 25, 2024
21efa76
Fixes the basic template
infomiho Jun 27, 2024
a327f9f
Attribute tests based on user input
infomiho Jun 30, 2024
8df0f18
Updates Wasp AI to work with the Prisma file (#2080)
infomiho Jun 30, 2024
17843aa
Merge branch 'main' into miho-prisma-file
infomiho Jun 30, 2024
344e37b
Remove redundant comment in template
infomiho Jun 30, 2024
0bcae13
Fixes missing schema crashing Wasp checksum check
infomiho Jul 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions waspc/cli/src/Wasp/Cli/Command/Info.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Wasp.Cli.Command.Common (readWaspCompileInfo)
import Wasp.Cli.Command.Compile (analyze)
import Wasp.Cli.Command.Message (cliSendMessageC)
import Wasp.Cli.Command.Require (InWaspProject (InWaspProject), require)
import Wasp.Cli.Command.Start.Db (getDbSystem)
import Wasp.Cli.Terminal (title)
import qualified Wasp.Message as Msg
import Wasp.Project (WaspProjectDir)
Expand All @@ -29,15 +28,15 @@ info = do
projectSize <- liftIO $ readDirectorySizeMB waspDir

appSpec <- analyze waspDir
let (appName, app) = ASV.getApp appSpec
let (appName, _) = ASV.getApp appSpec

cliSendMessageC $
Msg.Info $
unlines
[ "",
title "Project information",
printInfo "Name" appName,
printInfo "Database system" $ show $ getDbSystem app,
printInfo "Database system" $ show $ ASV.getValidDbSystem appSpec,
printInfo "Last compile" compileInfo,
printInfo "Project dir size" projectSize
]
Expand Down
12 changes: 3 additions & 9 deletions waspc/cli/src/Wasp/Cli/Command/Start/Db.hs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
module Wasp.Cli.Command.Start.Db
( start,
getDbSystem,
waspDevDbDockerVolumePrefix,
)
where

import Control.Monad (when)
import qualified Control.Monad.Except as E
import Control.Monad.IO.Class (liftIO)
import Data.Maybe (fromMaybe, isJust)
import Data.Maybe (isJust)
import StrongPath (Abs, Dir, File', Path', Rel, fromRelFile)
import System.Environment (lookupEnv)
import System.Process (callCommand)
import Text.Printf (printf)
import qualified Wasp.AppSpec as AS
import qualified Wasp.AppSpec.App as AS.App
import qualified Wasp.AppSpec.App.Db as AS.App.Db
import qualified Wasp.AppSpec.Valid as ASV
import Wasp.Cli.Command (Command, CommandError (CommandError))
Expand Down Expand Up @@ -42,8 +40,8 @@ start = do

throwIfCustomDbAlreadyInUse appSpec

let (appName, app) = ASV.getApp appSpec
case getDbSystem app of
let (appName, _) = ASV.getApp appSpec
case ASV.getValidDbSystem appSpec of
AS.App.Db.SQLite -> noteSQLiteDoesntNeedStart
AS.App.Db.PostgreSQL -> startPostgreDevDb waspProjectDir appName
where
Expand Down Expand Up @@ -85,10 +83,6 @@ throwIfCustomDbAlreadyInUse spec = do
throwCustomDbAlreadyInUseError msg =
E.throwError $ CommandError "You are using custom database already" msg

getDbSystem :: AS.App.App -> AS.App.Db.DbSystem
getDbSystem app =
fromMaybe AS.App.Db.SQLite (AS.App.db app >>= AS.App.Db.system)

startPostgreDevDb :: Path' Abs (Dir WaspProjectDir) -> String -> Command ()
startPostgreDevDb waspProjectDir appName = do
throwIfExeIsNotAvailable
Expand Down
13 changes: 5 additions & 8 deletions waspc/cli/src/Wasp/Cli/Command/Studio.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import qualified Wasp.AppSpec as AS
import qualified Wasp.AppSpec.Api as AS.Api
import qualified Wasp.AppSpec.App as AS.App
import qualified Wasp.AppSpec.App.Auth as AS.App.Auth
import qualified Wasp.AppSpec.App.Db as AS.App.Db
import qualified Wasp.AppSpec.Job as AS.Job
import Wasp.AppSpec.Operation (Operation (..))
import qualified Wasp.AppSpec.Operation as Operation
Expand Down Expand Up @@ -117,7 +116,7 @@ studio = do
.= object
[ "name" .= (appName :: String),
"auth" .= getAuthInfo appSpec app,
"db" .= getDbInfo app
"db" .= getDbInfo appSpec
]
-- TODO: Add CRUDs.
]
Expand Down Expand Up @@ -155,12 +154,10 @@ studio = do
resolveEntities spec entityRefs =
AS.resolveRef spec <$> fromMaybe [] entityRefs

getDbInfo app = do
db <- AS.App.db app
return $
object
[ "system" .= (show <$> AS.App.Db.system db)
]
getDbInfo spec =
object
[ "system" .= show (ASV.getValidDbSystem spec)
]

getAuthInfo spec app = do
auth <- AS.App.auth app
Expand Down
12 changes: 12 additions & 0 deletions waspc/data/Cli/templates/basic/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
datasource db {
provider = "sqlite"
// Wasp requires that the url is set to the DATABASE_URL environment variable.
url = env("DATABASE_URL")
}
Martinsos marked this conversation as resolved.
Show resolved Hide resolved

// Wasp requires the `prisma-client-js` generator to be present.
Martinsos marked this conversation as resolved.
Show resolved Hide resolved
generator client {
provider = "prisma-client-js"
}

// Define your Prisma schema below
22 changes: 9 additions & 13 deletions waspc/data/Generator/templates/db/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{{={= =}=}}

datasource db {
provider = "{= datasourceProvider =}"
url = {=& datasourceUrl =}
{=# dbExtensions =}
extensions = {=& . =}
{=/ dbExtensions =}
}
{=& datasourceSchema =}

generator client {
provider = "prisma-client-js"
{=# prismaPreviewFeatures =}
previewFeatures = {=& . =}
{=/ prismaPreviewFeatures =}
}
{=# generatorSchemas =}
{=& . =}
{=/ generatorSchemas =}

{=# modelSchemas =}
{=& . =}

{=/ modelSchemas =}
{=# enumSchemas =}
{=& . =}

{=/ enumSchemas =}
18 changes: 1 addition & 17 deletions waspc/examples/crud-testing/main.wasp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app crudTesting {
wasp: {
version: "^0.13.0"
version: "^0.14.0"
},
head: [
"<link rel=\"stylesheet\" href=\"https://unpkg.com/[email protected]/mvp.css\">"
Expand All @@ -16,7 +16,6 @@ app crudTesting {
onAuthFailedRedirectTo: "/login",
},
db: {
system: PostgreSQL,
seeds: [
import { migrateAuth } from "@src/seeds/migrateAuth.js"
]
Expand Down Expand Up @@ -45,21 +44,6 @@ page DetailPage {
authRequired: true,
}

entity User {=psl
id Int @id @default(autoincrement())
address String?
tasks Task[]
psl=}

// TODO: validate the fields
// Maybe delegate to Prisma
entity Task {=psl
id Int @id @default(autoincrement())
title String
userId Int
user User @relation(fields: [userId], references: [id])
psl=}

crud tasks {
entity: Task,
operations: {
Expand Down
24 changes: 24 additions & 0 deletions waspc/examples/crud-testing/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
datasource db {
provider = "sqlite"
// Wasp requires that the url is set to the DATABASE_URL environment variable.
url = env("DATABASE_URL")
}

// Wasp requires the `prisma-client-js` generator to be present.
generator client {
provider = "prisma-client-js"
}

// Define your Prisma schema below
model User {
id Int @id @default(autoincrement())
address String?
tasks Task[]
}

model Task {
id Int @id @default(autoincrement())
title String
userId Int
user User @relation(fields: [userId], references: [id])
}
22 changes: 1 addition & 21 deletions waspc/examples/pg-vector-example/main.wasp
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
app pgVectorExample {
wasp: {
version: "^0.13.0"
version: "^0.14.0"
},
title: "PG Vector Example",
client: {
rootComponent: import { Layout } from "@src/Layout.tsx",
},
db: {
system: PostgreSQL,
prisma: {
clientPreviewFeatures: ["postgresqlExtensions"],
dbExtensions: [{
name: "pgvector",
map: "vector"
}]
}
}
}

route RootRoute { path: "/", to: MainPage }
Expand Down Expand Up @@ -52,13 +42,3 @@ action deleteDocument {
fn: import { deleteDocument } from "@src/documents.js",
entities: [Document]
}

entity Document {=psl
id String @id @default(uuid())
title String
url String @unique
content String
embedding Unsupported("vector(1536)")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
psl=}
23 changes: 23 additions & 0 deletions waspc/examples/pg-vector-example/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
datasource db {
provider = "postgresql"
// Wasp requires that the url is set to the DATABASE_URL environment variable.
url = env("DATABASE_URL")
extensions = [pgvector(map: "vector")]
}

// Wasp requires the `prisma-client-js` generator to be present.
generator client {
provider = "prisma-client-js"
previewFeatures = ["postgresqlExtensions"]
}

// Define your Prisma schema below
model Document {
id String @id @default(uuid())
title String
url String @unique
content String
embedding Unsupported("vector(1536)")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}
18 changes: 0 additions & 18 deletions waspc/examples/todo-typescript/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ app TodoTypescript {
seeds: [
import { seedMyDb } from "@src/db/seeds.js"
],
system: PostgreSQL
},
webSocket: {
fn: import { webSocketFn } from "@src/websocket/index",
Expand All @@ -53,23 +52,6 @@ app TodoTypescript {
}
}

// Use Prisma Schema Language (PSL) to define our entities: https://www.prisma.io/docs/concepts/components/prisma-schema
// Run `wasp db migrate-dev` in the CLI to create the database tables
// Then run `wasp db studio` to open Prisma Studio and view your db models
entity User {=psl
id Int @id @default(autoincrement())
address String
tasks Task[]
psl=}

entity Task {=psl
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId Int
psl=}

crud Tasks {
entity: Task,
operations: {
Expand Down
25 changes: 25 additions & 0 deletions waspc/examples/todo-typescript/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
datasource db {
provider = "postgresql"
// Wasp requires that the url is set to the DATABASE_URL environment variable.
url = env("DATABASE_URL")
}

// Wasp requires the `prisma-client-js` generator to be present.
generator client {
provider = "prisma-client-js"
}

// Define your Prisma schema below
model User {
id Int @id @default(autoincrement())
address String
tasks Task[]
}

model Task {
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId Int
}
4 changes: 2 additions & 2 deletions waspc/examples/todo-typescript/src/Todo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ const { mockQuery } = mockServer()

const mockUser = {
identities: {
username: {
id: 'Elon'
username: {
id: 'Elon',
},
},
} as AuthUser
Expand Down
16 changes: 0 additions & 16 deletions waspc/examples/todoApp/main.wasp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ app todoApp {
setupFn: import setup from "@src/clientSetup"
},
db: {
system: PostgreSQL,
seeds: [
import { devSeedSimple } from "@src/dbSeeds",
import { prodSeed } from "@src/dbSeeds"
Expand All @@ -68,21 +67,6 @@ app todoApp {
},
}

entity User {=psl
id Int @id @default(autoincrement())
// Business logic
tasks Task[]
address String?
psl=}

entity Task {=psl
id Int @id @default(autoincrement())
description String
isDone Boolean @default(false)
user User @relation(fields: [userId], references: [id])
userId Int
psl=}

route SignupRoute { path: "/signup", to: SignupPage }
page SignupPage {
component: import Signup from "@src/pages/auth/Signup"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- CreateTable
CREATE TABLE "TaskVote" (
"id" TEXT NOT NULL,
"userId" INTEGER NOT NULL,
"taskId" INTEGER NOT NULL,

CONSTRAINT "TaskVote_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "TaskVote" ADD CONSTRAINT "TaskVote_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "TaskVote" ADD CONSTRAINT "TaskVote_taskId_fkey" FOREIGN KEY ("taskId") REFERENCES "Task"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Loading
Loading