Skip to content

feat: PostgreSQL移行の第一段階 — 開発環境・migration互換・テストプロファイル (#62)#66

Merged
strnh merged 5 commits into
mainfrom
feature/62-postgres-primary
Jul 12, 2026
Merged

feat: PostgreSQL移行の第一段階 — 開発環境・migration互換・テストプロファイル (#62)#66
strnh merged 5 commits into
mainfrom
feature/62-postgres-primary

Conversation

@strnh

@strnh strnh commented Jul 12, 2026

Copy link
Copy Markdown
Owner

概要

Issue #62(PostgreSQL 移行)の第一実装単位「PostgreSQL で migrate:fresh と Feature test を通す」を実装する。

変更内容

  • docs: README の DB 記述 3 箇所を「PostgreSQL を primary DB へ移行予定(feat: postgresql 移行 #62)、SQLite は移行元/legacy 扱い」に整合
  • 開発環境: .env.pgsql.example(pgsql 接続のローカル既定値)と scripts/pgsql-dev.sh(podman/docker で postgres:17-alpine の start/stop/destroy/status。start 時にテスト用 DB quotebuilder_test も作成)を追加
  • migration 互換: customer_signatures 移行の重複検出を having('n','>',1)havingRaw('count(*) > 1') に修正。PostgreSQL は HAVING で SELECT 別名を参照できない(SQLSTATE 42703)
  • テスト: phpunit.pgsql.xml プロファイルと composer run test:pgsql を追加。BackupStorageTest を pgsql 実行に対応
    • acting user を default 接続切替前に作成
    • 手書き backup_audit_logs スキーマを実 migration の列構成に一致
    • tearDown で database.default を復元(切替したままだと RefreshDatabase のロールバックが一時 SQLite へ向かい、pgsql 側トランザクションの残置ロックで次テストの migrate がハング)

検証

  • PostgreSQL 17 で migrate:fresh / migrate:reset / migrate 全件通過
  • composer run test:pgsql: 201/201 pass
  • composer test(SQLite :memory:): 201/201 pass(回帰なし)
  • composer validate 通過

スコープ外(後続)

  • バックアップ/リストアの DB ドライバ別分離(SqliteFullBackup/Restore/BackupStorage は SQLite 専用のまま)
  • JSON restore 後の PostgreSQL sequence reset(setval()

Closes 参照: #62(クローズはせず、移行計画の第一段階として紐づけ)

🤖 Generated with Claude Code

strnh and others added 4 commits July 11, 2026 20:48
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- .env.pgsql.example: pgsql接続のローカル開発既定値
- scripts/pgsql-dev.sh: podman/docker でのコンテナ起動/停止/破棄。
  起動時にテスト用DB quotebuilder_test も作成する

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
PostgreSQLはHAVINGでSELECT別名を参照できないため、
having('n','>',1) を havingRaw('count(*) > 1') に変更。
pgsqlでmigrate:fresh/migrate:resetの全件通過を確認、
SQLite側もFeature test 201件で回帰なし。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- phpunit.pgsql.xml: scripts/pgsql-dev.sh の quotebuilder_test へ
  force接続するプロファイル。composer run test:pgsql で実行
- BackupStorageTest を pgsql プロファイル対応に修正
  - acting user を default接続切替前に作成(切替後だと手書き
    スキーマの一時DBへinsertされ失敗)
  - 手書き backup_audit_logs を実migrationと同じ列構成に更新
  - tearDown で database.default を復元。切替したままだと
    RefreshDatabase のロールバックが一時SQLiteへ向かい、pgsql側の
    トランザクション残置で次テストの migrate がロック待ちハング
- pgsql / sqlite 両プロファイルで 201件 pass を確認

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

PostgreSQL 移行(Issue #62)の第一段階として、開発環境・migration・テストプロファイルを整備し、「PostgreSQL で migrate と Feature tests を通す」ための足場を追加しています。

Changes:

  • PostgreSQL 開発用の env/example とコンテナ操作スクリプトを追加
  • PostgreSQL で動かない migration の HAVING 句(SELECT 別名参照)を互換な形に修正
  • PostgreSQL 実行用 PHPUnit プロファイルと composer スクリプトを追加し、関連テストを調整

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/Feature/BackupStorageTest.php pgsql プロファイルでも安定して動くよう、接続切替タイミングと手書き SQLite スキーマを実 migration に整合
scripts/pgsql-dev.sh podman/docker で開発用 PostgreSQL コンテナを start/stop/destroy/status できるユーティリティを追加
README.md DB 方針(PostgreSQL を primary DB へ移行予定、SQLite は legacy 扱い)に記述を統一
phpunit.pgsql.xml PostgreSQL 向け PHPUnit 実行プロファイル(quotebuilder_test 接続)を追加
database/migrations/2026_07_01_000000_create_customer_signatures_table.php PostgreSQL 互換の HAVING 条件に修正(別名参照を排除)
composer.json composer run test:pgsql を追加し、pgsql プロファイルでの PHPUnit 実行導線を追加
.env.pgsql.example ローカル PostgreSQL 接続の既定値を提供する env サンプルを追加

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread phpunit.pgsql.xml Outdated
Comment on lines +30 to +35
<env name="DB_CONNECTION" value="pgsql" force="true"/>
<env name="DB_HOST" value="127.0.0.1" force="true"/>
<env name="DB_PORT" value="5432" force="true"/>
<env name="DB_DATABASE" value="quotebuilder_test" force="true"/>
<env name="DB_USERNAME" value="quotebuilder" force="true"/>
<env name="DB_PASSWORD" value="quotebuilder" force="true"/>

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

修正完了: DB_HOST/DB_PORT/DB_USERNAME/DB_PASSWORD の force を外し環境変数で上書き可能にしました(commit a49cd5b)。DB_CONNECTION と DB_DATABASE は、誤上書きで RefreshDatabase が開発DBを消すのを防ぐため force 固定を維持しています。

Copilot レビュー指摘対応。DB_HOST/DB_PORT/DB_USERNAME/DB_PASSWORD の
force="true" を外し、CI やローカルで接続先を環境変数で差し替え可能にする。
DB_CONNECTION と DB_DATABASE は誤って開発DBへ向けて RefreshDatabase が
実データを消さないよう force 固定を維持する。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants