Skip to content

GTFSのDBマイグレーション - #51

Open
hikaru-0602 wants to merge 9 commits into
mainfrom
feature/add-gtfs-migration
Open

hikaru-0602 wants to merge 9 commits into
mainfrom
feature/add-gtfs-migration

Conversation

@hikaru-0602

@hikaru-0602 hikaru-0602 commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

変更点

GTFSのDBモデル定義,マイグレーション実行

@hikaru-0602 hikaru-0602 self-assigned this Aug 20, 2026

@kantacky kantacky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Standards軸・Spec軸で確認した指摘をインラインコメントとして残します。

Comment thread internal/shared/model/calendar_date.go Outdated
Common

ServiceID string `gorm:"not null;index"`
Calendar *Calendar `gorm:"belongsTo;foreignKey:ServiceID;references:ServiceID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

belongsTo はgormの公式タグとして存在しないキーです。既存コード(例: room_change.go)は gorm:"foreignKey:XxxID;constraint:..." のみを使っており、belongsTo は無効な値として単に無視されます。削除をお願いします。

@hikaru-0602 hikaru-0602 Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

公式にはタグはないけどライブラリ自体には存在してる
https://github.com/go-gorm/gorm/blob/master/schema/relationship.go

これないとHasOne判定になってマイグレーション失敗するからタグ残すことにした
これでも問題はないけど,削除した方が良いなら対応します

Comment thread internal/shared/model/fare_rule.go
Comment thread internal/shared/model/fare_rule.go
Comment thread internal/shared/model/fare_rule.go
Origin *Stop `gorm:"belongsTo;foreignKey:OriginID;references:StopID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
DestinationID string `gorm:"not null;index"`
Destination *Stop `gorm:"belongsTo;foreignKey:DestinationID;references:StopID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
Price float64 `gorm:"not null"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GTFS標準のfare_rules.txtにはprice列は存在せず、price/currency_typeはfare_attributes.txt側(fare_idで紐付け)の責務です。このモデルはfare_attributes相当を作らずpriceを直接埋め込んでおり、正規化されたGTFSモデルから逸脱しています。同一fare_idを複数ルールで共有するケースやcurrency_type等の拡張に対応できなくなるため、設計意図を確認したいです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

本来は,子どもと大人で料金が異なる場合とかを想定してテーブル分かれてるんだけど,実データ見たところ一律料金だったため,テーブルを分ける必要は無いと判断.
将来子ども料金とか作られたら対応は必要になる.

Comment thread internal/shared/model/trip.go Outdated
Comment thread internal/shared/model/trip.go Outdated
Common

StopID string `gorm:"not null;uniqueIndex"`
StopName string `gorm:"not null"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

GTFS仕様上 stop_lat/stop_lon(緯度経度)はConditionally Requiredで、経路探索・地図表示に実質必須のフィールドです。現状StopIDとStopNameのみで位置情報が完全に欠落しており、機能上致命的な漏れの可能性があります。意図的な省略でなければ追加をお願いします。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

今回の仕様には緯度経度は必要ないと判断.
もし,現在地から一番近いバス停を自動選択といった機能を追加するならその際に対応が必要

type CalendarDate struct {
Common

ServiceID string `gorm:"not null;index"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ServiceIDがCalendarへのNOT NULL FKになっていますが、GTFS仕様上はcalendar.txtにservice_idが存在せず、calendar_dates.txtのみで運行日を定義するケースも許容されています。そのケースの取り込み時にFK制約違反になる可能性があるため、Calendar側の存在を前提にしてよいか確認したいです。

Comment thread cmd/atlas-loader/main.go
FareRuleとFCMTokenの登録順が入れ替わっていたため修正。

Co-authored-by: Cursor <cursoragent@cursor.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 10, 2026

Copy link
Copy Markdown

Deploying fun-dotto-server-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5a6c4b5
Status: ✅  Deploy successful!
Preview URL: https://ac92f282.fun-dotto-server-docs.pages.dev
Branch Preview URL: https://feature-add-gtfs-migration.fun-dotto-server-docs.pages.dev

View logs

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