Is there a way to bootstrap only data in the development environment

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Is there a way to bootstrap only data in the development environment

Cromer, Rick

Is there a way to configure the bootstrap.groovy class where the data is only loaded in development environment?  Maybe another set of data for test and not any in production.

 

Regards,
Rick Cromer

 

Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to bootstrap only data in the development environment

burtbeckwith
Sure - you can use GrailsUtil.getEnvironment() to determine whether you're in
development or production mode, e.g.:

import grails.util.GrailsUtil

class BootStrap {

   def init = { servletContext ->

      // insert data for all environments

      switch (GrailsUtil.environment) {
         case 'development':
            // insert development data
            break

         case 'production':
            // insert production data
            break
      }
   }

   def destroy = {}
}

Burt

On Thursday 28 February 2008 11:50:03 pm Cromer, Rick wrote:
> Is there a way to configure the bootstrap.groovy class where the data is
> only loaded in development environment?  Maybe another set of data for
> test and not any in production.
>
>
>
> Regards,
> Rick Cromer



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to bootstrap only data in the development environment

Tyler Williams
In reply to this post by Cromer, Rick
Sure thing, see the example below. Imports are there to demonstrate running the groovy console.

----------

import org.springframework.web.context.support.WebApplicationContextUtils
import org.codehaus.groovy.grails.commons.GrailsApplication;
import grails.util.GrailsUtil;
import groovy.ui.Console;

class BootStrap {
    def init = {servletContext ->
        // Only perform in dev
        if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
            // launch a groovy console
            def appCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)
            def grailsApp = appCtx.getBean(GrailsApplication.APPLICATION_ID);
            Binding b = new Binding();
            b.setVariable("ctx", appCtx);
            def console = new Console(grailsApp.classLoader, b);
            console.run()

            // Load some test data
            new Person(name: "Jim").save()
            new Person(name: "Sue").save()
        }
...


Cromer, Rick wrote
Is there a way to configure the bootstrap.groovy class where the data is
only loaded in development environment?  Maybe another set of data for
test and not any in production.

 

Regards,
Rick Cromer



 
Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to bootstrap only data in the development environment

Jason Morris-5
Slight variation on the same question - can you tell if a "create-drop" setup actually dropped the tables?

What I'm looking for is this:

In development, I want auto-recompile, but I also want to rebuild the db but only if the SCHEMA changed. I have quite a lot of data to bootstrap, and it makes startup slow to do that every time. But if the schema changes, I need to rebuild the db and reload the data. Grails seems to be able to detect a domain change while running, just not sure if it can detect it at startup.

At the moment I fudged it - I have dev setup as "update", and a "rebuild" env that is "create-drop". I only bootstrap the data in the "rebuild" env, and I only launch with that if I change the domain classes. Then I get much faster startup in dev most of the time. (I have to restart more often than I would like due to a couple of recompile bugs in one of the plugins, but faster startup is faster startup, no? This makes the difference of 60 to 90 seconds a pop).

How do other people handle this - seems like a pretty standard concept?

(I know I could protect all the data sections with an existence check first, but that is a bit tedious!)

Cheers

Jason

On Fri, Feb 29, 2008 at 5:04 AM, twilliams <[hidden email]> wrote:

Sure thing, see the example below. Imports are there to demonstrate running
the groovy console.

----------

import org.springframework.web.context.support.WebApplicationContextUtils
import org.codehaus.groovy.grails.commons.GrailsApplication;
import grails.util.GrailsUtil;
import groovy.ui.Console;

class BootStrap {
   def init = {servletContext ->
       // Only perform in dev
       if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
           // launch a groovy console
           def appCtx =
WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext)
           def grailsApp =
appCtx.getBean(GrailsApplication.APPLICATION_ID);
           Binding b = new Binding();
           b.setVariable("ctx", appCtx);
           def console = new Console(grailsApp.classLoader, b);
           console.run()

           // Load some test data
           new Person(name: "Jim").save()
           new Person(name: "Sue").save()
       }
...



Cromer, Rick wrote:
>
> Is there a way to configure the bootstrap.groovy class where the data is
> only loaded in development environment?  Maybe another set of data for
> test and not any in production.
>
>
>
> Regards,
> Rick Cromer
>
>
>
>
>
>
>

--
View this message in context: http://www.nabble.com/Is-there-a-way-to-bootstrap-only-data-in-the-development-environment-tp15752047p15752183.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|

Re: Is there a way to bootstrap only data in the development environment

SMcDowall

This maybe simplistic -- but if you know certain data should be there (i.e. you bootstrap it) -- why not just check the existence of a "known" "static" piece of data is?  If its not there one can (somewhat) assume the tables got dropped .. and you can reload...

Of course -- I thought Grails ALWAYS dropped/created the tables at launch time if you have "create-drop" specified ..  so the update method below seems reasonable.. but I maybe wrong about that.. interesting experiment..


Jason Morris-5 wrote
Slight variation on the same question - can you tell if a "create-drop"
setup actually dropped the tables?

What I'm looking for is this:

In development, I want auto-recompile, but I also want to rebuild the db but
only if the SCHEMA changed. I have quite a lot of data to bootstrap, and it
makes startup slow to do that every time. But if the schema changes, I need
to rebuild the db and reload the data. Grails seems to be able to detect a
domain change while running, just not sure if it can detect it at startup.

At the moment I fudged it - I have dev setup as "update", and a "rebuild"
env that is "create-drop". I only bootstrap the data in the "rebuild" env,
and I only launch with that if I change the domain classes. Then I get much
faster startup in dev most of the time. (I have to restart more often than I
would like due to a couple of recompile bugs in one of the plugins, but
faster startup is faster startup, no? This makes the difference of 60 to 90
seconds a pop).

How do other people handle this - seems like a pretty standard concept?

(I know I could protect all the data sections with an existence check first,
but that is a bit tedious!)

Cheers

Jason

On Fri, Feb 29, 2008 at 5:04 AM, twilliams <kaerfredoc@gmail.com> wrote:

>
> Sure thing, see the example below. Imports are there to demonstrate
> running
> the groovy console.
>
> ----------
>
> import org.springframework.web.context.support.WebApplicationContextUtils
> import org.codehaus.groovy.grails.commons.GrailsApplication;
> import grails.util.GrailsUtil;
> import groovy.ui.Console;
>
> class BootStrap {
>    def init = {servletContext ->
>         // Only perform in dev
>        if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT) {
>            // launch a groovy console
>            def appCtx =
> WebApplicationContextUtils.getRequiredWebApplicationContext
> (servletContext)
>            def grailsApp =
> appCtx.getBean(GrailsApplication.APPLICATION_ID);
>            Binding b = new Binding();
>            b.setVariable("ctx", appCtx);
>            def console = new Console(grailsApp.classLoader, b);
>            console.run()
>
>            // Load some test data
>            new Person(name: "Jim").save()
>            new Person(name: "Sue").save()
>        }
> ...
>
>
>
> Cromer, Rick wrote:
> >
> > Is there a way to configure the bootstrap.groovy class where the data is
> > only loaded in development environment?  Maybe another set of data for
> > test and not any in production.
> >
> >
> >
> > Regards,
> > Rick Cromer
> >
> >
> >
> >
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Is-there-a-way-to-bootstrap-only-data-in-the-development-environment-tp15752047p15752183.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
Reply | Threaded
Open this post in threaded view
|

RE: Is there a way to bootstrap only data in the development environment

Cromer, Rick
In reply to this post by burtbeckwith
Thanks Burt, that's exactly what I was looking for.

Regards,
Rick Cromer
Stratus Technologies


-----Original Message-----
From: Burt Beckwith [mailto:[hidden email]]
Sent: Thursday, February 28, 2008 11:00 PM
To: [hidden email]
Subject: Re: [grails-user] Is there a way to bootstrap only data in the
development environment

Sure - you can use GrailsUtil.getEnvironment() to determine whether
you're in
development or production mode, e.g.:

import grails.util.GrailsUtil

class BootStrap {

   def init = { servletContext ->

      // insert data for all environments

      switch (GrailsUtil.environment) {
         case 'development':
            // insert development data
            break

         case 'production':
            // insert production data
            break
      }
   }

   def destroy = {}
}

Burt

On Thursday 28 February 2008 11:50:03 pm Cromer, Rick wrote:
> Is there a way to configure the bootstrap.groovy class where the data
is
> only loaded in development environment?  Maybe another set of data for
> test and not any in production.
>
>
>
> Regards,
> Rick Cromer



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Is there a way to bootstrap only data in thedevelopment environment

Cromer, Rick
In reply to this post by Tyler Williams
Thanks for this. This will help when run the test.

Regards,
Rick Cromer
Stratus Technologies


-----Original Message-----
From: twilliams [mailto:[hidden email]]
Sent: Thursday, February 28, 2008 11:05 PM
To: [hidden email]
Subject: Re: [grails-user] Is there a way to bootstrap only data in
thedevelopment environment


Sure thing, see the example below. Imports are there to demonstrate
running
the groovy console.

----------

import
org.springframework.web.context.support.WebApplicationContextUtils
import org.codehaus.groovy.grails.commons.GrailsApplication;
import grails.util.GrailsUtil;
import groovy.ui.Console;

class BootStrap {
    def init = {servletContext ->
        // Only perform in dev
        if (GrailsUtil.environment == GrailsApplication.ENV_DEVELOPMENT)
{
            // launch a groovy console
            def appCtx =
WebApplicationContextUtils.getRequiredWebApplicationContext(servletConte
xt)
            def grailsApp =
appCtx.getBean(GrailsApplication.APPLICATION_ID);
            Binding b = new Binding();
            b.setVariable("ctx", appCtx);
            def console = new Console(grailsApp.classLoader, b);
            console.run()

            // Load some test data
            new Person(name: "Jim").save()
            new Person(name: "Sue").save()
        }
...



Cromer, Rick wrote:
>
> Is there a way to configure the bootstrap.groovy class where the data
is

> only loaded in development environment?  Maybe another set of data for
> test and not any in production.
>
>  
>
> Regards,
> Rick Cromer
>
>
>
>  
>
>
>

--
View this message in context:
http://www.nabble.com/Is-there-a-way-to-bootstrap-only-data-in-the-devel
opment-environment-tp15752047p15752183.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email