[38300] branches/gsoc08-mpwa/db

digx at macports.org digx at macports.org
Mon Jul 14 21:47:41 PDT 2008


Revision: 38300
          http://trac.macosforge.org/projects/macports/changeset/38300
Author:   digx at macports.org
Date:     2008-07-14 21:47:41 -0700 (Mon, 14 Jul 2008)
Log Message:
-----------
Schema and migrations

Added Paths:
-----------
    branches/gsoc08-mpwa/db/migrate/
    branches/gsoc08-mpwa/db/migrate/20080714065738_acts_as_taggable_on_migration.rb
    branches/gsoc08-mpwa/db/migrate/20080715041010_rename_port_pkgs_to_packages.rb
    branches/gsoc08-mpwa/db/schema.rb

Added: branches/gsoc08-mpwa/db/migrate/20080714065738_acts_as_taggable_on_migration.rb
===================================================================
--- branches/gsoc08-mpwa/db/migrate/20080714065738_acts_as_taggable_on_migration.rb	                        (rev 0)
+++ branches/gsoc08-mpwa/db/migrate/20080714065738_acts_as_taggable_on_migration.rb	2008-07-15 04:47:41 UTC (rev 38300)
@@ -0,0 +1,39 @@
+class ActsAsTaggableOnMigration < ActiveRecord::Migration
+  def self.up
+    create_table :taggings do |t|
+      t.column :tag_id, :integer
+      t.column :taggable_id, :integer
+      t.column :taggable_type, :string
+      t.column :tagger_id, :integer
+      t.column :tagger_type, :string
+      t.column :context, :string      
+      t.column :created_at, :datetime
+    end
+    
+    add_index :taggings, :tag_id
+    add_index :taggings, [:taggable_id, :taggable_type, :context]
+    
+    puts "Transferring #{Port.count} ports to new schema.  This could take a while..."
+    
+    Port.find(:all).each do |port|
+      port.tags.each do |tag|
+        Tagging.create :tag_id => tag.id, :taggable_id => port.id, :taggable_type => 'Port', :context => 'tags'
+      end
+    end
+    
+    puts "Transferring #{PortPkg.count} port packages to new schema.  This could take a while..."
+    
+    PortPkg.find(:all).each do |portpkg|
+      portpkg.tags.each do |tag|
+         Tagging.create :tag_id => tag.id, :taggable_id => portpkg.id, :taggable_type => 'PortPkg', :context => 'tags'
+      end
+    end
+    
+    drop_table :ports_tags
+    drop_table :port_pkgs_tags
+  end
+  
+  def self.down
+    raise "Can't go down on this migration"
+  end
+end

Added: branches/gsoc08-mpwa/db/migrate/20080715041010_rename_port_pkgs_to_packages.rb
===================================================================
--- branches/gsoc08-mpwa/db/migrate/20080715041010_rename_port_pkgs_to_packages.rb	                        (rev 0)
+++ branches/gsoc08-mpwa/db/migrate/20080715041010_rename_port_pkgs_to_packages.rb	2008-07-15 04:47:41 UTC (rev 38300)
@@ -0,0 +1,26 @@
+class RenamePortPkgsToPackages < ActiveRecord::Migration
+  def self.up
+    # rename tables
+    rename_table :port_pkgs, :packages
+    rename_table :comments_port_pkgs, :comments_packages
+    rename_table :status_reports_port_pkgs, :status_reports_packages
+    rename_table :dependencies_port_pkgs, :dependencies_packages
+    
+    # rename columns
+    rename_column :comments_packages, :port_pkg_id, :package_id
+    
+    # update taggings
+    execute "UPDATE taggings SET taggable_type = 'Package' WHERE taggable_type = 'PortPkg'"
+  end
+
+  def self.down
+    rename_table :packages, :port_pkgs
+    rename_table :comments_packages, :comments_port_pkgs
+    rename_table :status_reports_packages, :status_reports_port_pkgs
+    rename_table :dependencies_packages, :dependencies_port_pkgs
+
+    rename_column :package_id, :port_pkg_id
+    
+    execute "UPDATE taggings SET taggable_type = 'PortPkg' WHERE taggable_type = 'Package'"
+  end
+end

