public
Description: A Ruby web application framework
Homepage: http://www.mackframework.com
Clone URL: git://github.com/markbates/mack.git
Click here to lend your support to: mack and make a donation at www.pledgie.com !
MigrationGenerator now uses the ModelColumnObject object.
markbates (author)
Fri Apr 18 12:37:27 -0700 2008
commit  04d21c01fece3a6556df545bcdc26201de7e35f8
tree    32fccfba6af28bd999b9bbd3e07c4e89329cd41a
parent  1b20bdeb7e8426b7617da49ef3c08f8160841fd5
...
76
77
78
79
 
80
81
82
83
84
85
 
86
87
88
...
76
77
78
 
79
80
81
82
83
84
 
85
86
87
88
0
@@ -76,13 +76,13 @@ module Mack
0
         puts "Created: #{output_dir}"
0
       end
0
       
0
- def columns
0
+ def columns(name = param(:name))
0
         ivar_cache("form_columns") do
0
           cs = []
0
           cols = (param(:cols) || param(:columns))
0
           if cols
0
             cols.split("|").each do |x|
0
- cs << Mack::Generator::ModelColumnObject.new(@name_singular, x)
0
+ cs << Mack::Generator::ModelColumnObject.new(name, x)
0
             end
0
           end
0
           cs
...
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
...
64
65
66
 
 
67
 
 
 
 
 
 
 
 
 
 
 
 
 
68
69
70
0
@@ -64,22 +64,7 @@ class MigrationGenerator < Mack::Generator::Migration::Base
0
     
0
     template_dir = File.join(File.dirname(__FILE__), "templates")
0
     
0
- @create_table_block = ""
0
- @drop_table_block = ""
0
     @table_name = param(:name).underscore.plural.gsub("create_", "")
0
- columns = ""
0
- cols = (param(:cols) || param(:columns))
0
- if cols
0
- cols = cols.split("|")
0
- cols.each_with_index do |v, i|
0
- x = v.split(":")
0
- columns << " t.column :#{x.first}, :#{x.last}\n"
0
- end
0
- @create_table_block = "create_table :#{@table_name} do |t|\n"
0
- @create_table_block << columns
0
- @create_table_block << " end"
0
- @drop_table_block = "drop_table :#{@table_name}"
0
- end
0
     
0
     template(File.join(template_dir, "migration.rb.template"), File.join(migrations_directory, "#{next_migration_number}_#{param(:name)}.rb"), :force => param(:force))
0
     
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
8
 
 
 
 
 
 
 
9
10
11
12
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
22
23
24
25
26
27
28
29
30
31
32
0
@@ -1,11 +1,31 @@
0
 class <%= param(:name).camelcase %> < <%= app_config.orm.camelcase %>::Migration
0
 
0
   def self.up
0
- <%= @create_table_block %>
0
+<%
0
+ unless columns.empty?
0
+-%>
0
+ create_table :<%= @table_name %> do |t|
0
+<%
0
+ for column in columns
0
+-%>
0
+ t.column :<%= column.column_name %>, :<%= column.column_type %>
0
+<%
0
+ end
0
+-%>
0
+ end
0
+<%
0
+ end
0
+-%>
0
   end
0
 
0
   def self.down
0
- <%= @drop_table_block %>
0
+<%
0
+ unless columns.empty?
0
+-%>
0
+ drop_table :<%= @table_name %>
0
+<%
0
+ end
0
+-%>
0
   end
0
 
0
 end
0
\ No newline at end of file
...
31
32
33
34
35
36
37
38
39
40
41
...
52
53
54
55
56
57
58
59
60
61
62
...
31
32
33
 
34
35
36
 
37
38
39
...
50
51
52
 
53
54
55
 
56
57
58
0
@@ -31,11 +31,9 @@ class MigrationGeneratorTest < Test::Unit::TestCase
0
 class FooBar < ActiveRecord::Migration
0
 
0
   def self.up
0
-
0
   end
0
 
0
   def self.down
0
-
0
   end
0
 
0
 end
0
@@ -52,11 +50,9 @@ MIG
0
 class FooBar < DataMapper::Migration
0
 
0
   def self.up
0
-
0
   end
0
 
0
   def self.down
0
-
0
   end
0
 
0
 end

Comments

    No one has commented yet.