Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

1.0.0

  • Loading branch information...
commit 7705c5a942197837748f2b5bcf6fb497148d9935 1 parent 72f4c6f
Rany Keddo authored February 09, 2012
5  CHANGELOG.md
Source Rendered
... ...
@@ -1,3 +1,8 @@
  1
+# 1.0.0 (Febuary 09, 2012)
  2
+
  3
+* added change_column
  4
+* final 1.0 release
  5
+
1 6
 # 1.0.0.rc8 (Febuary 09, 2012)
2 7
 
3 8
 * removed spec binaries from gem bins
15  lib/lhm/migrator.rb
@@ -55,6 +55,21 @@ def add_column(name, definition)
55 55
       ddl("alter table `%s` add column `%s` %s" % [@name, name, definition])
56 56
     end
57 57
 
  58
+    # Change an existing column to a new definition
  59
+    #
  60
+    # @example
  61
+    #
  62
+    #   Lhm.change_table(:users) do |m|
  63
+    #     m.change_column(:comment, "VARCHAR(12) DEFAULT '0' NOT NULL")
  64
+    #   end
  65
+    #
  66
+    # @param [String] name Name of the column to change
  67
+    # @param [String] definition Valid SQL column definition
  68
+    def change_column(name, definition)
  69
+      remove_column(name)
  70
+      add_column(name, definition)
  71
+    end
  72
+
58 73
     # Remove a column from a table
59 74
     #
60 75
     # @example
2  lib/lhm/version.rb
@@ -2,5 +2,5 @@
2 2
 # Schmidt
3 3
 
4 4
 module Lhm
5  
-  VERSION = "1.0.0.rc8"
  5
+  VERSION = "1.0.0"
6 6
 end
13  spec/integration/lhm_spec.rb
@@ -103,6 +103,19 @@
103 103
       end
104 104
     end
105 105
 
  106
+    it "should change a column" do
  107
+      Lhm.change_table(:users) do |t|
  108
+        t.change_column(:comment, "varchar(20) DEFAULT 'none' NOT NULL")
  109
+      end
  110
+
  111
+      slave do
  112
+        table_read(:users).columns["comment"].must_equal({
  113
+          :type => "varchar(20)",
  114
+          :metadata => "NOT NULL DEFAULT 'none'"
  115
+        })
  116
+      end
  117
+    end
  118
+
106 119
     describe "parallel" do
107 120
       it "should perserve inserts during migration" do
108 121
         50.times { |n| execute("insert into users set reference = '#{ n }'") }
9  spec/unit/migrator_spec.rb
@@ -64,6 +64,15 @@
64 64
         "alter table `lhmn_alt` drop `logins`"
65 65
       ])
66 66
     end
  67
+
  68
+    it "should change a column" do
  69
+      @creator.change_column("logins", "INT(255)")
  70
+
  71
+      @creator.statements.must_equal([
  72
+        "alter table `lhmn_alt` drop `logins`",
  73
+        "alter table `lhmn_alt` add column `logins` INT(255)"
  74
+      ])
  75
+    end
67 76
   end
68 77
 
69 78
   describe "direct changes" do

0 notes on commit 7705c5a

Please sign in to comment.
Something went wrong with that request. Please try again.