public
Description: All the extra stuff you could want for the Mack Framework.
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack-more.git
Added 'proper' test:setup tasks for data_mapper and active_record. [#67 
state:resolved]
markbates (author)
Tue Aug 12 10:08:59 -0700 2008
commit  5b2d5db9aeea49c0b4fe749a139b74c7f9cfb874
tree    4251450dda7aaedd0b3b0380a12fb641f09c220b
parent  7a172b53d81204a5afe56ec67926eb5a3e9e362e
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ require File.join(crt, "rake_task_requires")
0
   s.files = FileList['lib/**/*.*', 'README', 'doc/**/*.*', 'bin/**/*.*']
0
   s.require_paths << 'lib'
0
 
0
-  s.add_dependency("activerecord", "2.0.2")
0
+  s.add_dependency("activerecord", "2.1.0")
0
   s.extra_rdoc_files = ["README"]
0
   s.has_rdoc = true
0
   s.required_ruby_version = ">= 1.8.6"
...
67
68
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
71
72
...
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
0
@@ -67,6 +67,38 @@ module Mack
0
           FileUtils.rm_rf(dbs[:database]) if mode == :drop or mode == :drop_and_create
0
       end
0
     end
0
+    
0
+    def self.load_structure(file, env = Mack.env)
0
+      Mack::Database.establish_connection(env)
0
+      dbs = db_settings(env)
0
+      sql = File.read(file)
0
+      case dbs[:adapter]
0
+      when "mysql"
0
+        sql.split(";").each do |s|
0
+          s.strip! 
0
+          ActiveRecord::Base.connection.execute(s) unless s.blank?
0
+        end
0
+      else
0
+        ActiveRecord::Base.connection.execute(sql) unless sql.blank?
0
+      end
0
+    end
0
+    
0
+    def self.dump_structure(env = Mack.env)
0
+      Mack::Database.establish_connection(env)
0
+      dbs = db_settings(env)
0
+      structure = ""
0
+      output_file = File.join(Mack.root, "db", "#{env}_schema_structure.sql")
0
+      case dbs[:adapter]
0
+      when "mysql"
0
+        File.open(output_file, "w") {|f| f.puts ActiveRecord::Base.connection.structure_dump}
0
+      when "postgresql"
0
+        `pg_dump -i -U "#{dbs[:username]}" -s -x -O -n #{ENV["SCHEMA"] ||= "public"} -f #{output_file} #{dbs[:database]}`
0
+      when "sqlite3"
0
+        `sqlite3 #{dbs[:database]} .schema > #{output_file}`
0
+      else
0
+        raise "Task not supported for '#{dbs[:adapter]}'"
0
+      end
0
+    end
0
             
0
     private
0
     
...
1
2
3
4
5
6
...
1
2
 
3
4
5
0
@@ -1,6 +1,5 @@
0
 require 'pathname'
0
 require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
-require Pathname(__FILE__).dirname.expand_path + 'create_and_drop_task_helper'
0
 
0
 describe "rake" do
0
 
...
1
2
3
4
5
6
...
1
2
 
3
4
5
0
@@ -1,6 +1,5 @@
0
 require 'pathname'
0
 require Pathname(__FILE__).dirname.expand_path.parent.parent + 'spec_helper'
0
-require Pathname(__FILE__).dirname.expand_path + 'create_and_drop_task_helper'
0
 
0
 describe "rake" do
0
 
...
15
16
17
 
18
19
20
...
24
25
26
27
28
 
 
 
 
 
 
29
...
15
16
17
18
19
20
21
...
25
26
27
 
 
28
29
30
31
32
33
34
0
@@ -15,6 +15,7 @@ $genosaurus_output_directory = Mack.root
0
 
0
 require File.join(File.dirname(__FILE__), "..", "..", "mack-paths", "lib", "mack-paths")
0
 
0
+require File.join(File.dirname(__FILE__), 'create_and_drop_task_helper')
0
 
0
 def migrations_directory
0
   File.join(Mack.root, "db", "migrations")
0
@@ -24,6 +25,10 @@ def cleanup(file)
0
   File.delete(file) if !file.nil? and File.exists?(file)
0
 end
0
 
0
-def fixture(file)
0
-  File.read(File.join(File.dirname(__FILE__), "lib", "fixtures", file + ".fixtures"))
0
+def fixture(name)
0
+  File.read(fixture_location(name))
0
+end
0
+
0
+def fixture_location(name)
0
+  File.join(File.dirname(__FILE__), "fixtures", "#{name}.fixture")
0
 end
...
51
52
53
54
55
56
57
...
51
52
53
 
54
55
56
0
@@ -51,7 +51,6 @@ module Mack
0
       output_file = File.join(Mack.root, "db", "#{env}_#{repis}_schema_structure.sql")
0
       case adapter.class.name
0
       when /Mysql/
0
-        sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
0
         sql = "SHOW TABLES"
0
         adapter.query(sql).each do |res|
0
           show = adapter.query("SHOW CREATE TABLE #{res}").first

Comments