Added: branches/gsoc08-mpwa/db/schema.rb
===================================================================
--- branches/gsoc08-mpwa/db/schema.rb	                        (rev 0)
+++ branches/gsoc08-mpwa/db/schema.rb	2008-07-15 04:47:41 UTC (rev 38300)
@@ -0,0 +1,172 @@
+# This file is auto-generated from the current state of the database. Instead of editing this file, 
+# please use the migrations feature of Active Record to incrementally modify your database, and
+# then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your database schema. If you need
+# to create the application database on another system, you should be using db:schema:load, not running
+# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20080715041010) do
+
+  create_table "comments", :force => true do |t|
+    t.integer   "commenter_id", :limit => 20, :null => false
+    t.text      "comment"
+    t.timestamp "comment_at",                 :null => false
+  end
+
+  create_table "comments_packages", :id => false, :force => true do |t|
+    t.integer "comment_id", :limit => 20,                :null => false
+    t.integer "package_id", :limit => 20, :default => 0, :null => false
+  end
+
+  create_table "comments_ports", :id => false, :force => true do |t|
+    t.integer "comment_id", :limit => 20, :null => false
+    t.integer "port_id",    :limit => 20, :null => false
+  end
+
+  create_table "dependencies", :force => true do |t|
+    t.text "expression"
+  end
+
+  create_table "dependencies_port_pkgs", :id => false, :force => true do |t|
+    t.integer "package_id",    :limit => 20, :null => false
+    t.integer "dependency_id", :limit => 20, :null => false
+  end
+
+  create_table "dependencies_variants", :id => false, :force => true do |t|
+    t.integer "variant_id",    :limit => 20, :null => false
+    t.integer "dependency_id", :limit => 20, :null => false
+  end
+
+  create_table "file_blobs", :force => true do |t|
+    t.integer "file_info_id", :limit => 20, :null => false
+    t.integer "sequence",     :limit => 11, :null => false
+    t.binary  "data"
+  end
+
+  add_index "file_blobs", ["file_info_id", "sequence"], :name => "file_index"
+
+  create_table "file_infos", :force => true do |t|
+    t.string  "file_path", :limit => 2047
+    t.integer "length",    :limit => 20,   :null => false
+    t.string  "mime_type", :limit => 63
+    t.string  "md5",       :limit => 32
+    t.string  "sha256",    :limit => 64
+  end
+
+  add_index "file_infos", ["file_path", "md5", "sha256"], :name => "info_index"
+
+  create_table "file_refs", :force => true do |t|
+    t.integer "file_info_id",   :limit => 20,                    :null => false
+    t.integer "port_pkg_id",    :limit => 20
+    t.boolean "is_port_pkg",                  :default => false, :null => false
+    t.integer "download_count", :limit => 11, :default => 0,     :null => false
+  end
+
+  add_index "file_refs", ["file_info_id"], :name => "file_index"
+  add_index "file_refs", ["port_pkg_id"], :name => "port_pkg_index"
+
+  create_table "maintainers_ports", :id => false, :force => true do |t|
+    t.integer "person_id", :limit => 20, :null => false
+    t.integer "port_id",   :limit => 20, :null => false
+  end
+
+  add_index "maintainers_ports", ["port_id"], :name => "port_index"
+  add_index "maintainers_ports", ["person_id"], :name => "person_index"
+
+  create_table "packages", :force => true do |t|
+    t.integer  "port_id",         :limit => 20,                :null => false
+    t.string   "name",            :limit => 63
+    t.text     "short_desc"
+    t.text     "long_desc"
+    t.string   "home_page"
+    t.datetime "submitted_at",                                 :null => false
+    t.integer  "submitter_id",    :limit => 20,                :null => false
+    t.text     "submitter_notes"
+    t.string   "epoch",           :limit => 32
+    t.string   "version",         :limit => 32
+    t.string   "revision",        :limit => 32
+    t.integer  "votes_for",       :limit => 11, :default => 0, :null => false
+    t.integer  "votes_against",   :limit => 11, :default => 0, :null => false
+    t.integer  "download_count",  :limit => 11, :default => 0, :null => false
+  end
+
+  add_index "packages", ["submitted_at"], :name => "submitted_at_index"
+  add_index "packages", ["submitter_id"], :name => "submitter_index"
+  add_index "packages", ["port_id"], :name => "port_index"
+
+  create_table "people", :force => true do |t|
+    t.string "user_name",   :limit => 63
+    t.string "first_name",  :limit => 63
+    t.string "last_name",   :limit => 63
+    t.string "email",       :limit => 63
+    t.string "auth_method", :limit => 31
+    t.string "auth_token"
+    t.text   "public_key"
+  end
+
+  create_table "port_pkg_files", :force => true do |t|
+    t.integer "port_pkg_id",    :limit => 20,                  :null => false
+    t.string  "file_path",      :limit => 2047
+    t.integer "length",         :limit => 20,                  :null => false
+    t.string  "mime_type",      :limit => 63
+    t.string  "md5",            :limit => 32
+    t.string  "sha256",         :limit => 64
+    t.integer "download_count", :limit => 11,   :default => 0, :null => false
+  end
+
+  add_index "port_pkg_files", ["port_pkg_id"], :name => "portpkgfile_pkgid"
+
+  create_table "ports", :force => true do |t|
+    t.string "name",       :limit => 63
+    t.text   "short_desc"
+    t.text   "long_desc"
+    t.string "home_page"
+  end
+
+  add_index "ports", ["name"], :name => "name_index"
+
+  create_table "status_reports", :force => true do |t|
+    t.integer   "reporter_id", :limit => 20, :null => false
+    t.integer   "report_type", :limit => 11
+    t.integer   "status",      :limit => 11
+    t.text      "report"
+    t.timestamp "report_at",                 :null => false
+  end
+
+  create_table "status_reports_port_pkgs", :id => false, :force => true do |t|
+    t.integer "status_report_id", :limit => 20, :null => false
+    t.integer "port_pkg_id",      :limit => 20, :null => false
+  end
+
+  create_table "taggings", :force => true do |t|
+    t.integer  "tag_id",        :limit => 11
+    t.integer  "taggable_id",   :limit => 11
+    t.integer  "tagger_id",     :limit => 11
+    t.string   "tagger_type"
+    t.string   "taggable_type"
+    t.string   "context"
+    t.datetime "created_at"
+  end
+
+  add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id"
+  add_index "taggings", ["taggable_id", "taggable_type", "context"], :name => "index_taggings_on_taggable_id_and_taggable_type_and_context"
+
+  create_table "tags", :force => true do |t|
+    t.string "name", :limit => 31
+  end
+
+  add_index "tags", ["name"], :name => "name_index"
+
+  create_table "variants", :force => true do |t|
+    t.integer "port_pkg_id", :limit => 20, :null => false
+    t.string  "name",        :limit => 63
+    t.text    "description"
+  end
+
+  add_index "variants", ["port_pkg_id"], :name => "port_pkg_index"
+
+end
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/macports-changes/attachments/20080714/c3929c12/attachment.html 


More information about the macports-changes mailing list