Is it possible to include database versioning in the commit (GIT)?

Asked

Viewed 258 times

2

I wonder if it is possible to versioning the database (in my case Mysql) through GIT, or if there is some other effective way to do it.

  • 1

    http://answall.com/questions/183/como-versionar-banco-de-dados-mysql/187

  • 1

    Why don’t you export the structure to a . sql and take control of that . sql? It’s just a hint of how to do this very simply.

  • Very good the day, thank you!!

1 answer

1


It is possible, depending on the technologies involved.

Databases themselves generally do not provide versioning means. However, some frameworks do create means of applying patches to a database, and to modify it incrementally. These patches, or database Migrations, can be versioned.

The best known example is Active Record of Ruby on Rails. Here’s an example of how to change the type of a table column:

class ChangeProductsPrice < ActiveRecord::Migration
  def change
    reversible do |dir|
      change_table :products do |t|
        dir.up   { t.change :price, :string }
        dir.down { t.change :price, :integer }  # rollback
      end
    end
  end
end

In C#, for example, we can also use database Migrations of the Entity Framework.

public partial class AddPostAbstract : DbMigration 
{ 
    public override void Up() 
    { 
        AddColumn("dbo.Posts", "Abstract", c => c.String()); 
        Sql("UPDATE dbo.Posts SET Abstract = LEFT(Content, 100) WHERE Abstract IS NULL"); 
    } 

    public override void Down() 
    { 
        DropColumn("dbo.Posts", "Abstract"); 
    } 
} 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.