-
Notifications
You must be signed in to change notification settings - Fork 505
/
20220715_add_init_tables.go
124 lines (113 loc) · 3.65 KB
/
20220715_add_init_tables.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package migrationscripts
import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/migrationhelper"
"github.com/apache/incubator-devlake/plugins/github/models/migrationscripts/archived"
)
type addInitTables struct {
}
func (u *addInitTables) Up(basicRes context.BasicRes) errors.Error {
db := basicRes.GetDal()
err := db.DropTables(
&archived.GithubRepo{},
&archived.GithubConnection{},
&archived.GithubCommit{},
&archived.GithubRepoCommit{},
&archived.GithubPullRequest{},
&archived.GithubReviewer{},
&archived.GithubPrCommit{},
&archived.GithubPrLabel{},
&archived.GithubIssue{},
&archived.GithubIssueComment{},
&archived.GithubIssueEvent{},
&archived.GithubIssueLabel{},
&archived.GithubPrIssue{},
&archived.GithubCommitStat{},
&archived.GithubPrComment{},
&archived.GithubPrReview{},
&archived.GithubRepoAccount{},
&archived.GithubAccountOrg{},
&archived.GithubAccount{},
"_tool_github_users",
"_tool_github_milestones",
"_raw_github_api_issues",
"_raw_github_api_comments",
"_raw_github_api_commits",
"_raw_github_api_commit_stats",
"_raw_github_api_events",
"_raw_github_api_issues",
"_raw_github_api_pull_requests",
"_raw_github_api_pull_request_commits",
"_raw_github_api_pull_request_reviews",
"_raw_github_api_repositories",
"_raw_github_api_reviews",
)
// create connection
if err != nil {
return err
}
err = db.AutoMigrate(archived.GithubConnection{})
if err != nil {
return err
}
encodeKey := basicRes.GetConfig(plugin.EncodeKeyEnvStr)
connection := &archived.GithubConnection{}
connection.Endpoint = basicRes.GetConfig(`GITHUB_ENDPOINT`)
connection.Proxy = basicRes.GetConfig(`GITHUB_PROXY`)
connection.Token = basicRes.GetConfig(`GITHUB_AUTH`)
connection.Name = `GitHub`
if connection.Endpoint != `` && connection.Token != `` && encodeKey != `` {
// update from .env and save to db
err = db.Create(connection)
if err != nil {
return err
}
}
// create other table with connection id
err = migrationhelper.AutoMigrateTables(
basicRes,
&archived.GithubRepo{},
&archived.GithubCommit{},
&archived.GithubRepoCommit{},
&archived.GithubPullRequest{},
&archived.GithubReviewer{},
&archived.GithubPrComment{},
&archived.GithubPrCommit{},
&archived.GithubPrLabel{},
&archived.GithubIssue{},
&archived.GithubIssueComment{},
&archived.GithubIssueEvent{},
&archived.GithubIssueLabel{},
&archived.GithubAccount{},
&archived.GithubPrIssue{},
&archived.GithubCommitStat{},
&archived.GithubMilestone{},
&archived.GithubPrReview{},
&archived.GithubRepoAccount{},
&archived.GithubAccountOrg{},
&archived.GithubAccount{},
)
return err
}
func (*addInitTables) Version() uint64 {
return 20220715000001
}
func (*addInitTables) Name() string {
return "Github init schemas 20220707"
}