func()

in backend/plugins/bitbucket/models/migrationscripts/20230206_add_scope_and_transformation.go [105:197]


func (script *addScope20230206) Up(basicRes context.BasicRes) errors.Error {
	db := basicRes.GetDal()
	err := db.RenameColumn("_tool_bitbucket_repos", "owner_id", "owner")
	if err != nil {
		return err
	}

	// add `RepoId` as primary key
	err = migrationhelper.TransformTable(
		basicRes,
		script,
		"_tool_bitbucket_issues",
		func(s *archivedModel.BitbucketIssue) (*BitbucketIssue20230206, errors.Error) {
			dst := &BitbucketIssue20230206{
				ConnectionId:       s.ConnectionId,
				RepoId:             s.RepoId,
				BitbucketId:        s.BitbucketId,
				Number:             s.Number,
				State:              ``,
				StdState:           s.State,
				Title:              s.Title,
				Body:               s.Body,
				Priority:           s.Priority,
				Type:               s.Type,
				AuthorId:           s.AuthorId,
				AuthorName:         s.AuthorName,
				AssigneeId:         s.AssigneeId,
				AssigneeName:       s.AssigneeName,
				MilestoneId:        s.MilestoneId,
				LeadTimeMinutes:    s.LeadTimeMinutes,
				Url:                s.Url,
				ClosedAt:           s.ClosedAt,
				BitbucketCreatedAt: s.BitbucketCreatedAt,
				BitbucketUpdatedAt: s.BitbucketUpdatedAt,
				Severity:           s.Severity,
				Component:          s.Component,
				NoPKModel:          s.NoPKModel,
			}
			return dst, nil
		},
	)
	if err != nil {
		return err
	}

	// add `RepoId` as primary key
	err = migrationhelper.TransformTable(
		basicRes,
		script,
		"_tool_bitbucket_pull_requests",
		func(s *archivedModel.BitbucketPullRequest) (*BitbucketPullRequest20230206, errors.Error) {
			dst := &BitbucketPullRequest20230206{
				ConnectionId:       s.ConnectionId,
				RepoId:             s.RepoId,
				BitbucketId:        s.BitbucketId,
				Number:             s.Number,
				BaseRepoId:         s.BaseRepoId,
				HeadRepoId:         s.HeadRepoId,
				State:              s.State,
				Title:              s.Title,
				Description:        s.Description,
				BitbucketCreatedAt: s.BitbucketCreatedAt,
				BitbucketUpdatedAt: s.BitbucketUpdatedAt,
				ClosedAt:           s.ClosedAt,
				CommentCount:       s.CommentCount,
				Commits:            s.Commits,
				MergedAt:           s.MergedAt,
				Body:               s.Body,
				Type:               s.Type,
				Component:          s.Component,
				MergeCommitSha:     s.MergeCommitSha,
				HeadRef:            s.HeadRef,
				BaseRef:            s.BaseRef,
				BaseCommitSha:      s.BaseCommitSha,
				HeadCommitSha:      s.HeadCommitSha,
				Url:                s.Url,
				AuthorName:         s.AuthorName,
				AuthorId:           s.AuthorId,
				NoPKModel:          s.NoPKModel,
			}
			return dst, nil
		},
	)
	if err != nil {
		return err
	}

	return migrationhelper.AutoMigrateTables(
		basicRes,
		&BitbucketRepo20230206{},
		&archivedModel.BitbucketTransformationRule{},
	)
}