FlywayException: Found non-empty schema

8,507 views
Skip to first unread message

smallufo

unread,
Jan 17, 2014, 9:39:58 AM1/17/14
to ninja-f...@googlegroups.com
I modified the sample blog app , added tons of tables (with data) / POJOs / DAOs

But I found I cannot start ninja , no matter jetty:run or ninja:run , it reports :

22:31:12.829 INFO  Ninja - Using default eh cache implementation. (class ninja.cache.CacheEhCacheImpl) 
22:31:13.422 INFO  ninja.servlet.NinjaBootstap - Ninja injector started in 1799 ms.
22:31:13.423 INFO  ninja.lifecycle.LifecycleServiceImpl - Starting Ninja application...
22:31:15.118 WARN  o.e.j.u.component.AbstractLifeCycle - FAILED o.e.j.s.ServletContextHandler@56ac3a89{/,null,STARTING}: ninja.lifecycle.FailedStartException: com.googlecode.flyway.core.api.FlywayException: Found non-empty schema `ninja-data` without metadata table! Use init() first to initialize the metadata table.
ninja.lifecycle.FailedStartException: com.googlecode.flyway.core.api.FlywayException: Found non-empty schema `ninja-data` without metadata table! Use init() first to initialize the metadata table.
at ninja.lifecycle.LifecycleRegister.invokeTarget(LifecycleRegister.java:102) ~[ninja-core-2.5.1.jar:na]
at ninja.lifecycle.LifecycleRegister.start(LifecycleRegister.java:54) ~[ninja-core-2.5.1.jar:na]
at ninja.lifecycle.LifecycleServiceImpl.start(LifecycleServiceImpl.java:78) ~[ninja-core-2.5.1.jar:na]
at ninja.NinjaImpl.start(NinjaImpl.java:115) ~[ninja-core-2.5.1.jar:na]

It instructs me to run init() first .
But where should I put the code ?

The StartupActions.java ?

In application.conf , I set :
ninja.migration.run=false

But still got this error .

In StartupActions.java , I added :
  @Start(order = 100)
  public void generateDummyDataWhenInTest() {
    if (!ninjaProperties.isProd()) {
      setupDao.setup();
    }

    Flyway flyway = new Flyway();
    flyway.init();
  }


But still the same error ...

What should I do now ? ( ninja 2.5.1 )

Raphael André Bauer

unread,
Jan 17, 2014, 10:22:24 AM1/17/14
to ninja-f...@googlegroups.com
Hi smallufo,


Flyway tells you that your database already exists - and that it did
not create it. This might happen if your database is already running
in production.

But if you start a project from scratch this error should not happen.

The solution is to force the creation of Flyway's database migration
tables via flyway.setInitOnMigrate(true); and then do
flyway.migrate();

But this has to happen before JPA is started...

Blueprint:
https://github.com/ninjaframework/ninja/blob/develop/ninja-core/src/main/java/ninja/migrations/MigrationEngineFlyway.java

and initializer is here:
https://github.com/ninjaframework/ninja/blob/develop/ninja-core/src/main/java/ninja/migrations/MigrationInitializer.java

I think the best would be to modify MigrationEngineFlyway.java and add
a configuration variable ninja.migration.init_on_migrate or something
that sets the .setInitOnMigrate(...).

Hope that explains what is happening...


Raphael
> --
> You received this message because you are subscribed to the Google Groups
> "ninja-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ninja-framewo...@googlegroups.com.
> To post to this group, send email to ninja-f...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ninja-framework/CAKJWkkHwA-SauBQT-DHh73CZNOkZdmVoxE%2BB5twYEx9ktT4A6A%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
inc: http://ars-machina.raphaelbauer.com
tech: http://ars-codia.raphaelbauer.com
web: http://raphaelbauer.com

smallufo

unread,
Jan 17, 2014, 10:55:56 AM1/17/14
to ninja-f...@googlegroups.com
Hi , my app is running in dev mode (super dev mode)
23:39:57.405 INFO  ninja.utils.NinjaModeHelper - Ninja is running in mode dev

I am running ninja connected to mysql , with legacy data (plus sample app's Article/Author table) .

I modify my code to  :

  @Start(order = 100)
  public void generateDummyDataWhenInTest() {

    Flyway flyway = new Flyway();
    flyway.setInitOnMigrate(true);
    flyway.migrate();

    if (!ninjaProperties.isProd()) {
      setupDao.setup();
    }
  }

but still got the same error.

I fact , I think I don't need flyway (for now).

But even I turn it off ( ninja.migration.run=false ) , why it still invoked by ninja ?

(my hibernate.hbm2ddl.auto is "update" )

Raphael André Bauer

unread,
Jan 17, 2014, 11:04:31 AM1/17/14
to ninja-f...@googlegroups.com
Hi,

your code will always be executed because of your annotation
@Start(order = 100).

Therefore ninja.migration.run=false does not have any influence on
that method (generateDummyDataWhenInTest).

In addition Flyway flyway new Flyway() is not enough... you have to
set the datasource to migrate (as in
https://github.com/ninjaframework/ninja/blob/develop/ninja-core/src/main/java/ninja/migrations/MigrationEngineFlyway.java).

Hope that helps :)

We should add the option to allow flyway to run on already existing
data as well... that would be best - and its not a big issue to add :)


Cheers,

Raphael
> --
> You received this message because you are subscribed to the Google Groups
> "ninja-framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ninja-framewo...@googlegroups.com.
> To post to this group, send email to ninja-f...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ninja-framework/CAKJWkkG5i5HoLpx8xbEXq_XnmKRXp%3DZUcCtODz7JsGRv2aSXKA%40mail.gmail.com.

Eric PROTAT

unread,
Sep 4, 2014, 4:06:46 PM9/4/14
to ninja-f...@googlegroups.com
Hi,

Sorry to raise the dead (topic), but I can give a use case where this option would be needed. I just initialized a PostgreSQL + PostGIS database. It creates pre-existent tables (like spatial_ref_sys). And I get the message at start : "com.googlecode.flyway.core.api.FlywayException: Found non-empty schema `ninja-data` without metadata table! Use init() first to initialize the metadata table."

Daniel SAWAN

unread,
Feb 5, 2015, 3:40:22 PM2/5/15
to ninja-f...@googlegroups.com
I have the exact same problem, working in an existing database.
I tried what you said but the method :

    /**
     * We start it at order 9 which is below order 10 (where JPA is started)
     */
    @Start(order=9)
    public void start() {
        migrationEngine.migrate();
    }

is just never called. The crash happen before the call of .migrate()

I suppose it was a fix for an older version of Ninja. Has this option been implemented in the newer Ninja version ? Because i think it will help many guys ! (using 4.0.4 right now)
Reply all
Reply to author
Forward
0 new messages