[Scala] BootStrap only loads first table

110 views
Skip to first unread message

Matt Raible

unread,
Oct 24, 2011, 6:01:29 PM10/24/11
to play-fr...@googlegroups.com
Hello all,

I have the following BootStrap.scala class in my project that I'm using to load default data:

class BootStrap extends Job {

override def doJob() {

import models._
import play.test._

// Import initial data if the database is empty
if (Athlete.count().single() == 0) {
Yaml[List[Any]]("initial-data.yml").foreach {
_ match {
case a: Athlete => Athlete.create(a)
case w: Workout => Workout.create(w)
case c: Comment => Comment.create(c)
}
}
}
}
}

For some reason, only my "athlete" table is getting populated and the others aren't. I tried turning on debugging and trace, but nothing shows up in the logs.

This was working fine when connecting to "db=mem", but since I've changed to PostgreSQL, this behavior is happening. Below is my initial-data.yml:

- !!models.Athlete
id: !!Id[Long] 1
email: mra...@gmail.com
password: beer
firstName: Matt
lastName: Raible

- !!models.Athlete
id: !!Id[Long] 2
email: trishm...@gmail.com
password: whiskey
firstName: Trish
lastName: McGinity

- !!models.Workout
id: !!Id[Long] 1
title: Chainsaw Trail
distance: 7
duration: 90
athlete_id: 1
postedAt: 2011-10-13
description: >
A beautiful fall ride: cool breezes, awesome views and yellow leaves.

Would do it again in a heartbeat.

- !!models.Workout
id: !!Id[Long] 2
title: Monarch Lake Trail
distance: 4
duration: 90
athlete_id: 1
postedAt: 2011-10-15
description: >
A beautiful afternoon of hiking with fishing along the way.

- !!models.Workout
id: !!Id[Long] 3
title: Creekside to Flume to Chainsaw
distance: 12
duration: 150
athlete_id: 2
postedAt: 2011-10-16
description: >
Awesome morning ride through falling yellow leaves and cool fall breezes.

- !!models.Comment
id: !!NotAssigned
author: Jim
content: >
Nice day for it!
postedAt: 2011-10-16
workout_id: 1

- !!models.Comment
id: !!NotAssigned
author: Joe
content: >
Love that trail.
postedAt: 2011-10-15
workout_id: 2


Matt Raible

unread,
Oct 25, 2011, 1:36:38 AM10/25/11
to play-framework
AFAICT, this is happening because an insert statement is failing into
PostgreSQL. I only know this from looking at PostgreSQL logs. Does
Anorm have a way of printing these types of issues or at least
throwing exceptions?

On Oct 24, 4:01 pm, Matt Raible <mrai...@gmail.com> wrote:
> Hello all,
>
> I have the following BootStrap.scala class in my project that I'm using to load default data:
>
> class BootStrap extends Job {
>
>   override def doJob() {
>
>     import models._
>     import play.test._
>
>     // Import initial data if the database is empty
>     if (Athlete.count().single() == 0) {
>       Yaml[List[Any]]("initial-data.yml").foreach {
>         _ match {
>           case a: Athlete => Athlete.create(a)
>           case w: Workout => Workout.create(w)
>           case c: Comment => Comment.create(c)
>         }
>       }
>     }
>   }
>
> }
>
> For some reason, only my "athlete" table is getting populated and the others aren't. I tried turning on debugging and trace, but nothing shows up in the logs.
>
> This was working fine when connecting to "db=mem", but since I've changed to PostgreSQL, this behavior is happening. Below is my initial-data.yml:
>
> - !!models.Athlete
>     id:             !!Id[Long] 1
>     email:          mrai...@gmail.com
>     password:       beer
>     firstName:      Matt
>     lastName:       Raible
>
> - !!models.Athlete
>     id:             !!Id[Long] 2
>     email:          trishmcgin...@gmail.com

Matt Raible

unread,
Oct 25, 2011, 9:18:55 PM10/25/11
to play-fr...@googlegroups.com
I was able to solve this issue by cloning play-scala on GitHub, building it locally and then creating a symlink from my modules directory to the compiled project.

$ ll modules/
total 8
drwxr-xr-x  12 mraible  staff   408B Oct 12 09:30 coffee-1.0
drwxr-xr-x  10 mraible  staff   340B Oct 12 09:29 less-0.3.compatibility
lrwxr-xr-x   1 mraible  staff    29B Oct 25 18:02 scala-0.9.1 -> /Users/mraible/dev/play-scala

I'm guessing this was fixed in August by the following commit:


What's the best way to go about using this version of play-scala? I realize I could setup a local module, but that's not going to help me much when I deploy to Heroku.

Is it possible to get a new release of play-scala?

Thanks,

Matt

Matt Raible

unread,
Oct 25, 2011, 10:26:46 PM10/25/11
to play-fr...@googlegroups.com

Figured it out. In dependencies.yml:

- upgrades -> scala 0.9.1-20111025

repositories:
- upgrades:
type: http
artifact: "http://static.raibledesigns.com/[module]-[revision].zip"
contains:
- upgrades -> *

Still interested in an answer to the following question...

Manuel Bernhardt

unread,
Oct 27, 2011, 3:10:37 AM10/27/11
to play-fr...@googlegroups.com
>> Is it possible to get a new release of play-scala?
Yes please! Guys, 0.9.1 was released in May.
> --
> You received this message because you are subscribed to the Google Groups "play-framework" group.
> To post to this group, send email to play-fr...@googlegroups.com.
> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>
Reply all
Reply to author
Forward
0 new messages