Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reproduce interactive transaction timeout bug
- Loading branch information
Showing
6 changed files
with
60 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DATABASE_URL="postgresql://foo:localpassword@localhost:5432/foo" | ||
DATABASE_URL="postgresql://foo:localpassword@localhost:5435/foo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-- DropIndex | ||
DROP INDEX "User.email_index"; | ||
|
||
-- CreateIndex | ||
CREATE INDEX "User_email_idx" ON "User"("email"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,41 @@ | ||
import { PrismaClient } from '@prisma/client' | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient() | ||
const prisma = new PrismaClient(); | ||
|
||
// A `main` function so that you can use async/await | ||
async function main() { | ||
// ... you will write your Prisma Client queries here | ||
const email = `myemail+${Date.now()}@email.com`; | ||
|
||
const user = await prisma.$transaction( | ||
async (pris) => { | ||
const u = await pris.user.create({ | ||
data: { email }, | ||
}); | ||
|
||
await new Promise((res) => setTimeout(res, 600)); | ||
|
||
return u; | ||
}, | ||
{ timeout: 500 } | ||
); | ||
|
||
console.log("Created user", user); | ||
|
||
const persistedUser = await prisma.user.findUnique({ | ||
where: { id: user.id }, | ||
}); | ||
|
||
if (!persistedUser) { | ||
throw new Error("user not persisted"); | ||
} | ||
|
||
console.log("Loaded user from db", persistedUser); | ||
} | ||
|
||
main() | ||
.catch(e => { | ||
throw e | ||
.catch((e) => { | ||
throw e; | ||
}) | ||
.finally(async () => { | ||
await prisma.$disconnect() | ||
}) | ||
await prisma.$disconnect(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters