-
Notifications
You must be signed in to change notification settings - Fork 0
GTFSのDBマイグレーション #51
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
base: main
Are you sure you want to change the base?
GTFSのDBマイグレーション #51
Changes from 2 commits
24a5964
4c196f3
06f0511
f9f8263
10f9cf6
84e26d9
9b6debb
e03faa2
5a6c4b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package model | ||
|
|
||
| type Calendar struct { | ||
| Common | ||
|
|
||
| ServiceID string `gorm:"not null;uniqueIndex"` | ||
| Monday int `gorm:"not null"` | ||
| Tuesday int `gorm:"not null"` | ||
| Wednesday int `gorm:"not null"` | ||
| Thursday int `gorm:"not null"` | ||
| Friday int `gorm:"not null"` | ||
| Saturday int `gorm:"not null"` | ||
| Sunday int `gorm:"not null"` | ||
| StartDate string `gorm:"not null"` | ||
| EndDate string `gorm:"not null"` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package model | ||
|
|
||
| type CalendarDate struct { | ||
| Common | ||
|
|
||
| ServiceID string `gorm:"not null;index"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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側の存在を前提にしてよいか確認したいです。 |
||
| Calendar *Calendar `gorm:"belongsTo;foreignKey:ServiceID;references:ServiceID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 公式にはタグはないけどライブラリ自体には存在してる これないとHasOne判定になってマイグレーション失敗するからタグ残すことにした |
||
| Date string `gorm:"not null;index"` | ||
| ExceptionType int `gorm:"not null"` | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package model | ||
|
|
||
| type FareRule struct { | ||
| Common | ||
|
|
||
| RouteID string `gorm:"not null;index"` | ||
| Route *Route `gorm:"belongsTo;foreignKey:RouteID;references:RouteID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
|
||
| OriginID string `gorm:"not null;index"` | ||
| Origin *Stop `gorm:"belongsTo;foreignKey:OriginID;references:StopID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
|
||
| DestinationID string `gorm:"not null;index"` | ||
| Destination *Stop `gorm:"belongsTo;foreignKey:DestinationID;references:StopID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
|
||
| Price float64 `gorm:"not null"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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等の拡張に対応できなくなるため、設計意図を確認したいです。
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 本来は,子どもと大人で料金が異なる場合とかを想定してテーブル分かれてるんだけど,実データ見たところ一律料金だったため,テーブルを分ける必要は無いと判断. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package model | ||
|
|
||
| type Route struct { | ||
| Common | ||
|
|
||
| RouteID string `gorm:"not null;uniqueIndex"` | ||
| RouteShortName string `gorm:"not null"` | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package model | ||
|
|
||
| type Stop struct { | ||
| Common | ||
|
|
||
| StopID string `gorm:"not null;uniqueIndex"` | ||
| StopName string `gorm:"not null"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GTFS仕様上
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 今回の仕様には緯度経度は必要ないと判断. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package model | ||
|
|
||
| type StopTime struct { | ||
| Common | ||
|
|
||
| TripID string `gorm:"not null;index"` | ||
| Trip *Trip `gorm:"belongsTo;foreignKey:TripID;references:TripID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
Outdated
|
||
| ArrivalTime string `gorm:"not null"` | ||
| DepartureTime string `gorm:"not null"` | ||
| StopID string `gorm:"not null;index"` | ||
| Stop *Stop `gorm:"belongsTo;foreignKey:StopID;references:StopID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
|
||
| StopSequence int `gorm:"not null"` | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package model | ||
|
|
||
| type Trip struct { | ||
| Common | ||
|
|
||
| TripID string `gorm:"not null;uniqueIndex"` | ||
| RouteID string `gorm:"not null;index"` | ||
| Route *Route `gorm:"belongsTo;foreignKey:RouteID;references:RouteID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
Outdated
|
||
| ServiceID string `gorm:"not null;index"` | ||
| Calendar *Calendar `gorm:"belongsTo;foreignKey:ServiceID;references:ServiceID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"` | ||
|
hikaru-0602 marked this conversation as resolved.
Outdated
|
||
| DirectionID int `gorm:"not null"` | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| -- Create "calendars" table | ||
| CREATE TABLE "public"."calendars" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "service_id" text NOT NULL, | ||
| "monday" bigint NOT NULL, | ||
| "tuesday" bigint NOT NULL, | ||
| "wednesday" bigint NOT NULL, | ||
| "thursday" bigint NOT NULL, | ||
| "friday" bigint NOT NULL, | ||
| "saturday" bigint NOT NULL, | ||
| "sunday" bigint NOT NULL, | ||
| "start_date" text NOT NULL, | ||
| "end_date" text NOT NULL, | ||
| PRIMARY KEY ("id") | ||
| ); | ||
| -- Create index "idx_calendars_service_id" to table: "calendars" | ||
| CREATE UNIQUE INDEX "idx_calendars_service_id" ON "public"."calendars" ("service_id"); | ||
| -- Create "calendar_dates" table | ||
| CREATE TABLE "public"."calendar_dates" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "service_id" text NOT NULL, | ||
| "date" text NOT NULL, | ||
| "exception_type" bigint NOT NULL, | ||
| PRIMARY KEY ("id"), | ||
| CONSTRAINT "fk_calendar_dates_calendar" FOREIGN KEY ("service_id") REFERENCES "public"."calendars" ("service_id") ON UPDATE CASCADE ON DELETE CASCADE | ||
| ); | ||
| -- Create index "idx_calendar_dates_date" to table: "calendar_dates" | ||
| CREATE INDEX "idx_calendar_dates_date" ON "public"."calendar_dates" ("date"); | ||
| -- Create index "idx_calendar_dates_service_id" to table: "calendar_dates" | ||
| CREATE INDEX "idx_calendar_dates_service_id" ON "public"."calendar_dates" ("service_id"); | ||
| -- Create "stops" table | ||
| CREATE TABLE "public"."stops" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "stop_id" text NOT NULL, | ||
| "stop_name" text NOT NULL, | ||
| PRIMARY KEY ("id") | ||
| ); | ||
| -- Create index "idx_stops_stop_id" to table: "stops" | ||
| CREATE UNIQUE INDEX "idx_stops_stop_id" ON "public"."stops" ("stop_id"); | ||
| -- Create "routes" table | ||
| CREATE TABLE "public"."routes" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "route_id" text NOT NULL, | ||
| "route_short_name" text NOT NULL, | ||
| PRIMARY KEY ("id") | ||
| ); | ||
| -- Create index "idx_routes_route_id" to table: "routes" | ||
| CREATE UNIQUE INDEX "idx_routes_route_id" ON "public"."routes" ("route_id"); | ||
| -- Create "fare_rules" table | ||
| CREATE TABLE "public"."fare_rules" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "route_id" text NOT NULL, | ||
| "origin_id" text NOT NULL, | ||
| "destination_id" text NOT NULL, | ||
| "price" numeric NOT NULL, | ||
| PRIMARY KEY ("id"), | ||
| CONSTRAINT "fk_fare_rules_destination" FOREIGN KEY ("destination_id") REFERENCES "public"."stops" ("stop_id") ON UPDATE CASCADE ON DELETE CASCADE, | ||
| CONSTRAINT "fk_fare_rules_origin" FOREIGN KEY ("origin_id") REFERENCES "public"."stops" ("stop_id") ON UPDATE CASCADE ON DELETE CASCADE, | ||
| CONSTRAINT "fk_fare_rules_route" FOREIGN KEY ("route_id") REFERENCES "public"."routes" ("route_id") ON UPDATE CASCADE ON DELETE CASCADE | ||
| ); | ||
| -- Create index "idx_fare_rules_destination_id" to table: "fare_rules" | ||
| CREATE INDEX "idx_fare_rules_destination_id" ON "public"."fare_rules" ("destination_id"); | ||
| -- Create index "idx_fare_rules_origin_id" to table: "fare_rules" | ||
| CREATE INDEX "idx_fare_rules_origin_id" ON "public"."fare_rules" ("origin_id"); | ||
| -- Create index "idx_fare_rules_route_id" to table: "fare_rules" | ||
| CREATE INDEX "idx_fare_rules_route_id" ON "public"."fare_rules" ("route_id"); | ||
| -- Create "trips" table | ||
| CREATE TABLE "public"."trips" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "trip_id" text NOT NULL, | ||
| "route_id" text NOT NULL, | ||
| "service_id" text NOT NULL, | ||
| "direction_id" bigint NOT NULL, | ||
| PRIMARY KEY ("id"), | ||
| CONSTRAINT "fk_trips_calendar" FOREIGN KEY ("service_id") REFERENCES "public"."calendars" ("service_id") ON UPDATE CASCADE ON DELETE CASCADE, | ||
| CONSTRAINT "fk_trips_route" FOREIGN KEY ("route_id") REFERENCES "public"."routes" ("route_id") ON UPDATE CASCADE ON DELETE CASCADE | ||
| ); | ||
| -- Create index "idx_trips_route_id" to table: "trips" | ||
| CREATE INDEX "idx_trips_route_id" ON "public"."trips" ("route_id"); | ||
| -- Create index "idx_trips_service_id" to table: "trips" | ||
| CREATE INDEX "idx_trips_service_id" ON "public"."trips" ("service_id"); | ||
| -- Create index "idx_trips_trip_id" to table: "trips" | ||
| CREATE UNIQUE INDEX "idx_trips_trip_id" ON "public"."trips" ("trip_id"); | ||
| -- Create "stop_times" table | ||
| CREATE TABLE "public"."stop_times" ( | ||
| "id" uuid NOT NULL DEFAULT gen_random_uuid(), | ||
| "created_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "updated_at" timestamptz NULL DEFAULT CURRENT_TIMESTAMP, | ||
| "trip_id" text NOT NULL, | ||
| "arrival_time" text NOT NULL, | ||
| "departure_time" text NOT NULL, | ||
| "stop_id" text NOT NULL, | ||
| "stop_sequence" bigint NOT NULL, | ||
| PRIMARY KEY ("id"), | ||
| CONSTRAINT "fk_stop_times_stop" FOREIGN KEY ("stop_id") REFERENCES "public"."stops" ("stop_id") ON UPDATE CASCADE ON DELETE CASCADE, | ||
| CONSTRAINT "fk_stop_times_trip" FOREIGN KEY ("trip_id") REFERENCES "public"."trips" ("trip_id") ON UPDATE CASCADE ON DELETE CASCADE | ||
| ); | ||
| -- Create index "idx_stop_times_stop_id" to table: "stop_times" | ||
| CREATE INDEX "idx_stop_times_stop_id" ON "public"."stop_times" ("stop_id"); | ||
| -- Create index "idx_stop_times_trip_id" to table: "stop_times" | ||
| CREATE INDEX "idx_stop_times_trip_id" ON "public"."stop_times" ("trip_id"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| h1:mQA8+6XzgUFnR6Z3XZPxHD6GVSUJkrzddFL0jnGEnxs= | ||
| h1:D5+i7UkpjX21CwSfHPnweaD2G/XBWhvNtDxh558HwkY= | ||
| 20260510075358_baseline.sql h1:S1fQ5KJJJ/pulk/6WuV0GWMpC7jrMdg8uFGScIAr18A= | ||
| 20260510085829.sql h1:Jo1Alddu/vC51J4L/XttheZYY7FERVzLgRQLPStkHwk= | ||
| 20260716124002.sql h1:QVA3ZUNeL5M7ohqzdf7ZQ6RefAuQ5UGD1/SKZIje0OU= | ||
| 20260820171158_add_gtfs.sql h1:bqlu65oO9vfinAtbIXE7Mg5j3bbm9npUAPk9po9kRc0= |
Uh oh!
There was an error while loading. Please reload this page.