Skip to content

Commit 7705c5a

Browse files
author
Rany Keddo
committed
1.0.0
1 parent 72f4c6f commit 7705c5a

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.0.0 (Febuary 09, 2012)
2+
3+
* added change_column
4+
* final 1.0 release
5+
16
# 1.0.0.rc8 (Febuary 09, 2012)
27

38
* removed spec binaries from gem bins

lib/lhm/migrator.rb

+15
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,21 @@ def add_column(name, definition)
5555
ddl("alter table `%s` add column `%s` %s" % [@name, name, definition])
5656
end
5757

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+
5873
# Remove a column from a table
5974
#
6075
# @example

lib/lhm/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# Schmidt
33

44
module Lhm
5-
VERSION = "1.0.0.rc8"
5+
VERSION = "1.0.0"
66
end

spec/integration/lhm_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@
103103
end
104104
end
105105

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+
106119
describe "parallel" do
107120
it "should perserve inserts during migration" do
108121
50.times { |n| execute("insert into users set reference = '#{ n }'") }

spec/unit/migrator_spec.rb

+9
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,15 @@
6464
"alter table `lhmn_alt` drop `logins`"
6565
])
6666
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
6776
end
6877

6978
describe "direct changes" do

0 commit comments

Comments
 (0)