myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2406] trunk: added default values to download an


From: noreply
Subject: [myexperiment-hackers] [2406] trunk: added default values to download and viewing counts
Date: Thu, 13 May 2010 16:17:00 -0400 (EDT)

Revision
2406
Author
dgc
Date
2010-05-13 16:17:00 -0400 (Thu, 13 May 2010)

Log Message

added default values to download and viewing counts

Modified Paths

Diff

Modified: trunk/config/base_schema.xml (2405 => 2406)


--- trunk/config/base_schema.xml	2010-05-13 08:02:02 UTC (rev 2405)
+++ trunk/config/base_schema.xml	2010-05-13 20:17:00 UTC (rev 2406)
@@ -10,8 +10,8 @@
     <column type="integer"  name="policy_id"/>
     <column type="datetime" name="created_at"/>
     <column type="datetime" name="updated_at"/>
-    <column type="integer"  name="downloads_count"/>
-    <column type="integer"  name="viewings_count"/>
+    <column type="integer"  name="downloads_count" default="0"/>
+    <column type="integer"  name="viewings_count"  default="0"/>
     <column type="float"    name="rating"/>
     <column type="float"    name="rank"/>
 

Modified: trunk/vendor/plugins/structured_data/lib/auto_migrate.rb (2405 => 2406)


--- trunk/vendor/plugins/structured_data/lib/auto_migrate.rb	2010-05-13 08:02:02 UTC (rev 2405)
+++ trunk/vendor/plugins/structured_data/lib/auto_migrate.rb	2010-05-13 20:17:00 UTC (rev 2406)
@@ -10,7 +10,7 @@
   AUTO_TABLE_NAME       = "auto_tables"
   SCHEMA                = "config/base_schema.xml"
   SCHEMA_D              = "config/schema.d"
-  COLUMN_ATTRIBUTES     = ['name', 'type']
+  COLUMN_ATTRIBUTES     = ['name', 'type', 'default']
   BELONGS_TO_ATTRIBUTES = ['polymorphic']
   HAS_MANY_ATTRIBUTES   = ['target', 'through', 'foreign_key']
 
@@ -83,6 +83,14 @@
 
       old_columns = conn.columns(table_name).map do |column| column.name end - ["id"]
 
+      # and get detailed information about the existing columns
+
+      old_column_info = {}
+      
+      conn.columns(table_name).each do |c|
+        old_column_info[c.name] = c
+      end
+
       # determine the required columns
 
       new_columns = new_tables[table_name][:columns].map do |column, definition| column end
@@ -99,6 +107,24 @@
         conn.add_column(table_name, column_name, new_tables[table_name][:columns][column_name]["type"].to_sym)
       end
 
+      # modify existing columns
+
+      (old_columns & new_columns).each do |column_name|
+
+        old_default = old_column_info[column_name].default
+        new_default = new_tables[table_name][:columns][column_name]['default']
+
+        old_default = old_default.to_s unless old_default.nil?
+        new_default = new_default.to_s unless new_default.nil?
+
+        old_type    = old_column_info[column_name].type
+        new_type    = new_tables[table_name][:columns][column_name]['type'].to_sym
+
+        if (old_default != new_default) || (old_type != new_type)
+          conn.change_column(table_name.to_sym, column_name.to_sym, new_type, :default => new_default)
+        end
+      end
+
       # get the list of existing indexes
 
       old_indexes = conn.indexes(table_name).map do |index| [index.columns] end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]