migrations: java code

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

migrations: java code

marzia
Sometimes when refactoring a db schema we have a need to massage the
data using the java code instead of limited sql script... Is it
possible to augment the change script with something like

--//# fully_qualified_class_name

of a class which implements something like

    void migrate(org.apache.ibatis.session.SqlSession session);

This would make whole migrations much more powerfull and one-stop shop
for db maintenance.
Or if I am wrong can somebody point me how to solve this problem of
migrations with some custom code ?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: migrations: java code

Clinton Begin
Administrator
Interesting idea.  Sounds simple enough.

On 2011-02-18, marzia <[hidden email]> wrote:

> Sometimes when refactoring a db schema we have a need to massage the
> data using the java code instead of limited sql script... Is it
> possible to augment the change script with something like
>
> --//# fully_qualified_class_name
>
> of a class which implements something like
>
>     void migrate(org.apache.ibatis.session.SqlSession session);
>
> This would make whole migrations much more powerfull and one-stop shop
> for db maintenance.
> Or if I am wrong can somebody point me how to solve this problem of
> migrations with some custom code ?
>
> Thank you
>

--
Sent from my mobile device
Reply | Threaded
Open this post in threaded view
|

Re: migrations: java code

Nathan Maves
I was thinking this is a cool idea.

On Fri, Feb 18, 2011 at 10:09 PM, Clinton Begin <[hidden email]> wrote:
Interesting idea.  Sounds simple enough.

On 2011-02-18, marzia <[hidden email]> wrote:
> Sometimes when refactoring a db schema we have a need to massage the
> data using the java code instead of limited sql script... Is it
> possible to augment the change script with something like
>
> --//# fully_qualified_class_name
>
> of a class which implements something like
>
>     void migrate(org.apache.ibatis.session.SqlSession session);
>
> This would make whole migrations much more powerfull and one-stop shop
> for db maintenance.
> Or if I am wrong can somebody point me how to solve this problem of
> migrations with some custom code ?
>
> Thank you
>

--
Sent from my mobile device

Reply | Threaded
Open this post in threaded view
|

Re: migrations: java code

marzia
In reply to this post by Clinton Begin
Hi Clinton,

maybe a fully qualified class which is picked up by migrator can
implement:

public interface Migrator {
    void upgrade (SqlSession session);
    void downgrade (SqlSession session);
}

where it receives a 'special' session trough which it executes a
statements interleaved with code... Meaning of 'special' for session
is that a code could not mess with connections and/or transactions,
(some SqlSession delegate with those 'connection/transaction' methods
not delegating but throwing 'NotSupportedOperation') those would be
auto handled by calling code of migrations process. I don't know if on
the same line of the migration file can be specified .xml to be used
when constructing SqlSession instance...
Excuse me as I have not much experience with MyBatis but would like to
be helpful with some constructive suggestions ;-)
Reply | Threaded
Open this post in threaded view
|

Re: migrations: java code

Simone Tripodi-2
I'm +1 on Marzia's suggestions, sounds very interesting!

http://people.apache.org/~simonetripodi/
http://www.99soft.org/



On Sun, Feb 20, 2011 at 5:51 PM, marzia <[hidden email]> wrote:

> Hi Clinton,
>
> maybe a fully qualified class which is picked up by migrator can
> implement:
>
> public interface Migrator {
>    void upgrade (SqlSession session);
>    void downgrade (SqlSession session);
> }
>
> where it receives a 'special' session trough which it executes a
> statements interleaved with code... Meaning of 'special' for session
> is that a code could not mess with connections and/or transactions,
> (some SqlSession delegate with those 'connection/transaction' methods
> not delegating but throwing 'NotSupportedOperation') those would be
> auto handled by calling code of migrations process. I don't know if on
> the same line of the migration file can be specified .xml to be used
> when constructing SqlSession instance...
> Excuse me as I have not much experience with MyBatis but would like to
> be helpful with some constructive suggestions ;-)
>