-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13990 from transcom/MAIN-B-21509-DB-Add-POE-and-POD
MAIN-B-21509
- Loading branch information
Showing
11 changed files
with
643 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
migrations/app/schema/20241023184337_create_ports_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE IF NOT EXISTS ports ( | ||
id uuid NOT NULL, | ||
port_code varchar(4) NOT NULL, | ||
port_type varchar(1) NOT NULL, | ||
port_name varchar(100) NOT NULL, | ||
created_at timestamp NOT NULL DEFAULT NOW(), | ||
updated_at timestamp NOT NULL DEFAULT NOW(), | ||
CONSTRAINT port_pkey PRIMARY KEY(id), | ||
CONSTRAINT unique_port_code UNIQUE (port_code), | ||
CONSTRAINT chk_port_type CHECK (port_type IN ('A', 'S', 'B')) | ||
); | ||
COMMENT ON TABLE ports IS 'Stores ports identification data'; | ||
COMMENT ON COLUMN ports.port_code IS 'The 4 digit port code'; | ||
COMMENT ON COLUMN ports.port_type IS 'The 1 char port type A, S, or B'; | ||
COMMENT ON COLUMN ports.port_name IS 'The name of the port'; | ||
ALTER TABLE mto_service_items ADD COLUMN IF NOT EXISTS poe_location_id uuid; | ||
ALTER TABLE mto_service_items ADD CONSTRAINT fk_poe_location_id FOREIGN KEY (poe_location_id) REFERENCES ports (id); | ||
ALTER TABLE mto_service_items ADD COLUMN IF NOT EXISTS pod_location_id uuid; | ||
ALTER TABLE mto_service_items ADD CONSTRAINT fk_pod_location_id FOREIGN KEY (pod_location_id) REFERENCES ports (id); | ||
COMMENT ON COLUMN mto_service_items.poe_location_id IS 'Stores the POE location id for port of embarkation'; | ||
COMMENT ON COLUMN mto_service_items.pod_location_id IS 'Stores the POD location id for port of debarkation'; |
22 changes: 22 additions & 0 deletions
22
migrations/app/schema/20241023184350_create_port_locations_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
CREATE TABLE IF NOT EXISTS port_locations ( | ||
id uuid NOT NULL, | ||
port_id uuid NOT NULL | ||
CONSTRAINT fk_port_id_port REFERENCES ports (id), | ||
cities_id uuid NOT NULL | ||
CONSTRAINT fk_cities_id_re_cities REFERENCES re_cities (id), | ||
us_post_region_cities_id uuid NOT NULL | ||
CONSTRAINT fk_us_post_region_cities_id_us_post_region_cities REFERENCES us_post_region_cities (id), | ||
country_id uuid NOT NULL | ||
CONSTRAINT fk_country_id_re_countries REFERENCES re_countries (id), | ||
is_active bool DEFAULT TRUE, | ||
created_at timestamp NOT NULL DEFAULT NOW(), | ||
updated_at timestamp NOT NULL DEFAULT NOW(), | ||
CONSTRAINT port_locations_pkey PRIMARY KEY(id) | ||
); | ||
|
||
COMMENT ON TABLE port_locations IS 'Stores the port location information'; | ||
COMMENT ON COLUMN port_locations.port_id IS 'The ID for the port code references port'; | ||
COMMENT ON COLUMN port_locations.cities_id IS 'The ID of the city'; | ||
COMMENT ON COLUMN port_locations.us_post_region_cities_id IS 'The ID of the us postal regional city'; | ||
COMMENT ON COLUMN port_locations.country_id IS 'The ID for the country'; | ||
COMMENT ON COLUMN port_locations.is_active IS 'Bool for the active flag'; |
469 changes: 469 additions & 0 deletions
469
migrations/app/schema/20241023184437_insert_ports.up.sql
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
migrations/app/schema/20241120221040_change_port_location_fk_to_correct_table.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--POE Location columns should reference PORT_LOCATIONS table | ||
ALTER TABLE mto_service_items DROP CONSTRAINT fk_poe_location_id; | ||
ALTER TABLE mto_service_items DROP CONSTRAINT fk_pod_location_id; | ||
ALTER TABLE mto_service_items ADD CONSTRAINT fk_poe_location_id FOREIGN KEY (poe_location_id) REFERENCES port_locations (id); | ||
ALTER TABLE mto_service_items ADD CONSTRAINT fk_pod_location_id FOREIGN KEY (pod_location_id) REFERENCES port_locations (id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package models | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
) | ||
|
||
// PortType represents the type of port | ||
type PortType string | ||
|
||
// String is a string PortType | ||
func (p PortType) String() string { | ||
return string(p) | ||
} | ||
|
||
const ( | ||
PortTypeAir PortType = "A" | ||
PortTypeSurface PortType = "S" | ||
PortTypeBoth PortType = "B" | ||
) | ||
|
||
type Port struct { | ||
ID uuid.UUID `json:"id" db:"id" rw:"r"` | ||
PortCode string `json:"port_code" db:"port_code" rw:"r"` | ||
PortType PortType `json:"port_type" db:"port_type" rw:"r"` | ||
PortName string `json:"port_name" db:"port_name" rw:"r"` | ||
CreatedAt time.Time `json:"created_at" db:"created_at" rw:"r"` | ||
UpdatedAt time.Time `json:"updated_at" db:"updated_at" rw:"r"` | ||
} | ||
|
||
func (p Port) TableName() string { | ||
return "ports" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package models | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gobuffalo/pop/v6" | ||
"github.com/gobuffalo/validate/v3" | ||
"github.com/gobuffalo/validate/v3/validators" | ||
"github.com/gofrs/uuid" | ||
) | ||
|
||
type PortLocation struct { | ||
ID uuid.UUID `json:"id" db:"id"` | ||
PortId uuid.UUID `json:"port_id" db:"port_id"` | ||
CitiesId uuid.UUID `json:"cities_id" db:"cities_id"` | ||
UsPostRegionCitiesId uuid.UUID `json:"us_post_region_cities_id" db:"us_post_region_cities_id"` | ||
CountryId uuid.UUID `json:"country_id" db:"country_id"` | ||
IsActive *bool `json:"is_active" db:"is_active"` | ||
CreatedAt time.Time `json:"created_at" db:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at" db:"updated_at"` | ||
} | ||
|
||
func (l PortLocation) TableName() string { | ||
return "port_locations" | ||
} | ||
|
||
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. | ||
func (p *PortLocation) Validate(_ *pop.Connection) (*validate.Errors, error) { | ||
return validate.Validate( | ||
&validators.UUIDIsPresent{Field: p.PortId, Name: "PortID"}, | ||
&validators.UUIDIsPresent{Field: p.CitiesId, Name: "CitiesID"}, | ||
&validators.UUIDIsPresent{Field: p.UsPostRegionCitiesId, Name: "UsPostRegionCitiesID"}, | ||
&validators.UUIDIsPresent{Field: p.CountryId, Name: "CountryID"}, | ||
), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package models_test | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/gofrs/uuid" | ||
|
||
"github.com/transcom/mymove/pkg/models" | ||
) | ||
|
||
func (suite *ModelSuite) TestPortLocationValidation() { | ||
suite.Run("test valid PortLocation", func() { | ||
validPortLocation := models.PortLocation{ | ||
ID: uuid.Must(uuid.NewV4()), | ||
PortId: uuid.Must(uuid.NewV4()), | ||
CitiesId: uuid.Must(uuid.NewV4()), | ||
UsPostRegionCitiesId: uuid.Must(uuid.NewV4()), | ||
CountryId: uuid.Must(uuid.NewV4()), | ||
CreatedAt: time.Now(), | ||
UpdatedAt: time.Now(), | ||
} | ||
expErrors := map[string][]string{} | ||
suite.verifyValidationErrors(&validPortLocation, expErrors) | ||
}) | ||
|
||
suite.Run("test missing required fields", func() { | ||
invalidPortLocation := models.PortLocation{ | ||
ID: uuid.Must(uuid.NewV4()), | ||
CreatedAt: time.Now(), | ||
UpdatedAt: time.Now(), | ||
} | ||
|
||
expErrors := map[string][]string{ | ||
"port_id": {"PortID can not be blank."}, | ||
"cities_id": {"CitiesID can not be blank."}, | ||
"us_post_region_cities_id": {"UsPostRegionCitiesID can not be blank."}, | ||
"country_id": {"CountryID can not be blank."}, | ||
} | ||
|
||
suite.verifyValidationErrors(&invalidPortLocation, expErrors) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters