Giter VIP home page Giter VIP logo

xmigra's Introduction

XMigra Gem Version

DevOps tool for your relational database

What Does It Do?

  • Integrates version control with database schema management.
  • Enhances access artifact (stored procedure, view, and user defined function) development:
    • Allows each artifact to be defined in a separate file, giving easy access to version history.
    • Scripts artifact definitions in order (and removal in reverse order) by declared dependencies.
    • Makes records of all artifacts created, allowing removal by subsequent scripts without a priori knowledge of all previously created artifacts. (This is really helpful when you roll back to an earlier version of the schema source documents that do not even contain the names of more recently added objects.)
  • Facilitates multi-branch development by allowing database schema changes on any branch and providing tools to identify and resolve conflicts in the migration chain.
  • Provides development and production modes for script generation to ensure production databases remain in well-documented states.
  • Generates idempotent upgrade scripts that use only SQL (flavored specifically for a selected database).
  • Integrates the SQL you provide into the upgrade script intelligently -- you don't have to learn a whole new language to define your schema objects!
  • Provides tools for gathering information on the history of migration-modified database objects (tables, namespaces, etc.).
  • Allows tracking table structures declaratively, even suggesting SQL to effect supported changes to tables, which can integrate with database access layer testing.

What Systems Does It Work With?

Ruby

  • Versions 2.0+

Version Control

  • Subversion
  • Git

Databases

  • Microsoft SQL Server (2005 and later)
  • PostgreSQL (tested on 9.3, should work for 8.4 or later)

Tell Me More!

XMigra brings the tools and ideas of software development to the world of database schemas. Specifically, this tool enables you to keep your database schema parts under version control in much the same way you keep your software source code under version control.

XMigra also removes the tedious and error-prone task of organizing the order of stored procedure, view, and user-defined function definition with dependency declarations. XMigra will remove and create these access artifacts in an order that satisfies the dependencies you declare. With the information it persists about the artifacts it has created, XMigra can effectively remove any that you remove from your schema source -- no need for you to track the names of database objects you long ago discarded.

Multiple branch development -- whether simultaneous by multiple developers or for agilely shifting focus to between priorities -- is fully supported by XMigra with tools to properly identify and resolve conflicts in the migration chain. XMigra comes with support for multiple release chains (i.e. branch upgrades) baked right in, too!

XMigra has a modular design, allowing extension to additional version control and database systems with only minor, if any, changes to the central framework.

Get the code and run xmigra overview for the tool's own rundown on all of its exciting features. The wiki for this project also contains a fairly comprehensive tutorial.

Installation

Creative Commons License
XMigra by Next IT Corporation and Richard T. Weeks is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License .

Add this line to your application's Gemfile:

gem 'xmigra'

And then execute:

$ bundle

Or install it yourself as:

$ gem install xmigra

Usage

XMigra is bundled with its own documentation. To view it, run:

$ xmigra help

or:

$ xmigra overview

