Managing database changes between a Rails and Java project

At a new job I started, we have both a Java application that handles most of the heavy lifting in the core business logic, and we also have a Rails application that of course handles the web interface to this server. Both of these access the same database.

Up until now, most of the focus has been on the Java application, and as such, there are no migrations in the Rails project. The sql to update the shared database is managed in a file like changes.sql.

As you can imagine, this makes it somewhat difficult to develop.

My initial thought was to combine the codebases for the Java project and the Rails application, because there is a dependency there, and to manage that SQL file in the source. However, I thought I'd ask here to see if anyone else had tackled this issue with some degree of success.


Asked by: Wilson103 | Posted: 28-01-2022






Answer 1

One approach is to use the rails migration tools, generate the DDL files for the database and use Hibernate to update the Java objects that relate to specific database entities. You don't really say how you manage database changes on the Java side or whether you use an ORM, but you can certainly synchronize the two with a little work.

Or you can go the other way around and let the Java definitions control changes on the Rails side.

I think the key to doing this successfully is to select one of the two platforms as your "primary database modeller" and develop the process to migrate that model to the other platform. Attempting to allow changes from both will only cause headaches.

Answered by: Chelsea192 | Posted: 01-03-2022



Answer 2

We have a similar project structure: shared database with both java and rails applications as clients. I advocated and got buy-in to use the rails migration mechanism for handling database changes. It takes a bit of rails advocacy, and some willingness to help but the java team is also writing their own migrations.

We have some cases where we use stored procedures and database specific column types, so we changed the rails environment.rb to use sql for creating the test database.

  # Use SQL instead of Active Record's schema dumper when creating the test database.
  # This is necessary if your schema can't be completely dumped by the schema dumper,
  # like if you have constraints or database-specific column types
  config.active_record.schema_format = :sql

On the plus side managing the sql with migrations makes rails testing and setup clean for you. The downside is that some of the migration files are just not that pretty (e.g., you can't use the migration DSL to generate stored procedures so you have these execute %{blah } in your migrations).

Just remember to keep communication lines open beteen the teams. I like the fact that "cap production deploy:migrations" makes updating the production database dead simple.

Answered by: Victoria599 | Posted: 01-03-2022



Answer 3

Thanks Steve

On the Java side, they are using Hibernate, but with a manual SQL updating process.

I agree, that it should be one or the other. The more I think about it, adding yet another application / module / codebase to manage just the database is definitely the wrong idea.

Thanks

Answered by: Marcus358 | Posted: 01-03-2022



Similar questions

java - Managing history records in a database

I have a web project that uses a database to store data that is used to generate tasks that would be processed for remote machines to alter that records and store new data. My problem here is that I have to store all that changes on each table but I don't need all these information. For example, a table A could have 5 fields but I only need 2 for historical purposes. Another table B could have 3 and I would have to add ano...


arrays - Java : Managing information in code. NO DATABASE

I need help for a work I got at school... I'm trying to make a enum or more than one that will have in memory the information of the number of days in a month, the name of the month, and the number of the month. Also, my teach said that all the information MUST be in my code... No database or other stuff like that. -_- Exp: public enum list { month = "nbdays" && "m...


ms access - Managing a database with Java

I have a MS Access database. My goal is to create a simple program to manage said database (i.e. add, modify, and/or delete information). Do I need to have Access installed in order for this program to work?


java - Managing the product count in the database

Excuse me if this question may seem naive but I have come across a scenario where I need to manage the product count in the database of an e-commerce store. There is a Product class with an integer variable productCount which signifies the number of available products in the database which is visible to users of the site. Now this class is accessed by several threads or can say several users of the e-...


Managing JAVA Heap size during storing data from Oracle Database

I need to store in memory a huge amount of data by looping over a result set (Oracle database). I carried out some test and, by using a profiler, I noticed that there is a considerable difference between the heap size and the used heap (i.e. my data). Here an example.


java - Managing SQLite Database in Android Studio

This question already has answers here:


java - Managing a simple SQL Server database table with a Tomcat servlet

I started a new job recently and I'm using existing programs and creating new ones based on the previous ones. The IT team at the hospital is pretty small so it looks really homemade (their was no versioning tool before I get there). Those servlets are working but are not state of the art in regards to proper coding. For example it's not MVC, the HTML part is inside the main class. It's enough for simply displaying ...


java - Managing database in SQlite for Android

I've been developing simple Android app that will let me store players, games and results so I can then display them with some statistics (like results, games played, last match date, wins, losses etc). I've been thinking about the best approach. I've came up with few ideas and then I started wondering which would be the best performance wise. How to store that kind of data? What is the best way to manage SQLite queries?


java - Managing multiple Google Web Toolkit pages in 1 Project

I have a project which will be made up mostly of Java Servlets, JSP/Html pages, and some regular javascript. However, there are some screens which will be too complex to do in just javascript, so I will want to use GWT for that. Is it possible to do this, so there are multiple EntryPoint classes in the same project? Then, depending on which page is being loaded I will load the appropriate javascript fi...


java - Managing Swing Actions with a Registry

Typically when I'm creating a Swing (or any UI) application, I have various Actions that appear on menu items and buttons. I usually create an action registry and store the actions in there and then when certain things occur, I disable/enable actions in the registry based on the state of the application. I wouldn't call myself an avid Swing developer, although I know my way around it well enough, but is this a pretty typic...


java - Problem managing session with multiple data sources

I am working on a project where we each service refers four separate data-source. Until now, we have been using ProxyFactoryBean to refer to the Dao target and the Transaction Intereceptor - something like this.. <bean id="readOnlyUserProxy" class="org.springframework.aop.framework.ProxyFactoryBean"> <property name="target" ref="readOnlyDao"/> <property name="interceptorNames"> ...


java - managing software editions

I plan to create 3 editions of a piece of software in Java from existing code base. What's the best practice? should I create 3 different projects one for each edition? Also any tools for managing editions?


java - Managing test data for Junit tests

We are facing one problem in managing test data (xmls which is used to create mock objects). The data which we have currently has been evolved over a long period of time. Each time we add a new functionality or test case we add new data to test that functionality. Now, the problem is when the business requirement changes the format( like length or format of a variable) or any change which the test data doesn't support...


Managing Apache HTTP Server via Java code

Does anyone know of a library that would allow me to tweak Apache HTTP Server parameters (such as Max Keep Alive or Max Clients) programmatically from withing Java code, without having to resort to parsing and modifing the configuration file? Thanks


java - Managing my first project

Closed. This question is opinion-based. It is not c...


java - Managing Multiple JVM

I have some untrusted client code and I want to run it by initiating a java virtual machine instance for each client to manage the max memory used by the JVM for each instance and max running time the code is allowed to execute. How can I do this ? Is there a code sample for such a thing ? I read about JVM pooling her...


java - Managing Android project using Git and Eclipse

I believe I have a very common problem that affects developers with multiple versions of their apps (in my case I have two: paid one and a free one). To manage both versions I use the same git project with 2 different branches: free and paid However my source code package names differ from each other (as expected), and with the java restrictions of having the directory names mapping to package names a problem arises: how t...


Managing Regex in java

How we can manage regex in java ? Yes I did search regex topics but I think it is strange in java. What I would like to do is My team <xxx-yyyy@uuuu.com> with regex, I would like to get string between < > as xxx-yyyy@uuuu.com Pattern p = Pattern.compile("(.+?)\\<.*?\\>?"); Above one didn't work.






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top