-
Notifications
You must be signed in to change notification settings - Fork 0
fix: improve prisma reset command #568
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
Conversation
Summary of ChangesHello @exKAZUu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request refines the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
このプルリクエストは、prisma resetコマンドの改善を目的としています。主な変更点は、SQLiteデータベースの場合にリセット前にデータベースファイルをクリーンアップする機能の追加と、それに伴うresetメソッドのリファクタリングです。全体的に、コマンドの堅牢性を高める良い変更だと思います。リポジトリのスタイルガイドに従い、レビューは日本語で行っています。コードの重複を減らし、可読性を向上させるための提案をいくつかさせていただきます。
| const FILE_SCHEMA = 'file:'; | ||
| const dbUrl = project.env.DATABASE_URL; | ||
| if (!dbUrl?.startsWith(FILE_SCHEMA)) return; | ||
|
|
||
| const rawDbPath = dbUrl.slice(FILE_SCHEMA.length).replace(/[?#].*$/, ''); | ||
| if (!rawDbPath) return; | ||
|
|
||
| const POSSIBLE_PATHS = [ | ||
| { schemaPath: path.join('prisma', 'schema.prisma'), dbPath: 'prisma' }, | ||
| { schemaPath: path.join('prisma', 'schema'), dbPath: path.join('prisma', 'schema') }, | ||
| { schemaPath: path.join('db', 'schema.prisma'), dbPath: 'db' }, | ||
| ]; | ||
| const baseDir = POSSIBLE_PATHS.find(({ schemaPath }) => | ||
| fs.existsSync(path.resolve(project.dirPath, schemaPath)) | ||
| )?.dbPath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FILE_SCHEMA定数とPOSSIBLE_PATHS定数、およびbaseDirを見つけるロジックが、72行目と84-99行目のstudioメソッド内にも存在しており、コードが重複しています。コードの重複は将来のメンテナンス性を低下させる可能性があります。これらの定数とロジックをファイルスコープの定数やヘルパー関数として抽出し、両方の場所から再利用することを検討してください。
例えば、以下のようなヘルパー関数を定義できます。
const FILE_SCHEMA = 'file:';
const POSSIBLE_PRISMA_PATHS = [
{ schemaPath: path.join('prisma', 'schema.prisma'), dbPath: 'prisma' },
{ schemaPath: path.join('prisma', 'schema'), dbPath: path.join('prisma', 'schema') },
{ schemaPath: path.join('db', 'schema.prisma'), dbPath: 'db' },
];
function getPrismaBaseDir(project: Project): string | undefined {
return POSSIBLE_PRISMA_PATHS.find(({ schemaPath }) =>
fs.existsSync(path.resolve(project.dirPath, schemaPath))
)?.dbPath;
}これにより、cleanUpSqliteDbIfNeededとstudioの両方のメソッドがシンプルになり、一貫性が保たれます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR improves the Prisma reset command by adding automatic cleanup of SQLite database files before running the reset. The change addresses potential issues where stale WAL (Write-Ahead Logging) and SHM (Shared Memory) files could interfere with the database reset process.
Key Changes:
- Refactored the
resetmethod to build commands using an array-based approach with conditional steps - Added a new
cleanUpSqliteDbIfNeededutility function that generates shell commands to remove SQLite database files and their associated WAL/SHM files before reset - The cleanup is only performed for SQLite databases (detected via
file:protocol inDATABASE_URL)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…aScripts - Remove if/else redundancy by moving resetCommand push outside conditional - Extract FILE_SCHEMA and POSSIBLE_PRISMA_PATHS as file-level constants - Add getPrismaBaseDir helper function to eliminate code duplication - Simplify studio and cleanUpSqliteDbIfNeeded methods Co-authored-by: WillBooster (Claude Code) <agent@willbooster.com>
Close #
Self Check
All checks have passedon this page.WIP:.yarn test) passed.yarn lint) passed.