Skip to content

Commit

Permalink
adding first evolutions script.
Browse files Browse the repository at this point in the history
  • Loading branch information
phaus committed Jul 1, 2012
1 parent 0b38827 commit e04b44e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
!.gitignore

# Ignore Play! working directory #
db
db/h2
eclipse
log
logs
Expand Down
2 changes: 2 additions & 0 deletions app/models/Match.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import play.data.validation.Required;
Expand All @@ -15,6 +16,7 @@
* @author screencast
*/
@Entity
@Table(name="Matches")
public class Match extends Model {

@ManyToOne
Expand Down
13 changes: 9 additions & 4 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ application.name=kickster
# Otherwise set to prod.
application.mode=dev
%prod.application.mode=prod
%mysql.application.mode=dev

# Secret key
# ~~~~~
Expand Down Expand Up @@ -85,14 +86,18 @@ date.format=dd.MM.yyyy hh:mm
# db=mem
#

#db=fs
db=fs

db=${DATABASE_URL}
jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
jpa.ddl=update
%prod.db=${DATABASE_URL}
%prod.jpa.dialect=org.hibernate.dialect.PostgreSQLDialect
%prod.jpa.ddl=none

# To connect to a local MySQL5 database, use:
# db=mysql://user:pwd@host/database

%mysql.db=mysql://play:play@localhost/play_kickster
%mysql.jpa.ddl=update

#
# To connect to a local PostgreSQL9 database, use:
# db=postgres://user:pwd@host/database
Expand Down
57 changes: 57 additions & 0 deletions db/evolutions/1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Initial DB Setup

# --- !Ups

CREATE TABLE IF NOT EXISTS `Matches` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`date` date DEFAULT NULL,
`scoreTeam1` int(11) NOT NULL,
`scoreTeam2` int(11) NOT NULL,
`team1_id` bigint(20) DEFAULT NULL,
`team2_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `Player` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`score` int(11) NOT NULL,
PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `Team` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
);

CREATE TABLE IF NOT EXISTS `Team_Player` (
`teams_id` bigint(20) NOT NULL,
`players_id` bigint(20) NOT NULL,
PRIMARY KEY (`teams_id`,`players_id`)
);

ALTER TABLE `Matches`
ADD CONSTRAINT `FK95572113EC53FB47` FOREIGN KEY (`team1_id`) REFERENCES `Team` (`id`),
ADD CONSTRAINT `FK95572113EC546FA6` FOREIGN KEY (`team2_id`) REFERENCES `Team` (`id`);

ALTER TABLE `Team_Player`
ADD CONSTRAINT `FKD4E5F703EC71FBC5` FOREIGN KEY (`teams_id`) REFERENCES `Team` (`id`),
ADD CONSTRAINT `FKD4E5F703322211CD` FOREIGN KEY (`players_id`) REFERENCES `Player` (`id`);

# --- !Downs

ALTER TABLE `Matches`
DROP FOREIGN KEY `FK95572113EC53FB47`,
DROP FOREIGN KEY `FK95572113EC546FA6`;

ALTER TABLE `Team_Player`
DROP FOREIGN KEY `FKD4E5F703EC71FBC5`,
DROP FOREIGN KEY `FKD4E5F703322211CD`;

DROP TABLE `Matches`;

DROP TABLE `Player`;

DROP TABLE `Team`;

DROP TABLE `Team_Player`;

0 comments on commit e04b44e

Please sign in to comment.