active_record_schema 0.2.4 → 0.2.5

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.2.5
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "active_record_schema"
8
- s.version = "0.2.4"
8
+ s.version = "0.2.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mcasimir"]
@@ -7,6 +7,10 @@ module ActiveRecordSchema
7
7
  self.respond_to?(diff_method) ? self.send(diff_method) : []
8
8
  end
9
9
 
10
+ def table_exists?
11
+ _table_exists?
12
+ end
13
+
10
14
  def _diff_fields_add
11
15
  model.schema.fields.values.delete_if {|field| _column_names.include?(field.name.to_s) }
12
16
  end
@@ -29,16 +33,20 @@ module ActiveRecordSchema
29
33
  end
30
34
 
31
35
  def _column_names
32
- _connection.columns(_table).map(&:name)
36
+ _table_exists? ? _connection.columns(_table).map(&:name) : []
33
37
  end
34
38
 
35
39
  def _index_names
36
- _connection.indexes(_table).map(&:name)
40
+ _table_exists? ? _connection.indexes(_table).map(&:name) : []
37
41
  end
38
42
 
39
43
  def _table_names
40
44
  _connection.tables
41
45
  end
46
+
47
+ def _table_exists?
48
+ _connection.table_exists?(_table)
49
+ end
42
50
 
43
51
  end
44
52
  end
@@ -1,5 +1,9 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def change
3
+ <%- if !model.schema.table_exists? -%>
4
+ create_table :<%= model.table_name %>
5
+
6
+ <%- end -%>
3
7
  <%- model.schema.diff(:fields, :add).each do |field| -%>
4
8
  add_column :<%= model.table_name %>, <%= field.name.inspect %>, <%= field.type.inspect %><%= ", #{field.options.inspect}" if !field.options.blank? %>
5
9
  <%- end -%>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: 1144849732546431696
92
+ hash: -3601192281659392675
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements: