mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 14:35:52 +01:00
Refactor database schema.
This commit is contained in:
@@ -3,8 +3,7 @@ package model
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Accounts extends Table[Account]("ACCOUNT") {
|
||||
def userId = column[Long]("USER_ID", O AutoInc)
|
||||
def userName = column[String]("USER_NAME")
|
||||
def userName = column[String]("USER_NAME", O PrimaryKey)
|
||||
def mailAddress = column[String]("MAIL_ADDRESS")
|
||||
def password = column[String]("PASSWORD")
|
||||
def userType = column[Int]("USER_TYPE")
|
||||
@@ -12,12 +11,11 @@ object Accounts extends Table[Account]("ACCOUNT") {
|
||||
def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Date]("UPDATED_DATE")
|
||||
def lastLoginDate = column[java.sql.Date]("LAST_LOGIN_DATE")
|
||||
def * = userId.? ~ userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> (Account, Account.unapply _)
|
||||
def ins = userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> ({ t => Account(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Account) => Some((o.userName, o.mailAddress, o.password, o.userType, o.url, o.registeredDate, o.updatedDate, o.lastLoginDate))})
|
||||
def * = userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> (Account, Account.unapply _)
|
||||
// def ins = userName ~ mailAddress ~ password ~ userType ~ url.? ~ registeredDate ~ updatedDate ~ lastLoginDate.? <> ({ t => Account(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Account) => Some((o.userName, o.mailAddress, o.password, o.userType, o.url, o.registeredDate, o.updatedDate, o.lastLoginDate))})
|
||||
}
|
||||
|
||||
case class Account(
|
||||
userId: Option[Long],
|
||||
userName: String,
|
||||
mailAddress: String,
|
||||
password: String,
|
||||
@@ -32,8 +30,8 @@ class AccountDao {
|
||||
import Database.threadLocalSession
|
||||
|
||||
// def insert(o: Account): Account = Accounts.ins returning Accounts.* insert o
|
||||
def insert(o: Account): Long = Accounts.ins returning Accounts.userId insert o
|
||||
def insert(o: Account): Long = Accounts.* insert o
|
||||
|
||||
def select(key: Long): Option[Account] = Query(Accounts) filter(_.userId is key.bind) firstOption
|
||||
def select(key: String): Option[Account] = Query(Accounts) filter(_.userName is key.bind) firstOption
|
||||
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package model
|
||||
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Projects extends Table[Project]("PROJECT") {
|
||||
def projectId = column[Long]("PROJECT_ID", O AutoInc)
|
||||
def projectName= column[String]("PROJECT_NAME")
|
||||
def userId = column[Long]("USER_ID")
|
||||
def projectType = column[Int]("PROJECT_TYPE") // TODO should be sealed?
|
||||
def description = column[String]("DESCRIPTION")
|
||||
def defaultBranch = column[String]("DEFAULT_BRANCH")
|
||||
def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Date]("UPDATED_DATE")
|
||||
def lastActivityDate = column[java.sql.Date]("LAST_ACTIVITY_DATE")
|
||||
def * = projectId.? ~ projectName ~ userId ~ projectType ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Project, Project.unapply _)
|
||||
def ins = projectName ~ userId ~ projectType ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> ({ t => Project(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Project) => Some((o.projectName, o.userId, o.projectType, o.description, o.defaultBranch, o.registeredDate, o.updatedDate, o.lastActivityDate))})
|
||||
}
|
||||
|
||||
case class Project(
|
||||
projectId: Option[Long],
|
||||
projectName: String,
|
||||
userId: Long,
|
||||
projectType: Int,
|
||||
description: Option[String],
|
||||
defaultBranch: String,
|
||||
registeredDate: java.sql.Date,
|
||||
updatedDate: java.sql.Date,
|
||||
lastActivityDate: java.sql.Date
|
||||
)
|
||||
27
src/main/scala/model/Repository.scala
Normal file
27
src/main/scala/model/Repository.scala
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import scala.slick.driver.H2Driver.simple._
|
||||
|
||||
object Repositories extends Table[Repository]("REPOSITORY") {
|
||||
def repositoryName= column[String]("REPOSITORY_NAME", O PrimaryKey)
|
||||
def userName = column[String]("USER_NAME", O PrimaryKey)
|
||||
def repositoryType = column[Int]("REPOSITORY_TYPE") // TODO should be sealed?
|
||||
def description = column[String]("DESCRIPTION")
|
||||
def defaultBranch = column[String]("DEFAULT_BRANCH")
|
||||
def registeredDate = column[java.sql.Date]("REGISTERED_DATE") // TODO convert java.util.Date later
|
||||
def updatedDate = column[java.sql.Date]("UPDATED_DATE")
|
||||
def lastActivityDate = column[java.sql.Date]("LAST_ACTIVITY_DATE")
|
||||
def * = repositoryName ~ userName ~ repositoryType ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> (Repository, Repository.unapply _)
|
||||
// def ins = repositoryName ~ userName ~ repositoryType ~ description.? ~ defaultBranch ~ registeredDate ~ updatedDate ~ lastActivityDate <> ({ t => Project(None, t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8)}, { (o: Project) => Some((o.projectName, o.userId, o.projectType, o.description, o.defaultBranch, o.registeredDate, o.updatedDate, o.lastActivityDate))})
|
||||
}
|
||||
|
||||
case class Repository(
|
||||
repositoryName: String,
|
||||
userName: String,
|
||||
repositoryType: Int,
|
||||
description: Option[String],
|
||||
defaultBranch: String,
|
||||
registeredDate: java.sql.Date,
|
||||
updatedDate: java.sql.Date,
|
||||
lastActivityDate: java.sql.Date
|
||||
)
|
||||
Reference in New Issue
Block a user