Database source control with Oracle

前端 未结 9 2089
天命终不由人
天命终不由人 2021-02-04 08:14

I have been looking during hours for a way to check in a database into source control. My first idea was a program for calculating database diffs and ask all the developers to i

9条回答
  •  遥遥无期
    2021-02-04 08:47

    So many people try to do this sort of thing (diff schemas). My opinion is

    • Source code goes into a version control tool (Subversion, CSV, GIT, Perforce ...). Treat it as if it was Java or C code, its really no different. You should have an install process that checks it out and applies it to the database.
    • DDL IS SOURCE CODE. It goes into the version control tool too.
    • Data is a grey area - lookup tables maybe should be in a version control tool. Application generated data certainly should not.

    The way I do things these days is to create migration scripts similar to Ruby on Rails migrations. Put your DDL into scripts and run them to move the database between versions. Group changes for a release into a single file or set of files. Then you have a script that moves your application from version x to version y.

    One thing I never ever do anymore (and I used to do it until I learned better) is use any GUI tools to create database objects in my development environment. Write the DDL scripts from day 1 - you will need them anyway to promote the code to test, production etc. I have seen so many people who use the GUIs to create all the objects and come release time there is a scrabble to attempt to produce scripts to create/migrate the schema correctly that are often not tested and fail!

    Everyone will have their own preference to how to do this, but I have seen a lot of it done badly over the years which formed my opinions above.

提交回复
热议问题