Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions packages/shared-lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

sqlite.ts での提案に合わせて、こちらも定数を export するように変更してください。

Suggested change
export { getConnectionLevelSqlitePragmas, getPersistentSqlitePragmas } from './sqlite.js';
export { CONNECTION_LEVEL_SQLITE_PRAGMAS, PERSISTENT_SQLITE_PRAGMAS } from './sqlite.js';

export { zenkakuAlphanumericalsToHankaku } from './zenkaku.js';

export type { RetryOptions } from './error.js';
7 changes: 7 additions & 0 deletions packages/shared-lib/src/sqlite.ts
Original file line number Diff line number Diff line change
@@ -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;';
}
Comment on lines +1 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

これらの関数は常に固定の文字列を返すため、関数ではなく export した定数として定義する方がシンプルで分かりやすいです。これにより、不要な関数呼び出しのオーバーヘッドをなくし、値が定数であることを明確に示すことができます。

Suggested change
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;';
}
export const CONNECTION_LEVEL_SQLITE_PRAGMAS = 'PRAGMA busy_timeout = 5000; PRAGMA synchronous = NORMAL; PRAGMA wal_autocheckpoint = 0;';
export const PERSISTENT_SQLITE_PRAGMAS = 'PRAGMA journal_mode = WAL;';

Comment on lines +1 to +7
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new pragma getter functions lack documentation explaining their purpose and usage. Consider adding JSDoc comments to describe:

  1. What these SQLite pragmas do
  2. Why they are separated into connection-level vs persistent pragmas
  3. The context that they are intended for use with Litestream (as referenced in the original code comment: https://litestream.io/tips/)
  4. When each function should be called

This documentation would help developers understand when and how to use these functions correctly.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +7
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new pragma getter functions lack test coverage. Since shared-lib has tests for other utility functions (humanize, parseCommandLineArgs, zenkaku), these new functions should also have corresponding tests to verify:

  1. The returned pragma strings are formatted correctly
  2. The expected pragma statements are included in each function
  3. The pragmas remain consistent with Litestream best practices

Consider adding a test file at test/sqlite.test.ts.

Copilot uses AI. Check for mistakes.
13 changes: 0 additions & 13 deletions packages/wb/src/commands/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const prismaCommand: CommandModule = {
.command(deployCommand)
.command(deployForceCommand)
.command(listBackupsCommand)
.command(setUpDBForLitestreamCommand)
.command(migrateCommand)
.command(migrateDevCommand)
.command(resetCommand)
Expand Down Expand Up @@ -190,18 +189,6 @@ const seedCommand: CommandModule<unknown, InferredOptionTypes<typeof seedBuilder
},
};

const setUpDBForLitestreamCommand: CommandModule<unknown, InferredOptionTypes<typeof builder>> = {
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': {
Expand Down
22 changes: 0 additions & 22 deletions packages/wb/src/scripts/prismaScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = '';
Expand Down