<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -27,6 +27,64 @@ module Mack
       Mack::Database.establish_connection(env)
       drop_database(repis)
     end
+
+    # abcs = ActiveRecord::Base.configurations
+    # case abcs[RAILS_ENV][&quot;adapter&quot;]
+    # when &quot;mysql&quot;, &quot;oci&quot;, &quot;oracle&quot;
+    #   ActiveRecord::Base.establish_connection(abcs[RAILS_ENV])
+    #   File.open(&quot;db/#{RAILS_ENV}_structure.sql&quot;, &quot;w+&quot;) { |f| f &lt;&lt; ActiveRecord::Base.connection.structure_dump }
+    # when &quot;postgresql&quot;
+    #   ENV['PGHOST']     = abcs[RAILS_ENV][&quot;host&quot;] if abcs[RAILS_ENV][&quot;host&quot;]
+    #   ENV['PGPORT']     = abcs[RAILS_ENV][&quot;port&quot;].to_s if abcs[RAILS_ENV][&quot;port&quot;]
+    #   ENV['PGPASSWORD'] = abcs[RAILS_ENV][&quot;password&quot;].to_s if abcs[RAILS_ENV][&quot;password&quot;]
+    #   search_path = abcs[RAILS_ENV][&quot;schema_search_path&quot;]
+    #   search_path = &quot;--schema=#{search_path}&quot; if search_path
+    #   `pg_dump -i -U &quot;#{abcs[RAILS_ENV][&quot;username&quot;]}&quot; -s -x -O -f db/#{RAILS_ENV}_structure.sql #{search_path} #{abcs[RAILS_ENV][&quot;database&quot;]}`
+    #   raise &quot;Error dumping database&quot; if $?.exitstatus == 1
+    # when &quot;sqlite&quot;, &quot;sqlite3&quot;
+    #   dbfile = abcs[RAILS_ENV][&quot;database&quot;] || abcs[RAILS_ENV][&quot;dbfile&quot;]
+    #   `#{abcs[RAILS_ENV][&quot;adapter&quot;]} #{dbfile} .schema &gt; db/#{RAILS_ENV}_structure.sql`
+    # when &quot;sqlserver&quot;
+    #   `scptxfr /s #{abcs[RAILS_ENV][&quot;host&quot;]} /d #{abcs[RAILS_ENV][&quot;database&quot;]} /I /f db\\#{RAILS_ENV}_structure.sql /q /A /r`
+    #   `scptxfr /s #{abcs[RAILS_ENV][&quot;host&quot;]} /d #{abcs[RAILS_ENV][&quot;database&quot;]} /I /F db\ /q /A /r`
+    # when &quot;firebird&quot;
+    #   set_firebird_env(abcs[RAILS_ENV])
+    #   db_string = firebird_db_string(abcs[RAILS_ENV])
+    #   sh &quot;isql -a #{db_string} &gt; db/#{RAILS_ENV}_structure.sql&quot;
+    # else
+    #   raise &quot;Task not supported by '#{abcs[&quot;test&quot;][&quot;adapter&quot;]}'&quot;
+    # end
+    
+    def self.structure_dump(env = Mack.env, repis = :default)
+      adapter = repository(repis).adapter
+      uri = adapter.uri
+      structure = &quot;&quot;
+      output_file = File.join(Mack.root, &quot;db&quot;, &quot;#{env}_#{repis}_schema_structure.sql&quot;)
+      case adapter.class.name
+        when /Mysql/
+          sql = &quot;SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'&quot;
+          sql = &quot;SHOW TABLES&quot;
+          adapter.query(sql).each do |res|
+            show = adapter.query(&quot;SHOW CREATE TABLE #{res}&quot;).first
+            structure += show.attributes[&quot;create table&quot;.to_sym]
+            structure += &quot;;\n\n&quot;
+          end
+          # puts structure
+          File.open(output_file, &quot;w&quot;) {|f| f.puts structure}
+        when /Postgres/
+          `pg_dump -i -U &quot;#{uri.user}&quot; -s -x -O -f #{output_file} #{uri.basename}`
+          # setup_temp(uri, &quot;postgres&quot;)
+          # repository(:tmp) do |repo|
+          #   puts &quot;Creating (PostgreSQL): #{uri.basename}&quot;
+          #   repo.adapter.execute &quot;CREATE DATABASE #{uri.basename} ENCODING = 'utf8'&quot;
+          # end
+        when /Sqlite3/
+          db_dir = File.join(Mack.root, &quot;db&quot;)
+          `sqlite3 #{File.join(db_dir, uri.basename)} .schema &gt; #{output_file}`
+        else
+          raise &quot;Task not supported for '#{repository(repis).adapter.class.name}'&quot;
+      end
+    end
     
     private
     def self.setup_temp(uri, adapter)</diff>
      <filename>mack-data_mapper/lib/mack-data_mapper/database.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,6 +37,15 @@ namespace :db do
     DataMapper::MigrationRunner.migrations.clear
   end
   
+  namespace :structure do
+    
+    desc &quot;Dump the database structure to a SQL file&quot;
+    task :dump =&gt; &quot;mack:environment&quot; do
+      Mack::Database.structure_dump
+    end
+    
+  end
+  
   private
   
   def migration_files</diff>
      <filename>mack-data_mapper/lib/mack-data_mapper/tasks/db_migration_tasks.rake</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>142b967dcb082b9fcfabf4ea8da85904c3ab2917</id>
    </parent>
  </parents>
  <author>
    <name>Mark Bates</name>
    <email>mark@markbates.com</email>
  </author>
  <url>http://github.com/markbates/mack-more/commit/2263caf43ab79d61970f3e7148dafc39ffbaa0ff</url>
  <id>2263caf43ab79d61970f3e7148dafc39ffbaa0ff</id>
  <committed-date>2008-08-08T14:45:24-07:00</committed-date>
  <authored-date>2008-08-08T14:45:24-07:00</authored-date>
  <message>The beginnings of adding proper db:structure:dump and db:structure:load tasks. [#67]</message>
  <tree>1afcaca76ec16e525181bcc814d6bcb173d5fb04</tree>
  <committer>
    <name>Mark Bates</name>
    <email>mark@markbates.com</email>
  </committer>
</commit>
