forked from zutherb/blog-db-evolution-git-example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bernd Zuther
committed
Jun 10, 2013
1 parent
8008804
commit 182f871
Showing
19 changed files
with
300 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,15 @@ | ||
# Extracted from https://github.com/ulrich/macaron-factory/blob/master/.gitignore | ||
# Ignore all dotfiles... | ||
.* | ||
# except for .gitignore | ||
!.gitignore | ||
|
||
# Ignore Play! working directory # | ||
db | ||
eclipse | ||
lib | ||
log | ||
logs | ||
modules | ||
precompiled | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
test-result | ||
server.pid | ||
*.iml | ||
*.eml | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
blog-db-evolution-git-example | ||
============================= | ||
This is your new Play 2.1 application | ||
===================================== | ||
|
||
This file will be packaged with your application, when using `play dist`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import org.squeryl.adapters.{H2Adapter, PostgreSqlAdapter} | ||
import org.squeryl.internals.DatabaseAdapter | ||
import org.squeryl.{Session, SessionFactory} | ||
import play.api.db.DB | ||
import play.api.GlobalSettings | ||
|
||
import play.api.Application | ||
|
||
/** | ||
* @author zutherb | ||
*/ | ||
object Global extends GlobalSettings { | ||
|
||
override def onStart(app: Application) { | ||
SessionFactory.concreteFactory = app.configuration.getString("db.default.driver") match { | ||
case Some("org.h2.Driver") => Some(() => getSession(new H2Adapter, app)) | ||
case Some("org.postgresql.Driver") => Some(() => getSession(new PostgreSqlAdapter, app)) | ||
case _ => sys.error("Database driver must be either org.h2.Driver or org.postgresql.Driver") | ||
} | ||
} | ||
|
||
def getSession(adapter:DatabaseAdapter, app: Application) = Session.create(DB.getConnection()(app), adapter) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package controllers | ||
|
||
import play.api.mvc._ | ||
import models.AppDB | ||
import org.squeryl.PrimitiveTypeMode._ | ||
|
||
object Application extends Controller { | ||
|
||
def index = Action { | ||
val entries = inTransaction { | ||
from(AppDB.entries)(entries => | ||
select(entries) | ||
).toList | ||
} | ||
Ok(views.html.index(entries)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package models | ||
|
||
import org.squeryl.{Schema, KeyedEntity} | ||
import java.sql.{Date, Timestamp} | ||
|
||
/** | ||
* @author zutherb | ||
*/ | ||
case class BlogEntry(val title: String, val content: String) extends KeyedEntity[Long] with java.io.Serializable { | ||
val id: Long = 0 | ||
val createdAt: Date = new Date(System.currentTimeMillis) | ||
|
||
override def toString = "{id : ${id}, title : ${title}, content : ${content}, createdAt : ${createdAt}}" | ||
} | ||
|
||
object AppDB extends Schema { | ||
|
||
val entries = table[BlogEntry]("entry") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
@(entries: List[models.BlogEntry]) | ||
|
||
@main("Welcome to Play 2.1") { | ||
|
||
<h1 class="text-warning">I am a wrong headline</h1> | ||
|
||
|
||
<ul> | ||
@for(entry <- entries) { | ||
<li>@entry.title</li> | ||
} | ||
</ul> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@(title: String)(content: Html) | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<title>@title</title> | ||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap.min.css")"> | ||
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/bootstrap-responsive.min.css")"> | ||
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")"> | ||
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript"></script> | ||
</head> | ||
<body> | ||
@content | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# This is the main configuration file for the application. | ||
# ~~~~~ | ||
|
||
# Secret key | ||
# ~~~~~ | ||
# The secret key is used to secure cryptographics functions. | ||
# If you deploy your application to several instances be sure to use the same key! | ||
application.secret="=g_oa/Ua5W``t8y>7uh?Cf?U72j63_;30pAkA>jDfUiy>sotlcuA[8F_rkf58y0e" | ||
|
||
# The application languages | ||
# ~~~~~ | ||
application.langs="en" | ||
|
||
# Global object class | ||
# ~~~~~ | ||
# Define the Global object class for this application. | ||
# Default to Global in the root package. | ||
# application.global=Global | ||
|
||
# Router | ||
# ~~~~~ | ||
# Define the Router object to use for this application. | ||
# This router will be looked up first when the application is starting up, | ||
# so make sure this is the entry point. | ||
# Furthermore, it's assumed your route file is named properly. | ||
# So for an application router like `my.application.Router`, | ||
# you may need to define a router file `conf/my.application.routes`. | ||
# Default to Routes in the root package (and conf/routes) | ||
# application.router=my.application.Routes | ||
|
||
# Database configuration | ||
# ~~~~~ | ||
# You can declare as many datasources as you want. | ||
# By convention, the default datasource is named `default` | ||
# | ||
db.default.driver=org.h2.Driver | ||
db.default.url="jdbc:h2:mem:play" | ||
db.default.user=sa | ||
db.default.password="" | ||
|
||
# Evolutions | ||
# ~~~~~ | ||
# You can disable evolutions if needed | ||
# evolutionplugin=disabled | ||
|
||
# Logger | ||
# ~~~~~ | ||
# You can also configure logback (http://logback.qos.ch/), by providing a logger.xml file in the conf directory . | ||
|
||
# Root logger: | ||
logger.root=ERROR | ||
|
||
# Logger used by the framework: | ||
logger.play=INFO | ||
|
||
# Logger provided to your application: | ||
logger.application=DEBUG | ||
|
||
#Port | ||
#~~~~ | ||
http.port=8080 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CREATE TABLE entry ( | ||
id SERIAL PRIMARY KEY, | ||
title VARCHAR(255) NOT NULL, | ||
content VARCHAR(255) NOT NULL, | ||
createdAt DATE | ||
); | ||
|
||
INSERT INTO entry (id, title, content, createdAt) VALUES (1, 'Entry 1', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', '2013-06-10') | ||
INSERT INTO entry (id, title, content, createdAt) VALUES (2, 'Entry 2', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', '2013-06-11') | ||
INSERT INTO entry (id, title, content, createdAt) VALUES (3, 'Entry 3', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', '2013-06-12') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Routes | ||
# This file defines all application routes (Higher priority routes first) | ||
# ~~~~ | ||
|
||
# Home page | ||
GET / controllers.Application.index | ||
|
||
# Map static resources from the /public folder to the /assets URL path | ||
GET /assets/*file controllers.Assets.at(path="/public", file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import sbt._ | ||
import Keys._ | ||
import play.Project._ | ||
|
||
object ApplicationBuild extends Build { | ||
|
||
val appName = "blog-db-evolution-git-example" | ||
val appVersion = "1.0-SNAPSHOT" | ||
|
||
val appDependencies = Seq( | ||
"org.squeryl" %% "squeryl" % "0.9.5-6", | ||
jdbc, | ||
anorm | ||
) | ||
|
||
|
||
val main = play.Project(appName, appVersion, appDependencies).settings( | ||
// Add your own project settings here | ||
) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=0.12.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Comment to get more information during initialization | ||
logLevel := Level.Warn | ||
|
||
// The Typesafe repository | ||
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" | ||
|
||
// Use the Play sbt plugin for Play projects | ||
addSbtPlugin("play" % "sbt-plugin" % "2.1.1") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package test | ||
|
||
import org.specs2.mutable._ | ||
|
||
import play.api.test._ | ||
import play.api.test.Helpers._ | ||
|
||
/** | ||
* Add your spec here. | ||
* You can mock out a whole application including requests, plugins etc. | ||
* For more information, consult the wiki. | ||
*/ | ||
class ApplicationSpec extends Specification { | ||
|
||
"Application" should { | ||
|
||
"send 404 on a bad request" in { | ||
running(FakeApplication()) { | ||
route(FakeRequest(GET, "/boum")) must beNone | ||
} | ||
} | ||
|
||
"render the index page" in { | ||
running(FakeApplication()) { | ||
val home = route(FakeRequest(GET, "/")).get | ||
|
||
status(home) must equalTo(OK) | ||
contentType(home) must beSome.which(_ == "text/html") | ||
contentAsString(home) must contain ("Your new application is ready.") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package test | ||
|
||
import org.specs2.mutable._ | ||
|
||
import play.api.test._ | ||
import play.api.test.Helpers._ | ||
import org.squeryl.PrimitiveTypeMode._ | ||
import play.api.test.TestServer | ||
|
||
/** | ||
* add your integration spec here. | ||
* An integration test will fire up a whole play application in a real (or headless) browser | ||
*/ | ||
class IntegrationSpec extends Specification { | ||
|
||
"Application" should { | ||
|
||
"work from within a browser" in { | ||
running(TestServer(3333), HTMLUNIT) { browser => | ||
|
||
browser.goTo("http://localhost:3333/") | ||
|
||
browser.pageSource must contain("Your new application is ready.") | ||
|
||
} | ||
} | ||
} | ||
|
||
} |