Contributing

  1. Fork it ( http://github.com/rtweeks/xmigra/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

xmigra's People

Contributors

rtweeks avatar

Stargazers

 avatar David Vázquez Púa avatar Scott avatar  avatar Alexander ADAM avatar

Watchers

James Cloos avatar Scott avatar  avatar

xmigra's Issues

Convert to gem

Reorganize this code as a gem that can be registered with rubygems.org.

Add a hook for a command to run for database backup.

When a new migration is created that extends the production migration chain, this hook command (if specified) will be run to create a database backup. This will allow restoring the database to a state on the production migration chain to support the case of syncing in upstream changes:

  • Sync-merge or rebase
  • xmigra.rb unbranch
  • Restore database from backup
  • Run the generated upgrade script against the "production state" database

Since the hook script can be anything, it can either do the backup itself or prompt the user to do the backup.

xmigra new --index tries to use [{filename}]

Index definition files don't get the filename metavariable replaced during upgrade script generation, so the xmigra new --index command should not inject it into the generated file and should, instead, put the correct string there.

Add support for PostgreSQL

Add support for a new database system, "PostgreSQL", that outputs scripts in PG-SQL compatible with the PostgreSQL database. Emitted SQL should be compatible with PostgreSQL 8.4 or later.

impdecl doesn't assess reintroduced declarative correctly

Because it was just comparing the "new" (recovered/copied-from-history) declarative file to the migration file that implemented destruction of that declarative, XMigra incorrectly assessed the declarative file as :newer instead of the correct :unimplemented.

Preprocessing/extension framework

Add hook points for extension libraries (e.g. sql_loaded, final_script_chunk, etc.) and a command line option to load (require) an arbitrary extension library.

Add "squishy" support of declarative source for structure

XMigra fundamentally organizes changes to the data-containment structure of a database as a chain of migration commands and there is no effective way or convincing argument here to change that. However, XMigra could offer some level of support to developers for comparing new versions of declarative-language structure files to their corresponding previous versions in the version control system and building a proposed migration off of those changes.

My initial thought is that the declarative files should be stored in the structure/declarative subdirectory of the XMigra project. Addition, deletion, or modification of those files would, for certain XMigra operations like upgrade, require a .decl.yaml file to exist in the structure directory that explicitly references the new version of the declarative file and gives SQL for implementing the change. XMigra would not enforce that the given SQL effected the change to the declarative file when run against the database -- only that one of these "special" migrations existed that claimed to do so. The files in the structure/declarative subdirectory should be named for the objects in the database they implement (as do the files in the access subdirectory).

The general flow is:

  • Alice revises (or creates or deletes) a declarative file for one database element.
  • Alice tries xmigra upgrade. XMigra exits with failure and notes that no existing migration implements the current state of the declarative file.
  • Alice runs xmigra impdecl to generate migrations implementing the current version of any unimplemented declarations. Any migration XMigra doesn't know how to fully generate will contain a flag that will continue to cause upgrade script generation to fail until the migration is edited and the flag removed.
  • Alice tries xmigra upgrade again. This time, the script generation is successful.

The special declarative-change-effector migrations (implementation migrations or .decl.yaml files) contain a superset of the top-level keys required for standard migrations. In addition, they contain (bold keys are required):

key meaning
does One of: creation, adoption, revision, renunciation, or destruction
of object basename of file in declarative subdirectory
to realize hash of the content of the declarative file implemented
delta a diff from the version control system showing how the two versions of the declarative file differ textually (not actually used by XMigra)
implementation qualification if present, usually has the value unimplemented or suggestion and its presence indicates that XMigra was not able to generate (or confident in generating) SQL to implement the declarative change without the intervention of a programmer

The .decl.yaml file contains the to realize hash because generation of the upgrade script in development mode does not require the files be committed to version control, and it would be important that the .decl.yaml files have a reference not only to the object name but also a hash of the contents to avoid the situation where Bob changes the declarative file, generates (and possibly edits) a migration to implement it, and then modifies the declarative file again but does not regenerate or edit the corresponding new migration file. Unless Bob is protected by XMigra checking the hash of the declarative file against the hash in the implementing migration, he could have a very bad day.

In addition to supporting addition, revision, and deletion, the structure/declarative system should also support the operations of adoption and renunciation, which allow existing structural elements to become declaratively managed or declaratively managed structural elements to cease declarative support without being eliminated from the database. xmigra impdecl run with the --adopt flag would generate an adoption script and similarly generate a renunciation script when run with --renounce.

xmigra impdecl would generate the new migration file using the object name and the identifier of the commit/revision of the previous version of the declarative file (or new for newly created or adopted declaratives, end for destroyed or renounced ones). It would properly set all the required fields (even those required for a normal migration) and include a diff from the previous version of the declarative to the current version in the migration under the delta key. It might generate SQL to implement the declarative change and it might add a implementation qualification key that would prevent generating an upgrade script.

The files in structure/declarative would also be YAML files with top-level keys TBD. The files would include information on the type of object as well as its structure, allowing piecewise implementation of SQL generation support in the XMigra tool.

Integrate with ActiveRecord::Migration

Allow specification of XMigra migrations as ActiveRecord::Migration code.

Reversible migrations should store reversion steps in the database for application when/if a new upgrade script that modifies the old migration is run.

2nd-and-later upgrade bug with PostgreSQL

The select_for_install_sql method returns SQL that selects multiple rows in a scalar context if more than one migration has already been applied, causing upgrade failure.

XMigra::VersionControlError when upgrading xmigra to version 1.6.0

Environment:

  • Windows 10
  • tortoise svn command line tools
svn --version
svn, version 1.9.3 (r1718519)
   compiled Dec 13 2015, 15:47:16 on x86-microsoft-windows

Build works fine with xmigra 1.5.1.

Repro:

  • Upgraded to to xmigra 1.6.0
  • Run same command displayed below.

Build command output:

running command "ruby "C:\Ruby21-x64\bin\xmigra" upgrade "--source=<Path to source>" -o "<output path>\conversation.2-debug-schema.sql""
The system cannot find the path specified.
Subversion command failed with exit code 1 (XMigra::VersionControlError)

init subcommand

Provide an "init" subcommand that initializes a directory as an XMigra schema.

Soften the production chain migration file history requirements

XMigra currently demands that migration files used to produce production upgrade scripts have been unmodified in the version control system since their introduction. This restriction is overly broad; not every part of the migration file contributes to the configuration of production servers, especially the "changes" section. It would be nice to be able to alter the "changes" section after committing. It would also be nice if mild formatting changes to the SQL (if SQL is used in the definition) that cannot change the meaning of the SQL commands (leaning conservatively) were acceptable, as reformatting may occasionally be desirable.

This would probably involve creating an SQL canonizer (overridable by RDBMS specifics) so SQL semantics could be compared (along with preceding state, which is a simple string compare) between the current version of the migration file and it's originally committed form. One potential issue is introduction of addition top level keys that help generate the SQL (especially through plugins): should they have hard immutability requirements? Can the immutability requirements be eased by plugins?

!table declarative support is confused by Git

The support code for the !table declarative schema:

  • is confused (when using Git version control) about indexed/cached files not being committed (it is considering them committed, but they have no commit hash since they aren't really committed)
  • is failing to retrieve file content because previous changes removed the leading ./ from the path used in the git show command.

`promote` tool for Git migration curation

Issue #31 and the fix in PR #32 revealed a gap in maintaining the immutability of the migration chain in a Git repository network. A more reliable process would be:

  • Merge (or directly commit) changes into the "main branch" (master or a version-specific branch)
  • Use the new xmigra promote tool to update the central definition of production (preceded by checks that the new commit is consistent with the old one).

Setting this up would involve using a branch name different than master in the xmigra-master Git attribute for the database.yaml file -- possibly something like prod-db-chain. It will probably also be necessary to mark a branch as the "premaster" to prevent accidentally promoting unmerged development changes to the database schema's master branch.

Support online/concurrent/etc. index creation/update

Currently, XMigra only supports immediate creation or update of indexes during the main upgrade transaction. It would be nice if the features of the database that allow indexes to be created concurrently with normal access to the table were accessible/manageable through XMigra.

Database Support

Considerations

  • MS SQL Server does not support these operations for all license levels. For organizations that use the more expensive licenses with support for this feature, it is likely that indexes will need to be managed without it in some (lower) environments.
  • PostgreSQL does not allow CONCURRENT index creation inside transactions.

Add `xmigra impdecl --undo`

xmigra impdecl often leaves a big mess if the declarative file has errors, especially if changes didn't start from a clean working tree/working copy. It would be nice if XMigra could back its changes out with xmigra impdecl --undo.

Option in database.yaml to specify XMigra metadata schema (i.e. namespace) in DB

The database.yaml file should support an option allowing specification of the schema name (rather than the hard-coded default of xmigra) within which the XMigra version tracking metadata is stored. In addition to general flexibility, this allows different parts of the same database to be managed by different XMigra schema source file trees.

unmerge fails

The method vcs_file_modified? is invoked but not defined by the Git and Subversion VCS implementations.

Add a --with-rollback flag for xmigra new --migration

It's a pain for the user to have to create and open the rollback file manually. If the proposed --with-rollback flag is given to xmigra new when generating a migration (either with the --migration flag or with no file-type flag), create an empty rollback file for the migration and open it in the editor (if the migration is opened in the editor).

Add support for "stopping points"

Stopping points are migrations with an SQL boolean expression attached; if the boolean expression is true, the sql of the migration is carried out, otherwise the upgrade is early-exited with a message about how to proceed.

Use of stopping points precludes single-transaction upgrade guarantees, but it enables functionality like non-blocking index creation (#25) and shared database management (#6).

Add `--delete` flag to `xmigra impdecl`

As a user, it's nice to get tab-completion on file paths. If I use rm, del, or a function of my editor to remove the declarative file before invoking xmigra impdecl for the destruction migration, I don't get tab completion. Rolling the deletion of the file into xmigra impdecl will solve that problem by allowing me to specify deletion of the file and generation of the implementing migration in one command (without repeating the path to the declarative file -- DRY and all that).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.