Is there a version control system for database structure changes?

后端 未结 22 1171
梦毁少年i
梦毁少年i 2020-11-30 17:53

I often run into the following problem.

I work on some changes to a project that require new tables or columns in the database. I make the database modifications and

相关标签:
22条回答
  • 2020-11-30 18:09

    Most database engines should support dumping your database into a file. I know MySQL does, anyway. This will just be a text file, so you could submit that to Subversion, or whatever you use. It'd be easy to run a diff on the files too.

    0 讨论(0)
  • We've used MS Team System Database Edition with pretty good success. It integrates with TFS version control and Visual Studio more-or-less seamlessly and allows us to manages stored procs, views, etc., easily. Conflict resolution can be a pain, but version history is complete once it's done. Thereafter, migrations to QA and production are extremely simple.

    It's fair to say that it's a version 1.0 product, though, and is not without a few issues.

    0 讨论(0)
  • 2020-11-30 18:10

    PLSQL Developer, a tool from All Arround Automations, has a plugin for repositories that works OK ( but not great) with Visual Source Safe.

    From the web:

    The Version Control Plug-In provides a tight integration between the PL/SQL Developer IDE >>and any Version Control System that supports the Microsoft SCC Interface Specification. >>This includes most popular Version Control Systems such as Microsoft Visual SourceSafe, >>Merant PVCS and MKS Source Integrity.

    http://www.allroundautomations.com/plsvcs.html

    0 讨论(0)
  • 2020-11-30 18:13

    Two book recommendations: "Refactoring Databases" by Ambler and Sadalage and "Agile Database Techniques" by Ambler.

    Someone mentioned Rails Migrations. I think they work great, even outside of Rails applications. I used them on an ASP application with SQL Server which we were in the process of moving to Rails. You check the migration scripts themselves into the VCS. Here's a post by Pragmatic Dave Thomas on the subject.

    0 讨论(0)
  • 2020-11-30 18:14

    In Ruby on Rails, there's a concept of a migration -- a quick script to change the database.

    You generate a migration file, which has rules to increase the db version (such as adding a column) and rules to downgrade the version (such as removing a column). Each migration is numbered, and a table keeps track of your current db version.

    To migrate up, you run a command called "db:migrate" which looks at your version and applies the needed scripts. You can migrate down in a similar way.

    The migration scripts themselves are kept in a version control system -- whenever you change the database you check in a new script, and any developer can apply it to bring their local db to the latest version.

    0 讨论(0)
  • 2020-11-30 18:14

    I'm a bit old-school, in that I use source files for creating the database. There are actually 2 files - project-database.sql and project-updates.sql - the first for the schema and persistant data, and the second for modifications. Of course, both are under source control.

    When the database changes, I first update the main schema in project-database.sql, then copy the relevant info to the project-updates.sql, for instance ALTER TABLE statements. I can then apply the updates to the development database, test, iterate until done well. Then, check in files, test again, and apply to production.

    Also, I usually have a table in the db - Config - such as:

    SQL

    CREATE TABLE Config
    (
        cfg_tag VARCHAR(50),
        cfg_value VARCHAR(100)
    );
    
    INSERT INTO Config(cfg_tag, cfg_value) VALUES
    ( 'db_version', '$Revision: $'),
    ( 'db_revision', '$Revision: $');
    

    Then, I add the following to the update section:

    UPDATE Config SET cfg_value='$Revision: $' WHERE cfg_tag='db_revision';
    

    The db_version only gets changed when the database is recreated, and the db_revision gives me an indication how far the db is off the baseline.

    I could keep the updates in their own separate files, but I chose to mash them all together and use cut&paste to extract relevant sections. A bit more housekeeping is in order, i.e., remove ':' from $Revision 1.1 $ to freeze them.

    0 讨论(0)
提交回复
热议问题