(refs #1498) Fix record inserting and deletion of repository related tables

This commit is contained in:
Naoki Takezoe
2017-03-17 21:38:21 +09:00
parent 05739f60ce
commit f165e89a8d
2 changed files with 5 additions and 9 deletions

View File

@@ -1,13 +1,11 @@
package gitbucket.core.model
trait DeployKeyComponent { self: Profile =>
trait DeployKeyComponent extends TemplateComponent { self: Profile =>
import profile.api._
lazy val DeployKeys = TableQuery[DeployKeys]
class DeployKeys(tag: Tag) extends Table[DeployKey](tag, "DEPLOY_KEY") {
val userName = column[String]("USER_NAME")
val repositoryName = column[String]("REPOSITORY_NAME")
class DeployKeys(tag: Tag) extends Table[DeployKey](tag, "DEPLOY_KEY") with BasicTemplate {
val deployKeyId = column[Int]("DEPLOY_KEY_ID", O AutoInc)
val title = column[String]("TITLE")
val publicKey = column[String]("PUBLIC_KEY")

View File

@@ -73,6 +73,7 @@ trait RepositoryService { self: AccountService =>
val collaborators = Collaborators .filter(_.byRepository(oldUserName, oldRepositoryName)).list
val protectedBranches = ProtectedBranches .filter(_.byRepository(oldUserName, oldRepositoryName)).list
val protectedBranchContexts = ProtectedBranchContexts.filter(_.byRepository(oldUserName, oldRepositoryName)).list
val deployKeys = DeployKeys .filter(_.byRepository(oldUserName, oldRepositoryName)).list
Repositories.filter { t =>
(t.originUserName === oldUserName.bind) && (t.originRepositoryName === oldRepositoryName.bind)
@@ -112,6 +113,7 @@ trait RepositoryService { self: AccountService =>
CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
DeployKeys .insertAll(deployKeys .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
// Update source repository of pull requests
PullRequests.filter { t =>
@@ -126,11 +128,6 @@ trait RepositoryService { self: AccountService =>
userName = newUserName,
repositoryName = newRepositoryName
)) :_*)
IssueLabels.insertAll(issueLabels.map(x => x.copy(
labelId = newLabelMap(oldLabelMap(x.labelId)),
userName = newUserName,
repositoryName = newRepositoryName
)) :_*)
// TODO Drop transfered owner from collaborators?
Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
@@ -168,6 +165,7 @@ trait RepositoryService { self: AccountService =>
Milestones .filter(_.byRepository(userName, repositoryName)).delete
WebHooks .filter(_.byRepository(userName, repositoryName)).delete
WebHookEvents .filter(_.byRepository(userName, repositoryName)).delete
DeployKeys .filter(_.byRepository(userName, repositoryName)).delete
Repositories .filter(_.byRepository(userName, repositoryName)).delete
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME