Skip to content

Instantly share code, notes, and snippets.

@ashgti
Created June 18, 2009 19:55
Show Gist options
  • Select an option

  • Save ashgti/132153 to your computer and use it in GitHub Desktop.

Select an option

Save ashgti/132153 to your computer and use it in GitHub Desktop.
#!ruby
require 'rubygems'
require 'dm-core'
require 'dm-timestamps'
require 'dm-is-versioned'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "mysql://root:password@localhost/db_testing")
class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :type, Discriminator
property :updated_at, DateTime
timestamps :at
class << self
# def storage_name repo
# 'contents'
# end
end
is_versioned :on => :updated_at
end
class Comment < Post
property :content, Text
end
Post.auto_migrate!
Comment.auto_migrate!
post = Post.new
post.title = 'one'
post.save
sleep 5
post.title = 'changed'
# post.updated_at = Time.new + 10000
post.save
comment = Comment.new
comment.content = 'hi'
comment.title = 'yes'
comment.save
comment.content = 'changed, should make a new version'
comment.save
p comment.versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment