Skip to content

Commit

Permalink
fix: change table column name
Browse files Browse the repository at this point in the history
  • Loading branch information
Tennessine699 committed Oct 14, 2024
1 parent 5e5e98d commit ca42f65
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 103 deletions.
48 changes: 24 additions & 24 deletions internal/infrastructure/migration/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func v3() *gormigrate.Migration {

for _, contest := range contests {
contestLink := v3ContestLink{
ID: contest.ID,
Order: 0,
Link: contest.Link,
ContestID: contest.ID,
Order: 0,
Link: contest.Link,
}
if err := db.Create(&contestLink).Error; err != nil {
return err
Expand All @@ -51,9 +51,9 @@ func v3() *gormigrate.Migration {

for _, contestTeam := range contestTeams {
teamLink := v3ContestTeamLink{
ID: contestTeam.ID,
Order: 0,
Link: contestTeam.Link,
ContestTeamID: contestTeam.ID,
Order: 0,
Link: contestTeam.Link,
}
if err := db.Create(&teamLink).Error; err != nil {
return err
Expand All @@ -74,9 +74,9 @@ func v3() *gormigrate.Migration {

for _, group := range groups {
groupLink := v3GroupLink{
ID: group.GroupID,
Order: 0,
Link: group.Link,
GroupID: group.GroupID,
Order: 0,
Link: group.Link,
}
if err := db.Create(&groupLink).Error; err != nil {
return err
Expand All @@ -97,9 +97,9 @@ func v3() *gormigrate.Migration {

for _, project := range projects {
projectLink := v3ProjectLink{
ID: project.ID,
Order: 0,
Link: project.Link,
ProjectID: project.ID,
Order: 0,
Link: project.Link,
}
if err := db.Create(&projectLink).Error; err != nil {
return err
Expand Down Expand Up @@ -134,9 +134,9 @@ func (*v3OldContest) TableName() string {
}

type v3ContestLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
ContestID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*v3ContestLink) TableName() string {
Expand All @@ -161,9 +161,9 @@ func (*v3OldContestTeam) TableName() string {
}

type v3ContestTeamLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
ContestTeamID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*v3ContestTeamLink) TableName() string {
Expand All @@ -184,9 +184,9 @@ func (*v3OldGroup) TableName() string {
}

type v3GroupLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
GroupID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*v3GroupLink) TableName() string {
Expand All @@ -211,9 +211,9 @@ func (*v3OldProject) TableName() string {
}

type v3ProjectLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
ProjectID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*v3ProjectLink) TableName() string {
Expand Down
28 changes: 14 additions & 14 deletions internal/infrastructure/repository/contest_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (r *ContestRepository) getContest(ctx context.Context, contestID uuid.UUID)
contestLinks := make([]*model.ContestLink, 0)
if err := r.h.
WithContext(ctx).
Where(&model.ContestLink{ID: contestID}).
Where(&model.ContestLink{ContestID: contestID}).
Find(&contestLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down Expand Up @@ -122,7 +122,7 @@ func (r *ContestRepository) CreateContest(ctx context.Context, args *repository.
for i, link := range args.Links {
if err := tx.
WithContext(ctx).
Create(&model.ContestLink{ID: contest.ID, Order: i, Link: link}).
Create(&model.ContestLink{ContestID: contest.ID, Order: i, Link: link}).
Error; err != nil {
return err
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func (r *ContestRepository) UpdateContest(ctx context.Context, contestID uuid.UU
if afterLinks, ok := args.Links.V(); ok {
if err := r.h.
WithContext(ctx).
Where(&model.ContestLink{ID: contestID}).
Where(&model.ContestLink{ContestID: contestID}).
Find(&contestLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down Expand Up @@ -225,7 +225,7 @@ func (r *ContestRepository) UpdateContest(ctx context.Context, contestID uuid.UU
for i, link := range changeLinks {
if err := tx.
WithContext(ctx).
Where(&model.ContestLink{ID: contestID, Order: i}).
Where(&model.ContestLink{ContestID: contestID, Order: i}).
Updates(&model.ContestLink{Link: link}).
Error; err != nil {
return err
Expand All @@ -238,7 +238,7 @@ func (r *ContestRepository) UpdateContest(ctx context.Context, contestID uuid.UU
for _, order := range removeLinks {
if err := tx.
WithContext(ctx).
Where(&model.ContestLink{ID: contestID, Order: order}).
Where(&model.ContestLink{ContestID: contestID, Order: order}).
Delete(&model.ContestLink{}).
Error; err != nil {
return err
Expand All @@ -251,7 +251,7 @@ func (r *ContestRepository) UpdateContest(ctx context.Context, contestID uuid.UU
for i, insertLink := range insertLinks {
if err := tx.
WithContext(ctx).
Create(&model.ContestLink{ID: contestID, Order: i, Link: insertLink}).
Create(&model.ContestLink{ContestID: contestID, Order: i, Link: insertLink}).
Error; err != nil {
return err
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func (r *ContestRepository) DeleteContest(ctx context.Context, contestID uuid.UU

if err := tx.
WithContext(ctx).
Where(&model.ContestLink{ID: contestID}).
Where(&model.ContestLink{ContestID: contestID}).
Delete(&model.ContestLink{}).
Error; err != nil {
return err
Expand Down Expand Up @@ -402,7 +402,7 @@ func (r *ContestRepository) GetContestTeam(ctx context.Context, contestID uuid.U

if err := r.h.
WithContext(ctx).
Where(&model.ContestTeamLink{ID: teamID}).
Where(&model.ContestTeamLink{ContestID: teamID}).
Find(&teamLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down Expand Up @@ -472,7 +472,7 @@ func (r *ContestRepository) CreateContestTeam(ctx context.Context, contestID uui
for i, link := range _contestTeam.Links {
if err := tx.
WithContext(ctx).
Create(&model.ContestTeamLink{ID: contestTeam.ID, Order: i, Link: link}).
Create(&model.ContestTeamLink{ContestID: contestTeam.ID, Order: i, Link: link}).
Error; err != nil {
return err
}
Expand Down Expand Up @@ -529,7 +529,7 @@ func (r *ContestRepository) UpdateContestTeam(ctx context.Context, teamID uuid.U
if afterLinks, ok := args.Links.V(); ok {
if err := r.h.
WithContext(ctx).
Model(&model.ContestTeamLink{ID: teamID}).
Model(&model.ContestTeamLink{ContestID: teamID}).
Find(&teamLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down Expand Up @@ -580,7 +580,7 @@ func (r *ContestRepository) UpdateContestTeam(ctx context.Context, teamID uuid.U
for i, link := range changeLinks {
if err := tx.
WithContext(ctx).
Where(&model.ContestTeamLink{ID: teamID, Order: i}).
Where(&model.ContestTeamLink{ContestID: teamID, Order: i}).
Updates(&model.ContestTeamLink{Link: link}).
Error; err != nil {
return err
Expand All @@ -593,7 +593,7 @@ func (r *ContestRepository) UpdateContestTeam(ctx context.Context, teamID uuid.U
for _, order := range removeLinks {
if err := tx.
WithContext(ctx).
Where(&model.ContestTeamLink{ID: teamID, Order: order}).
Where(&model.ContestTeamLink{ContestID: teamID, Order: order}).
Delete(&model.ContestTeamLink{}).
Error; err != nil {
return err
Expand All @@ -606,7 +606,7 @@ func (r *ContestRepository) UpdateContestTeam(ctx context.Context, teamID uuid.U
for i, insertLink := range insertLinks {
if err := tx.
WithContext(ctx).
Create(&model.ContestTeamLink{ID: teamID, Order: i, Link: insertLink}).
Create(&model.ContestTeamLink{ContestID: teamID, Order: i, Link: insertLink}).
Error; err != nil {
return err
}
Expand Down Expand Up @@ -642,7 +642,7 @@ func (r *ContestRepository) DeleteContestTeam(ctx context.Context, contestID uui

if err := tx.
WithContext(ctx).
Where(&model.ContestTeamLink{ID: teamID}).
Where(&model.ContestTeamLink{ContestID: teamID}).
Delete(&model.ContestTeamLink{}).
Error; err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/repository/group_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (r *GroupRepository) GetGroup(ctx context.Context, groupID uuid.UUID) (*dom
groupLinks := make([]model.GroupLink, 0)
if err := r.h.
WithContext(ctx).
Where(&model.GroupLink{ID: groupID}).
Where(&model.GroupLink{GroupID: groupID}).
Find(&groupLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down
12 changes: 6 additions & 6 deletions internal/infrastructure/repository/model/contests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func (*Contest) TableName() string {
}

type ContestLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
ContestID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
// 256件とかリンク追加されても困るし小さくした方がいいか…?
// Order uint8 `gorm:"type:tinyint(1);not null;primaryKey"`
}
Expand Down Expand Up @@ -63,9 +63,9 @@ func (*ContestTeamUserBelonging) TableName() string {
}

type ContestTeamLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
ContestID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*ContestTeamLink) TableName() string {
Expand Down
6 changes: 3 additions & 3 deletions internal/infrastructure/repository/model/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func (*GroupUserAdmin) TableName() string {
}

type GroupLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
GroupID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*GroupLink) TableName() string {
Expand Down
6 changes: 3 additions & 3 deletions internal/infrastructure/repository/model/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ func (*ProjectMember) TableName() string {
}

type ProjectLink struct {
ID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
ProjectID uuid.UUID `gorm:"type:char(36);not null;primaryKey"`
Order int `gorm:"type:int;not null;primaryKey"`
Link string `gorm:"type:text;not null"`
}

func (*ProjectLink) TableName() string {
Expand Down
12 changes: 6 additions & 6 deletions internal/infrastructure/repository/project_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (r *ProjectRepository) GetProject(ctx context.Context, projectID uuid.UUID)
projectLinks := make([]model.ProjectLink, 0)
if err := r.h.
WithContext(ctx).
Where(&model.ProjectLink{ID: projectID}).
Where(&model.ProjectLink{ProjectID: projectID}).
Find(&projectLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down Expand Up @@ -147,7 +147,7 @@ func (r *ProjectRepository) CreateProject(ctx context.Context, args *repository.
for i, link := range args.Links {
if err := tx.
WithContext(ctx).
Create(&model.ProjectLink{ID: p.ID, Order: i, Link: link}).
Create(&model.ProjectLink{ProjectID: p.ID, Order: i, Link: link}).
Error; err != nil {
return err
}
Expand Down Expand Up @@ -200,7 +200,7 @@ func (r *ProjectRepository) UpdateProject(ctx context.Context, projectID uuid.UU
if afterLinks, ok := args.Links.V(); ok {
if err := r.h.
WithContext(ctx).
Where(&model.ProjectLink{ID: projectID}).
Where(&model.ProjectLink{ProjectID: projectID}).
Find(&projectLinks).
Error; err != nil {
if err != repository.ErrNotFound {
Expand Down Expand Up @@ -258,7 +258,7 @@ func (r *ProjectRepository) UpdateProject(ctx context.Context, projectID uuid.UU
for i, link := range changeLinks {
if err := tx.
WithContext(ctx).
Where(&model.ProjectLink{ID: projectID, Order: i}).
Where(&model.ProjectLink{ProjectID: projectID, Order: i}).
Updates(&model.ProjectLink{Link: link}).
Error; err != nil {
return err
Expand All @@ -271,7 +271,7 @@ func (r *ProjectRepository) UpdateProject(ctx context.Context, projectID uuid.UU
for _, order := range removeLinks {
if err := tx.
WithContext(ctx).
Where(&model.ProjectLink{ID: projectID, Order: order}).
Where(&model.ProjectLink{ProjectID: projectID, Order: order}).
Delete(&model.ProjectLink{}).
Error; err != nil {
return err
Expand All @@ -284,7 +284,7 @@ func (r *ProjectRepository) UpdateProject(ctx context.Context, projectID uuid.UU
for i, insertLink := range insertLinks {
if err := tx.
WithContext(ctx).
Create(&model.ProjectLink{ID: projectID, Order: i, Link: insertLink}).
Create(&model.ProjectLink{ProjectID: projectID, Order: i, Link: insertLink}).
Error; err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/pkgs/mockdata/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func CloneHandlerMockContestLinksByID() map[uuid.UUID][]string {
}

for _, link := range mockContestLinks {
hContestLinks[link.ID] = append(hContestLinks[link.ID], link.Link)
hContestLinks[link.ContestID] = append(hContestLinks[link.ContestID], link.Link)
}

return hContestLinks
Expand Down Expand Up @@ -166,7 +166,7 @@ func CloneHandlerMockContestTeamLinksByID() map[uuid.UUID][]string {
}

for _, link := range mockContestTeamLinks {
hContestTeamLinks[link.ID] = append(hContestTeamLinks[link.ID], link.Link)
hContestTeamLinks[link.ContestID] = append(hContestTeamLinks[link.ContestID], link.Link)
}

return hContestTeamLinks
Expand Down Expand Up @@ -316,7 +316,7 @@ func CloneHandlerMockGroupLinksByID() map[uuid.UUID][]string {
}

for _, link := range mockGroupLinks {
hGroupLinks[link.ID] = append(hGroupLinks[link.ID], link.Link)
hGroupLinks[link.GroupID] = append(hGroupLinks[link.GroupID], link.Link)
}

return hGroupLinks
Expand Down Expand Up @@ -425,7 +425,7 @@ func CloneHandlerMockProjectLinksByID() map[uuid.UUID][]string {
}

for _, link := range mockProjectLinks {
hProjectLinks[link.ID] = append(hProjectLinks[link.ID], link.Link)
hProjectLinks[link.ProjectID] = append(hProjectLinks[link.ProjectID], link.Link)
}

return hProjectLinks
Expand Down
Loading

0 comments on commit ca42f65

Please sign in to comment.