Browse files

BootMapper conveniences: allowing db.schema prop, default to snakifyi…

…ng column_names, printing sys.error for failed migrations
  • Loading branch information...
1 parent 4c97828 commit a8a93d14b82707a47f6f936ea4e9933f5b2bcc62 @ldeck committed Apr 28, 2012
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/main/scala/bootstrap/liftweb/BootMapper.scala
View
22 src/main/scala/bootstrap/liftweb/BootMapper.scala
@@ -21,15 +21,33 @@ object BootMapper {
val vendor = new StandardDBVendor(Props.get("db.driver") openOr "org.h2.Driver",
Props.get("db.url") openOr "jdbc:h2:lift_proto.db;AUTO_SERVER=TRUE",
Props.get("db.user"),
- Props.get("db.password"))
+ Props.get("db.password")
+ Props.get("db.schema"))
LiftRules.unloadHooks.append(vendor.closeAllConnections_! _)
DB.defineConnectionManager(DefaultConnectionIdentifier, vendor)
}
+ // Mapper default rules
+ MapperRules.columnName = (_,name) => StringHelpers.snakify(name)
+ MapperRules.tableName = (_,name) => StringHelpers.snakify(name)
+
// Use Lift's Mapper ORM to populate the database
// you don't need to use Mapper to use Lift... use
// any ORM you want
- Schemifier.schemify(true, Schemifier.infoF _, User)
+ val cmds = Schemifier.schemify(true, Schemifier.infoF _, User)
+ if (!cmds.isEmpty)
+ {
+ sys.error("Database scheme is out of date. The following is missing:\n" + cmds.mkString("\n"))
+ }
}
}
+
+class DBVendor(val driverName: String, val dbUrl: String, val dbUser: Box[String], val dbPassword: Box[String], val schemaName: Box[String] = Empty)
+ extends StandardDBVendor(driverName, dbUrl, dbUser, dbPassword)
+{
+ Class.forName(driverName)
+
+ override def newSuperConnection(name: ConnectionIdentifier) : Box[SuperConnection] =
+ newConnection(name).map(c => new SuperConnection(c, () => releaseConnection(c), tryo(schemaName openOr "PUBLIC")))
+}

0 comments on commit a8a93d1

Please sign in to comment.