I have existing oracle database. I want to put it under source control (Subversion).
The only solution I know – create ‘DROP/CREATE/INSERT’ text scripts and store them to SVN.
May be there is better way to manage schema and data? I’m using Oracle SQL Developer and I have seen there Migration/Repository management features. Should I use them? And how to use them?
I’m not sure if I am really answering your question here or just spewing random stuff 🙂
To start, I would like to say first I am highly against putting data into source control – your database is where you maintain your data. I use a SCM to keep track of object changes and an archive strategy within the DB to track data changes.
I have not used SQL Developer’s Version control, mainly as we have our deployments integrated with our Jenkins CI server, so maybe it does exactly what you need already.
A basic structure is required to organize your code and I think this should conform as close as possible to your actual database.
The above mimics the namespace boundaries within Oracle. PLSQL and DDL objects do share the same namespace but I separate them due to PLSQL having business logic.
I host all objects within these folders with the naming schema of OBJECTNAME.TYPEEXTENSION, with the (more or less) standardized file extensions:
The contents of these scripts I find depends on your deployment tool and the object type.
With this in mind you can figure out the structure you will need to have in these files.
Our tool currently can not handle rerunability, i.e. where we do not have CREATE OR REPLACE objects or there are tightly coupled dependencies between User Defined Objects.
For these we have had to write a PLSQL block to check system tables to see, for example, if an index has been added and if so it throws an exception which the tool captures and knows to discard and move on to the next script.
I only look to apply the deltas within the database during our continuous integration, hence why we do not use DROP/CREATE/INSERT scripts. This allows us to track each change independently and, with our rollback logic, revert to a specific build.