schema_plus 0.4.1 → 1.0.0
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/.gitignore +3 -1
- data/.travis.yml +6 -9
- data/Gemfile +0 -4
- data/README.rdoc +168 -70
- data/Rakefile +58 -47
- data/gemfiles/rails-3.2/Gemfile.base +4 -0
- data/gemfiles/rails-3.2/Gemfile.mysql +4 -0
- data/gemfiles/rails-3.2/Gemfile.mysql2 +4 -0
- data/gemfiles/rails-3.2/Gemfile.postgresql +4 -0
- data/gemfiles/rails-3.2/Gemfile.sqlite3 +4 -0
- data/lib/schema_plus.rb +2 -0
- data/lib/schema_plus/active_record/column_options_handler.rb +73 -32
- data/lib/schema_plus/active_record/connection_adapters/abstract_adapter.rb +60 -31
- data/lib/schema_plus/active_record/connection_adapters/foreign_key_definition.rb +7 -2
- data/lib/schema_plus/active_record/connection_adapters/index_definition.rb +2 -1
- data/lib/schema_plus/active_record/connection_adapters/mysql_adapter.rb +19 -1
- data/lib/schema_plus/active_record/connection_adapters/postgresql_adapter.rb +68 -17
- data/lib/schema_plus/active_record/connection_adapters/sqlite3_adapter.rb +28 -3
- data/lib/schema_plus/active_record/connection_adapters/table_definition.rb +27 -1
- data/lib/schema_plus/active_record/db_default.rb +19 -0
- data/lib/schema_plus/active_record/foreign_keys.rb +40 -32
- data/lib/schema_plus/active_record/schema_dumper.rb +7 -3
- data/lib/schema_plus/version.rb +1 -1
- data/runspecs +5 -8
- data/schema_plus.gemspec +2 -5
- data/spec/column_definition_spec.rb +18 -1
- data/spec/column_spec.rb +39 -2
- data/spec/connection_spec.rb +1 -1
- data/spec/connections/mysql/connection.rb +1 -1
- data/spec/connections/mysql2/connection.rb +1 -1
- data/spec/connections/postgresql/connection.rb +1 -1
- data/spec/foreign_key_definition_spec.rb +0 -4
- data/spec/foreign_key_spec.rb +37 -13
- data/spec/index_definition_spec.rb +54 -2
- data/spec/index_spec.rb +59 -15
- data/spec/migration_spec.rb +336 -85
- data/spec/multiple_schemas_spec.rb +127 -0
- data/spec/schema_dumper_spec.rb +65 -25
- data/spec/schema_spec.rb +16 -18
- data/spec/spec_helper.rb +19 -18
- data/spec/support/matchers/reference.rb +7 -1
- data/spec/views_spec.rb +5 -2
- metadata +43 -54
- data/gemfiles/Gemfile.rails-2.3 +0 -6
- data/gemfiles/Gemfile.rails-2.3.lock +0 -65
- data/gemfiles/Gemfile.rails-3.0 +0 -5
- data/gemfiles/Gemfile.rails-3.0.lock +0 -113
- data/gemfiles/Gemfile.rails-3.1 +0 -5
- data/gemfiles/Gemfile.rails-3.1.lock +0 -123
- data/gemfiles/Gemfile.rails-3.2 +0 -5
- data/gemfiles/Gemfile.rails-3.2.lock +0 -121
- data/spec/models/comment.rb +0 -2
- data/spec/models/post.rb +0 -2
- data/spec/models/user.rb +0 -2
- data/spec/rails3_migration_spec.rb +0 -144
data/spec/models/comment.rb
DELETED
data/spec/models/post.rb
DELETED
data/spec/models/user.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
|
-
|
4
|
-
describe ActiveRecord::Migration do
|
5
|
-
include SchemaPlusHelpers
|
6
|
-
|
7
|
-
before(:all) do
|
8
|
-
load_auto_schema
|
9
|
-
end
|
10
|
-
|
11
|
-
around(:each) do |example|
|
12
|
-
with_fk_config(:auto_create => true, :auto_index => true) { example.run }
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when table is created" do
|
16
|
-
|
17
|
-
before(:each) do
|
18
|
-
@model = Post
|
19
|
-
end
|
20
|
-
|
21
|
-
it "should create foreign keys" do
|
22
|
-
create_table(:user_id => {},
|
23
|
-
:author_id => { :references => :users },
|
24
|
-
:member_id => { :references => nil } )
|
25
|
-
@model.should reference(:users, :id).on(:user_id)
|
26
|
-
@model.should reference(:users, :id).on(:author_id)
|
27
|
-
@model.should_not reference.on(:member_id)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
unless SchemaPlusHelpers.sqlite3?
|
33
|
-
|
34
|
-
context "when column is added" do
|
35
|
-
|
36
|
-
before(:each) do
|
37
|
-
@model = Comment
|
38
|
-
end
|
39
|
-
|
40
|
-
it "should create a foreign key" do
|
41
|
-
add_column(:post_id, :integer) do
|
42
|
-
@model.should reference(:posts, :id).on(:post_id)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should create an index" do
|
47
|
-
add_column(:post_id, :integer) do
|
48
|
-
@model.should have_index.on(:post_id)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
context "when column is changed" do
|
55
|
-
|
56
|
-
before(:each) do
|
57
|
-
@model = Comment
|
58
|
-
end
|
59
|
-
|
60
|
-
it "should create a foreign key" do
|
61
|
-
change_column :user, :string, :references => [:users, :login]
|
62
|
-
@model.should reference(:users, :login).on(:user)
|
63
|
-
change_column :user, :string, :references => nil
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should remove a foreign key" do
|
67
|
-
@model.should reference(:users, :id).on(:user_id)
|
68
|
-
change_column :user_id, :integer, :references => nil
|
69
|
-
@model.should_not reference(:users, :id).on(:user_id)
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
73
|
-
|
74
|
-
context "when column is removed" do
|
75
|
-
|
76
|
-
before(:each) do
|
77
|
-
@model = Comment
|
78
|
-
end
|
79
|
-
|
80
|
-
it "should remove a foreign key" do
|
81
|
-
suppress_messages do
|
82
|
-
target.add_column(@model.table_name, :post_id, :integer)
|
83
|
-
target.remove_column(@model.table_name, :post_id)
|
84
|
-
end
|
85
|
-
@model.should_not reference(:posts)
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should remove an index" do
|
89
|
-
suppress_messages do
|
90
|
-
target.add_column(@model.table_name, :post_id, :integer)
|
91
|
-
target.remove_column(@model.table_name, :post_id)
|
92
|
-
end
|
93
|
-
@model.should_not have_index.on(:post_id)
|
94
|
-
end
|
95
|
-
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
protected
|
101
|
-
def target
|
102
|
-
ActiveRecord::Migration.connection
|
103
|
-
end
|
104
|
-
|
105
|
-
def add_column(column_name, *args)
|
106
|
-
table = @model.table_name
|
107
|
-
suppress_messages do
|
108
|
-
target.add_column(table, column_name, *args)
|
109
|
-
@model.reset_column_information
|
110
|
-
yield if block_given?
|
111
|
-
target.remove_column(table, column_name)
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
def change_column(column_name, *args)
|
116
|
-
table = @model.table_name
|
117
|
-
suppress_messages do
|
118
|
-
target.change_column(table, column_name, *args)
|
119
|
-
@model.reset_column_information
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
def create_table(columns_with_options)
|
124
|
-
suppress_messages do
|
125
|
-
target.create_table @model.table_name, :force => true do |t|
|
126
|
-
columns_with_options.each_pair do |column, options|
|
127
|
-
t.send :integer, column, options
|
128
|
-
end
|
129
|
-
end
|
130
|
-
@model.reset_column_information
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
def with_fk_config(opts, &block)
|
135
|
-
save = Hash[opts.keys.collect{|key| [key, SchemaPlus.config.foreign_keys.send(key)]}]
|
136
|
-
begin
|
137
|
-
SchemaPlus.config.foreign_keys.update_attributes(opts)
|
138
|
-
yield
|
139
|
-
ensure
|
140
|
-
SchemaPlus.config.foreign_keys.update_attributes(save)
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|