Using different databases with MyBatis Schema Migrations

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

Using different databases with MyBatis Schema Migrations

cowwoc
Hi,

What is the recommended practice when one application may be deployed
into different databases by different users? Are we supposed to create
different database repositories per type? Are we supposed to "ifdef"
the contents of our scripts somehow? Are we supposed to limit
ourselves to "portable" SQL as much as possible?

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

Re: Using different databases with MyBatis Schema Migrations

Guy Rouillier
On 1/16/2011 9:38 AM, cowwoc wrote:
> Hi,
>
> What is the recommended practice when one application may be deployed
> into different databases by different users? Are we supposed to create
> different database repositories per type? Are we supposed to "ifdef"
> the contents of our scripts somehow? Are we supposed to limit
> ourselves to "portable" SQL as much as possible?

Since MyBatis is a statement mapper, the issue of making your app work
with multiple databases is the same as if you were using straight JDBC.
  So, what would you do if you were programming with JDBC?  Answer that
question and transfer your answer to MyBatis.

Perhaps you are asking if MyBatis provides some magic pill so that
everything just works with different DBMSs.  The answer is no.  If your
app is lucky enough that standardized SQL works across all DBMSs your
app is likely to be configured with, great - stick with that.  If not,
then you can either include some <if> statements to tailor a single XML
file for each DBMS as necessary.  Or, if the SQL is drastically
different between DBMSs, you might prefer to just use completely
independent XML files for each target DBMS.

--
Guy Rouillier
Reply | Threaded
Open this post in threaded view
|

Re: Using different databases with MyBatis Schema Migrations

Clinton Begin
Administrator
In reply to this post by cowwoc
Regarding Migrations specifically, yes.  You should have a separate DB repository for each DB type.  

The "ifdef" you're looking for is the repository name. While the DML side of SQL can be somewhat standardized, I've never seen two compatible DDL implementations.  Any interior ifdef type feature would litter your DDL so badly it would be unrecognizable.

Cheers,
Clinton

On Sun, Jan 16, 2011 at 7:38 AM, cowwoc <[hidden email]> wrote:
Hi,

What is the recommended practice when one application may be deployed
into different databases by different users? Are we supposed to create
different database repositories per type? Are we supposed to "ifdef"
the contents of our scripts somehow? Are we supposed to limit
ourselves to "portable" SQL as much as possible?

Thank you,
Gili

Reply | Threaded
Open this post in threaded view
|

Re: Using different databases with MyBatis Schema Migrations

cowwoc

    Makes sense. Thanks Clinton!

Gili

On 18/01/2011 11:05 AM, Clinton Begin wrote:
Regarding Migrations specifically, yes.  You should have a separate DB repository for each DB type.  

The "ifdef" you're looking for is the repository name. While the DML side of SQL can be somewhat standardized, I've never seen two compatible DDL implementations.  Any interior ifdef type feature would litter your DDL so badly it would be unrecognizable.

Cheers,
Clinton

On Sun, Jan 16, 2011 at 7:38 AM, cowwoc <[hidden email]> wrote:
Hi,

What is the recommended practice when one application may be deployed
into different databases by different users? Are we supposed to create
different database repositories per type? Are we supposed to "ifdef"
the contents of our scripts somehow? Are we supposed to limit
ourselves to "portable" SQL as much as possible?

Thank you,
Gili