I write a small datamapper plugin, that have these features (currently
only works >= mysql 5.0.2):
- For people who want to log every database change. and can easily
find out who change what and when.
- Multiple database accepting changes, and easily keep them syncronized.

For example, You have multiple databases with same schema, some of
them are for production, always showing correct data to end user,
some of them are used for Editors, Administors who want to edit
articles, categories, product listings, templates etc, and don't want
to change that directly in production. and want to make sure that data
changed is correct and tested, and then push to production.


basicly what the plugin do is keep the database serialized in git
repository as json files.
the git repository directory is like:
  /repository_path/users/1  #=> {"id": 1, "name":"Felix", "email":"....."}
                   users/2
                   productions/1
                   productions/2

each database have corresponding git repository keeping all the
changes you made to the database.
So when a database want to pull changes from another database, It use
git to pull the files, and use the diff to update the database.

Example


DataMapper.setup(:master1, "mysql://localhost/gitdb_master1").config_git(
    :local => "/git_repo1",
    :as_url => "ssh://[EMAIL PROTECTED]/git_repo1",
    :increment_offset => 1, # This will setup this server generate pk
like 1, 3, 5, 7
    :origin => true
)  # make sure origin db with data, others db are empty.

DataMapper.setup(:master2, "mysql://localhost/gitdb_master2").config_git(
    :local => "/git_repo2",
    :increment_offset => 2, This will setup this server generate pk
like 2, 4, 6, 8
    :as_url => "ssh://[EMAIL PROTECTED]/git_repo2"
)

class MyModel
    include DataMapper::Resource
    include DataMapper::GitDb

    property :id, Serial
    property :name, String
end

repository(:master1) do
    MyModel.create(:name => "master1 #1")
    MyModel.create(:name => "master1 #2")
end

DataMapper::GitDb.build  # this will dump data to files, create git
repository, make the two git repositories connected.


repository(:master1) do
    MyModel.first(:name => "master1 #1").destroy
    MyModel.first(:name => "master1 #2").update_attributes(:name =>
"master1 #2 edited")
    MyModel.create(:name => "master1 #3")
end
repository(:master1).commit("edited in master1")

repository(:master2) do
    MyModel.create(:name => "master3 #1")
end
repository(:master1).commit("edited in master2")


repository(:master2).pull(:master1)



Then master2 have all the changes by master1 (deleted #1, edited #2, added #3),
But master1 don't have the changes that master2 made (added master 3 #1).


GitHub: http://github.com/sunfmin/dm-gitdb

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to