Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
[rails_datamapper] Apply patch from Kristian Meier <m.kristian@web.de>
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Kubb <dan.kubb@autopilotmarketing.com>
  • Loading branch information
Dan Kubb committed Apr 17, 2009
1 parent a9d7779 commit a5f6d69
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
36 changes: 36 additions & 0 deletions rails_datamapper/datamapper.rake
@@ -0,0 +1,36 @@
namespace :db do

desc "Perform automigration"
task :automigrate => :environment do
::DataMapper.auto_migrate!
end

desc "Perform non destructive automigration"
task :autoupgrade => :environment do
::DataMapper.auto_upgrade!
end

namespace :migrate do
task :load => :environment do
gem 'dm-migrations'
FileList["db/migrations/*.rb"].each do |migration|
load migration
end
end

desc "Migrate up using migrations"
task :up, :version, :needs => :load do |t, args|
version = args[:version]
migrate_up!(version)
end

desc "Migrate down using migrations"
task :down, :version, :needs => :load do |t, args|
version = args[:version]
migrate_down!(version)
end
end

desc "Migrate the database to the latest version"
task :migrate => 'db:migrate:up'
end
Expand Up @@ -2,11 +2,17 @@ namespace :db do

desc "Perform automigration"
task :automigrate => :environment do
FileList["app/models/**/*.rb"].each do |model|
load model
end
::DataMapper.auto_migrate!
end

desc "Perform non destructive automigration"
task :autoupgrade => :environment do
FileList["app/models/**/*.rb"].each do |model|
load model
end
::DataMapper.auto_upgrade!
end

Expand Down
1 change: 1 addition & 0 deletions rails_datamapper/generators/dm_model/dm_model_generator.rb
@@ -1,4 +1,5 @@
require 'rails_generator/generators/components/model/model_generator'
require 'active_record'

This comment has been minimized.

Copy link
@michaelklishin

michaelklishin Apr 17, 2009

Contributor

Is this because generator is tied AR code?

This comment has been minimized.

Copy link
@michaelklishin

michaelklishin Apr 17, 2009

Contributor

that should read: “tied to AR code”


class DmModelGenerator <ModelGenerator

Expand Down
12 changes: 11 additions & 1 deletion rails_datamapper/generators/dm_model/templates/model.rb
@@ -1,4 +1,14 @@
class <%= class_name %>
include DataMapper::Resource
property :id, Integer, :serial => true
property :id, Serial
<% for attribute in attributes -%>
property :<%= attribute.name %>, <%= attribute.type.to_s.capitalize %>, :nullable => false

<% end -%>
<% unless options[:skip_timestamps] %>
property :created_at, DateTime, :nullable => false
property :updated_at, DateTime, :nullable => false

<% end -%>
end
@@ -1,4 +1,5 @@
require 'rails_generator/generators/components/model/model_generator'
require 'active_record'

class RspecDmModelGenerator <ModelGenerator

Expand Down
12 changes: 11 additions & 1 deletion rails_datamapper/generators/rspec_dm_model/templates/model.rb
@@ -1,4 +1,14 @@
class <%= class_name %>
include DataMapper::Resource
property :id, Integer, :serial => true
property :id, Serial
<% for attribute in attributes -%>
property :<%= attribute.name %>, <%= attribute.type.to_s.capitalize %>, :nullable => false

<% end -%>
<% unless options[:skip_timestamps] %>
property :created_at, DateTime, :nullable => false
property :updated_at, DateTime, :nullable => false

<% end -%>
end
2 changes: 1 addition & 1 deletion rails_datamapper/lib/rails_datamapper/rails_datamapper.rb
@@ -1,5 +1,5 @@
def config_file()
Rails.root + "/config/database.yml"
RAILS_ROOT + "/config/database.yml"
end

def create_connection()
Expand Down

1 comment on commit a5f6d69

@dkubb
Copy link
Member

@dkubb dkubb commented on a5f6d69 Apr 17, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

michaelklishin: Good question. I must’ve missed that when reviewing the patch. If it is possible to make this work without depending on AR I would prefer it, because people would be able to alter their Rails config so that AR isn’t loaded into memory at all (why load it if you’re not using it?).

Perhaps we should direct comments to here: http://datamapper.lighthouseapp.com/projects/20609/tickets/804-patch-rails_datamapper-get-it-to-run-with-rails-230#ticket-804-2

Please sign in to comment.