Skip to content
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

B 21489 Update schema to accommodate multiple transportation offices #14009

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions migrations/app/migrations_manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,7 @@
20240917165710_update_duty_locations_provides_services_counseling.up.sql
20240927145659_update_mobile_home_factor.up.sql
20240930171315_updatePostalCodeToGbloc233BGNC.up.sql
20240930224757_add_transportation_office_assignments.up.sql
20241001144741_update_boat_factor.up.sql
20241001174400_add_is_oconus_column.up.sql
20241001193619_market-code-enum.up.sql
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS public.transportation_office_assignments (
id uuid NOT NULL,
transportation_office_id uuid NOT NULL,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT null,
primary_office bool
);

INSERT INTO public.transportation_office_assignments SELECT id, transportation_office_id, created_at, updated_at FROM office_users;

UPDATE public.transportation_office_assignments toa SET primary_office = true FROM public.office_users ofusr WHERE ofusr.transportation_office_id = toa.transportation_office_id;
34 changes: 34 additions & 0 deletions pkg/models/transportation_office_assignments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package models

import (
"time"

"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
"github.com/gobuffalo/validate/v3/validators"
"github.com/gofrs/uuid"
)

// TransportationAssignment is the transportation office the OfficeUser is assigned to
type TransportationAssignment struct {
ID uuid.UUID `json:"id" db:"id"`
TransportationOfficeID uuid.UUID `json:"transportation_office_id" db:"transportation_office_id"`
TransportationOffice TransportationOffice `belongs_to:"transportation_office" fk_id:"transportation_office_id"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
PrimaryOffice bool `json:"primary_office" db:"primary_office"`
}

// TableName overrides the table name used by Pop.
func (o TransportationAssignment) TableName() string {
return "transportation_office_assignments"
}

type TransportationAssignments []TransportationAssignment

// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
func (o *TransportationAssignment) Validate(_ *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.UUIDIsPresent{Field: o.TransportationOfficeID, Name: "TransportationOfficeID"},
), nil
}