From 7e1235fe123663bc609eb924c2c840bf68dd0a88 Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Sat, 13 Dec 2025 13:57:47 +0900 Subject: [PATCH] feat!: remove 'prisma setup-db-for-litestream' and add pragmas getters --- packages/shared-lib/src/index.ts | 1 + packages/shared-lib/src/sqlite.ts | 7 +++++++ packages/wb/src/commands/prisma.ts | 13 ------------- packages/wb/src/scripts/prismaScripts.ts | 22 ---------------------- 4 files changed, 8 insertions(+), 35 deletions(-) create mode 100644 packages/shared-lib/src/sqlite.ts diff --git a/packages/shared-lib/src/index.ts b/packages/shared-lib/src/index.ts index c90161de..f55c1b1a 100644 --- a/packages/shared-lib/src/index.ts +++ b/packages/shared-lib/src/index.ts @@ -4,6 +4,7 @@ export { mailTemplates } from './mail.js'; export { parseCommandLineArgs } from './parseCommandLineArgs.js'; export { shuffle } from './shuffle.js'; export { sleep } from './sleep.js'; +export { getConnectionLevelSqlitePragmas, getPersistentSqlitePragmas } from './sqlite.js'; export { zenkakuAlphanumericalsToHankaku } from './zenkaku.js'; export type { RetryOptions } from './error.js'; diff --git a/packages/shared-lib/src/sqlite.ts b/packages/shared-lib/src/sqlite.ts new file mode 100644 index 00000000..3c35ce0b --- /dev/null +++ b/packages/shared-lib/src/sqlite.ts @@ -0,0 +1,7 @@ +export function getConnectionLevelSqlitePragmas(): string { + return 'PRAGMA busy_timeout = 5000; PRAGMA synchronous = NORMAL; PRAGMA wal_autocheckpoint = 0;'; +} + +export function getPersistentSqlitePragmas(): string { + return 'PRAGMA journal_mode = WAL;'; +} diff --git a/packages/wb/src/commands/prisma.ts b/packages/wb/src/commands/prisma.ts index 58d1b414..8f6e4630 100644 --- a/packages/wb/src/commands/prisma.ts +++ b/packages/wb/src/commands/prisma.ts @@ -24,7 +24,6 @@ export const prismaCommand: CommandModule = { .command(deployCommand) .command(deployForceCommand) .command(listBackupsCommand) - .command(setUpDBForLitestreamCommand) .command(migrateCommand) .command(migrateDevCommand) .command(resetCommand) @@ -190,18 +189,6 @@ const seedCommand: CommandModule> = { - command: 'setup-db-for-litestream', - describe: 'Setup DB for Litestream', - builder, - async handler(argv) { - const allProjects = await findPrismaProjects(argv); - for (const project of prepareForRunningCommand('prisma setup-db-for-litestream', allProjects)) { - await runWithSpawn(prismaScripts.setUpDBForLitestream(project), project, argv); - } - }, -}; - const studioBuilder = { ...builder, 'db-url-or-path': { diff --git a/packages/wb/src/scripts/prismaScripts.ts b/packages/wb/src/scripts/prismaScripts.ts index 0ad3d503..6b142c4f 100644 --- a/packages/wb/src/scripts/prismaScripts.ts +++ b/packages/wb/src/scripts/prismaScripts.ts @@ -2,7 +2,6 @@ import fs from 'node:fs'; import path from 'node:path'; import type { Project } from '../project.js'; -import { runtimeWithArgs } from '../utils/runtime.js'; /** * A collection of scripts for executing Prisma commands. @@ -63,27 +62,6 @@ class PrismaScripts { return `if [ -e "prisma/seeds.ts" ]; then BUN build-ts run prisma/seeds.ts; fi`; } - setUpDBForLitestream(_: Project): string { - // cf. https://litestream.io/tips/ - return `${runtimeWithArgs} -e ' -const { PrismaClient } = require("@prisma/client"); -const prisma = new PrismaClient(); -(async () => { - try { - await prisma.$queryRawUnsafe("PRAGMA busy_timeout = 5000"); - await prisma.$queryRawUnsafe("PRAGMA journal_mode = WAL"); - await prisma.$queryRawUnsafe("PRAGMA synchronous = NORMAL"); - await prisma.$queryRawUnsafe("PRAGMA wal_autocheckpoint = 0"); - } catch (error) { - console.error("Failed due to:", error); - process.exit(1); - } finally { - await prisma.$disconnect(); - } -})(); -'`; - } - studio(project: Project, dbUrlOrPath?: string, additionalOptions = ''): string { const FILE_SCHEMA = 'file:'; let prefix = '';