ensured_schema 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,20 @@ module ActiveRecord
2
2
  module ConnectionAdapters
3
3
  class EnsuredTable < Table
4
4
 
5
+ def column(column_name, type, options = {})
6
+ if column_exists?(column_name)
7
+ unless column_exists?(column_name, type, options)
8
+ change(column_name, type, options)
9
+ end
10
+ else
11
+ @base.add_column(@table_name, column_name, type, options)
12
+ end
13
+ end
14
+
15
+ def remove(column_name)
16
+ super if column_exists?(column_name)
17
+ end
18
+
5
19
  %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
6
20
  class_eval <<-EOV
7
21
  def #{column_type}(*args) # def string(*args)
@@ -18,15 +32,7 @@ module ActiveRecord
18
32
  column_def = build_column_definition(name, column_type, options)
19
33
  def_options = column_def.members.inject({}){|h, k| h[k.to_sym] = column_def[k]; h;}
20
34
  #debugger
21
- if column_exists?(name)
22
- unless column_exists?(name, column_type, def_options)
23
- change(name, column_def.sql_type, options)
24
- puts "#{name} has been changed!"
25
- end
26
- else
27
- puts "creating column"
28
- @base.add_column(@table_name, name, column_def.sql_type, options)
29
- end
35
+ column(name, column_type.to_sym, def_options)
30
36
  end
31
37
  end
32
38
 
@@ -47,10 +47,8 @@ module ActiveRecord
47
47
 
48
48
  def table(table_name, options = {}, &block)
49
49
  if table_exists?(table_name)
50
- puts "table already exists"
51
50
  ensure_table(table_name, &block) # what to do about changing table options
52
51
  else
53
- puts "creating table"
54
52
  create_table(table_name, options, &block)
55
53
  end
56
54
  end
@@ -1,3 +1,3 @@
1
1
  module EnsuredSchema
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -20,7 +20,7 @@ if ActiveRecord::Base.connection.supports_migrations?
20
20
  @conn.drop_table("testings") if @conn.table_exists?("testings")
21
21
  end
22
22
 
23
- def testings_definition
23
+ def test_table_definition
24
24
  assert_nothing_raised do
25
25
  ActiveRecord::Schema.ensure(:version => '1') do
26
26
  table(:testings, :id => false, :force => true) do |t|
@@ -42,10 +42,12 @@ if ActiveRecord::Base.connection.supports_migrations?
42
42
  ActiveRecord::Schema.ensure(:version => '1') do
43
43
  table(:testings, :id => false, :force => true) do |t|
44
44
  t.string :test, :limit => 30, :default => "", :null => false
45
+ t.column :test2, :string
45
46
  end
46
47
  table(:testings, :id => false, :force => true) do |t|
47
48
  t.expects(:change).never
48
49
  t.string :test, :limit => 30, :default => "", :null => false
50
+ t.column :test2, :string
49
51
  end
50
52
  end
51
53
  end
@@ -183,6 +185,26 @@ if ActiveRecord::Base.connection.supports_migrations?
183
185
  assert @conn.column_exists?(:testings, :test)
184
186
  end
185
187
 
188
+ def test_column_is_removed_once
189
+ assert_nothing_raised do
190
+ ActiveRecord::Schema.ensure(:version => '1') do
191
+ table(:testings, :id => false, :force => true) do |t|
192
+ t.string :test, :limit => 30, :default => "", :null => false
193
+ t.string :test2
194
+ t.remove(:test)
195
+ t.remove(:test)
196
+ end
197
+ end
198
+
199
+ ActiveRecord::Schema.ensure(:version => '1') do
200
+ table(:testings, :id => false, :force => true) do |t|
201
+ t.remove(:test)
202
+ end
203
+ end
204
+ end
205
+ assert !@conn.column_exists?(:testings, :test)
206
+ end
207
+
186
208
  def test_ensure_index
187
209
  assert_nothing_raised do
188
210
  ActiveRecord::Schema.ensure(:version => '1') do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ensured_schema
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Chris Conley