[Discuss] Adding database migration hooks to pax-jdbc-config

25 views
Skip to first unread message

Christian Schneider

unread,
Feb 6, 2017, 7:37:07 AM2/6/17
to op...@googlegroups.com
I think a common case is that code using a database needs the database
to be in a certain state to work correctly.

A lot of people use tools like liquibase to achieve that. Now the
question is how to best hook liquibase or a similar tool into the
startup of an OSGi application.

What I would like to do is provide a way to specify a migration task in
a pax-jdbc-config that is then guaranteed to run before the DataSource
is published for general use.

What I imagine is to use some interface like:

public interface DatabaseSetupHook {
public void prepare(DataSource ds);
}

An implementation could be exposed as a service given a name using a
service property like this:

@Component(property={"name=myhook"})
public class Migrate implements DatabaseSetupHook {

public void prepare(DataSource ds) {

}

}


In the database config we could refer to the hook via:

pre-hook=myhook

Pax-jdbc-config would then only establish the DataSource once that hook
is present and will run it before publishing the DataSource.

If it makes sense we could even wrap liquidbase in a hook that just
needs to be configured by the user.

What do you think?

Christian




--
Christian Schneider
http://www.liquid-reality.de

Open Source Architect
http://www.talend.com

Csákány Róbert

unread,
Feb 6, 2017, 2:38:31 PM2/6/17
to OPS4J
Its a very good idea, because now I to achive that I have to make "database ready" marker interface on ServiceRegistry via liquibase loader and have to make some extra service dependency for marker interface where the datasource is also referenced - So I had to wrapped it the whole. Its very ugly. So I prefere this way Christian!
Regards,

Robert
Reply all
Reply to author
Forward
0 new messages