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 specs for mack-data_mapper structure_dump [#67]
markbates (author)
Fri Aug 08 18:09:42 -0700 2008
commit  41ec8a0fe9fb206f5a6bb490a1e58655a712cef0
tree    627fad1c8d4e2f5290a4231214ff2086496a3bfd
parent  2263caf43ab79d61970f3e7148dafc39ffbaa0ff
...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
87
88
...
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
148
149
...
27
28
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
31
32
...
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
...
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
105
106
107
108
109
110
111
112
113
114
115
0
@@ -27,33 +27,6 @@ module Mack
0
       Mack::Database.establish_connection(env)
0
       drop_database(repis)
0
     end
0
-
0
-    # abcs = ActiveRecord::Base.configurations
0
-    # case abcs[RAILS_ENV]["adapter"]
0
-    # when "mysql", "oci", "oracle"
0
-    #   ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
0
-    #   File.open("db/#{RAILS_ENV}_structure.sql", "w+") { |f| f << ActiveRecord::Base.connection.structure_dump }
0
-    # when "postgresql"
0
-    #   ENV['PGHOST']     = abcs[RAILS_ENV]["host"] if abcs[RAILS_ENV]["host"]
0
-    #   ENV['PGPORT']     = abcs[RAILS_ENV]["port"].to_s if abcs[RAILS_ENV]["port"]
0
-    #   ENV['PGPASSWORD'] = abcs[RAILS_ENV]["password"].to_s if abcs[RAILS_ENV]["password"]
0
-    #   search_path = abcs[RAILS_ENV]["schema_search_path"]
0
-    #   search_path = "--schema=#{search_path}" if search_path
0
-    #   `pg_dump -i -U "#{abcs[RAILS_ENV]["username"]}" -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV]["database"]}`
0
-    #   raise "Error dumping database" if $?.exitstatus == 1
0
-    # when "sqlite", "sqlite3"
0
-    #   dbfile = abcs[RAILS_ENV]["database"] || abcs[RAILS_ENV]["dbfile"]
0
-    #   `#{abcs[RAILS_ENV]["adapter"]} #{dbfile} .schema > db/#{RAILS_ENV}_structure.sql`
0
-    # when "sqlserver"
0
-    #   `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
0
-    #   `scptxfr /s #{abcs[RAILS_ENV]["host"]} /d #{abcs[RAILS_ENV]["database"]} /I /F db\ /q /A /r`
0
-    # when "firebird"
0
-    #   set_firebird_env(abcs[RAILS_ENV])
0
-    #   db_string = firebird_db_string(abcs[RAILS_ENV])
0
-    #   sh "isql -a #{db_string} > db/#{RAILS_ENV}_structure.sql"
0
-    # else
0
-    #   raise "Task not supported by '#{abcs["test"]["adapter"]}'"
0
-    # end
0
     
0
     def self.structure_dump(env = Mack.env, repis = :default)
0
       adapter = repository(repis).adapter
0
@@ -61,28 +34,22 @@ module Mack
0
       structure = ""
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
0
-            structure += show.attributes["create table".to_sym]
0
-            structure += ";\n\n"
0
-          end
0
-          # puts structure
0
-          File.open(output_file, "w") {|f| f.puts structure}
0
-        when /Postgres/
0
-          `pg_dump -i -U "#{uri.user}" -s -x -O -f #{output_file} #{uri.basename}`
0
-          # setup_temp(uri, "postgres")
0
-          # repository(:tmp) do |repo|
0
-          #   puts "Creating (PostgreSQL): #{uri.basename}"
0
-          #   repo.adapter.execute "CREATE DATABASE #{uri.basename} ENCODING = 'utf8'"
0
-          # end
0
-        when /Sqlite3/
0
-          db_dir = File.join(Mack.root, "db")
0
-          `sqlite3 #{File.join(db_dir, uri.basename)} .schema > #{output_file}`
0
-        else
0
-          raise "Task not supported for '#{repository(repis).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
0
+          structure += show.attributes["create table".to_sym]
0
+          structure += ";\n\n"
0
+        end
0
+        File.open(output_file, "w") {|f| f.puts structure}
0
+      when /Postgres/
0
+        `pg_dump -i -U "#{uri.user}" -s -x -O -f #{output_file} #{uri.basename}`
0
+      when /Sqlite3/
0
+        db_dir = File.join(Mack.root, "db")
0
+        `sqlite3 #{File.join(db_dir, uri.basename)} .schema > #{output_file}`
0
+      else
0
+        raise "Task not supported for '#{repository(repis).adapter.class.name}'"
0
       end
0
     end
0
     
0
@@ -100,50 +67,49 @@ module Mack
0
     def self.create_database(repis = :default)
0
       uri = repository(repis).adapter.uri
0
       case repository(repis).adapter.class.name
0
-        when /Mysql/
0
-          setup_temp(uri, "mysql")
0
-          repository(:tmp) do |repo|
0
-            puts "Creating (MySQL): #{uri.basename}"
0
-            repo.adapter.execute "CREATE DATABASE `#{uri.basename}` DEFAULT CHARACTER SET `utf8`"
0
-          end
0
-        when /Postgres/
0
-          setup_temp(uri, "postgres")
0
-          repository(:tmp) do |repo|
0
-            puts "Creating (PostgreSQL): #{uri.basename}"
0
-            repo.adapter.execute "CREATE DATABASE #{uri.basename} ENCODING = 'utf8'"
0
-          end
0
-        when /Sqlite3/
0
-          db_dir = File.join(Mack.root, "db")
0
-          puts "Creating (SQLite3): #{uri.basename}"
0
-          FileUtils.mkdir_p(db_dir)
0
-          FileUtils.touch(File.join(db_dir, uri.basename))
0
-        else
0
-          raise "Task not supported for '#{repository(repis).adapter.class.name}'"
0
+      when /Mysql/
0
+        setup_temp(uri, "mysql")
0
+        repository(:tmp) do |repo|
0
+          puts "Creating (MySQL): #{uri.basename}"
0
+          repo.adapter.execute "CREATE DATABASE `#{uri.basename}` DEFAULT CHARACTER SET `utf8`"
0
+        end
0
+      when /Postgres/
0
+        setup_temp(uri, "postgres")
0
+        repository(:tmp) do |repo|
0
+          puts "Creating (PostgreSQL): #{uri.basename}"
0
+          repo.adapter.execute "CREATE DATABASE #{uri.basename} ENCODING = 'utf8'"
0
+        end
0
+      when /Sqlite3/
0
+        db_dir = File.join(Mack.root, "db")
0
+        puts "Creating (SQLite3): #{uri.basename}"
0
+        FileUtils.mkdir_p(db_dir)
0
+        FileUtils.touch(File.join(db_dir, uri.basename))
0
+      else
0
+        raise "Task not supported for '#{repository(repis).adapter.class.name}'"
0
       end
0
     end
0
     
0
-    
0
     def self.drop_database(repis = :default)
0
       uri = repository(repis).adapter.uri
0
       case repository(repis).adapter.class.name
0
-        when /Mysql/
0
-          setup_temp(uri, "mysql")
0
-          repository(:tmp) do |repo|
0
-            puts "Dropping (MySQL): #{uri.basename}"
0
-            repo.adapter.execute "DROP DATABASE IF EXISTS `#{uri.basename}`"
0
-          end
0
-        when /Postgres/
0
-          setup_temp(uri, "postgres")
0
-          repository(:tmp) do |repo|
0
-            puts "Dropping (PostgreSQL): #{uri.basename}"
0
-            repo.adapter.execute "DROP DATABASE IF EXISTS #{uri.basename}"
0
-          end
0
-        when /Sqlite3/
0
-          puts "Dropping (SQLite3): #{uri.basename}"
0
-          db_dir = File.join(Mack.root, "db")
0
-          FileUtils.rm_rf(File.join(db_dir.to_s, uri.basename))
0
-        else
0
-          raise "Task not supported for '#{repository(repis).adapter.class.name}'"
0
+      when /Mysql/
0
+        setup_temp(uri, "mysql")
0
+        repository(:tmp) do |repo|
0
+          puts "Dropping (MySQL): #{uri.basename}"
0
+          repo.adapter.execute "DROP DATABASE IF EXISTS `#{uri.basename}`"
0
+        end
0
+      when /Postgres/
0
+        setup_temp(uri, "postgres")
0
+        repository(:tmp) do |repo|
0
+          puts "Dropping (PostgreSQL): #{uri.basename}"
0
+          repo.adapter.execute "DROP DATABASE IF EXISTS #{uri.basename}"
0
+        end
0
+      when /Sqlite3/
0
+        puts "Dropping (SQLite3): #{uri.basename}"
0
+        db_dir = File.join(Mack.root, "db")
0
+        FileUtils.rm_rf(File.join(db_dir.to_s, uri.basename))
0
+      else
0
+        raise "Task not supported for '#{repository(repis).adapter.class.name}'"
0
       end
0
     end
0
     

Comments