active_record_schema 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.5.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "active_record_schema"
8
- s.version = "0.5.4"
8
+ s.version = "0.5.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"]
12
- s.date = "2012-08-17"
12
+ s.date = "2012-08-19"
13
13
  s.description = "ActiveRecordSchema is an ActiveRecord extension that allows you to write the database schema for a model within the model itself and to generate migrations directly from models."
14
14
  s.email = "maurizio.cas@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -40,6 +40,10 @@ module Migration
40
40
  def model
41
41
  @current_model
42
42
  end
43
+
44
+ def inherits?
45
+ model.superclass < ActiveRecord::Base
46
+ end
43
47
 
44
48
  def models
45
49
  @models ||= model_names.map {|name|
@@ -1,26 +1,28 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
2
  def change
3
3
  <%- if !model.schema.table_exists? -%>
4
- create_table :<%= model.schema.prefixed_table_name %>
4
+ create_table :<%= model.schema.prefixed_table_name %> unless table_exists?(:<%= model.schema.prefixed_table_name %>)
5
5
 
6
6
  <%- end -%>
7
7
  <%- model.schema.diff(:fields, :add).each do |field| -%>
8
- add_column :<%= model.schema.prefixed_table_name %>, <%= field.name.inspect %>, <%= field.type.inspect %><%= ", #{field.options.inspect}" if !field.options.blank? %>
8
+ add_column :<%= model.schema.prefixed_table_name %>, <%= field.name.inspect %>, <%= field.type.inspect %><%= ", #{field.options.inspect}" if !field.options.blank? %> unless column_exists?(:<%= model.schema.prefixed_table_name %>, <%= field.name.inspect %>)
9
9
  <%- end -%>
10
10
 
11
11
  <%- model.schema.diff(:indexes, :add).each do |index| -%>
12
- add_index :<%= model.schema.prefixed_table_name %>, <%= index.name.inspect %><%= ", #{index.options.inspect}" if !index.options.blank? %>
12
+ add_index :<%= model.schema.prefixed_table_name %>, <%= index.name.inspect %><%= ", #{index.options.inspect}" if !index.options.blank? %> unless index_exists?(:<%= model.schema.prefixed_table_name %>, <%= index.name.inspect %>)
13
13
  <%- end -%>
14
14
 
15
15
  <%- model.schema.diff(:joins, :add).each do |join| -%>
16
- create_table :<%= join.table %>, :id => false do |t|
17
- t.integer <%= join.key1.inspect %>
18
- t.integer <%= join.key2.inspect %>
16
+ unless table_exists?(:<%= join.table %>)
17
+ create_table :<%= join.table %>, :id => false do |t|
18
+ t.integer <%= join.key1.inspect %>
19
+ t.integer <%= join.key2.inspect %>
20
+ end
21
+ <%- if join.index -%>
22
+ add_index :<%= join.table %>, <%= join.key1.inspect %>
23
+ add_index :<%= join.table %>, <%= join.key2.inspect %>
24
+ <%- end -%>
19
25
  end
20
- <%- if join.index -%>
21
- add_index :<%= join.table %>, <%= join.key1.inspect %>
22
- add_index :<%= join.table %>, <%= join.key2.inspect %>
23
- <%- end -%>
24
26
  <%- end -%>
25
27
  end
26
28
  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.5.4
4
+ version: 0.5.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-17 00:00:00.000000000 Z
12
+ date: 2012-08-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -86,7 +86,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: -884911166514939792
89
+ hash: -2284041961868308555
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  none: false
92
92
  requirements: