active_record_inline_schema 0.5.7 → 0.5.9
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/CHANGELOG +20 -0
- data/lib/active_record_inline_schema/config.rb +26 -40
- data/lib/active_record_inline_schema/version.rb +1 -1
- data/spec/models.rb +6 -0
- data/spec/shared_examples.rb +5 -13
- data/spec/sqlite3_spec.rb +1 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
0.5.9 / 2012-07-26
|
2
|
+
|
3
|
+
* Bug fixes
|
4
|
+
|
5
|
+
* Don't try to use ActiveRecord::Base.checkout with SQLite - it causes "Could not find table" errors
|
6
|
+
|
7
|
+
0.5.8 / 2012-07-26
|
8
|
+
|
9
|
+
* Breaking changes
|
10
|
+
|
11
|
+
* No longer automatically adds inheritance columns - you should specify them like "col :type"
|
12
|
+
|
13
|
+
* Enhancements
|
14
|
+
|
15
|
+
* A bit more testing of how primary keys work.
|
16
|
+
|
17
|
+
* Notes
|
18
|
+
|
19
|
+
* Something is going horribly wrong with SQLite support - lots of "Could not find table" errors. Hoping we can revisit this when sqlite3 gem 1.3.7 comes out.
|
20
|
+
|
1
21
|
0.5.7 / 2012-06-22
|
2
22
|
|
3
23
|
* Bug fix
|
@@ -28,50 +28,44 @@ class ActiveRecordInlineSchema::Config
|
|
28
28
|
primary_key_column.type != :primary_key
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
if non_standard_primary_key
|
32
|
+
if postgresql? or sqlite?
|
33
|
+
primary_key_column.options[:null] = false
|
34
|
+
end
|
35
|
+
else
|
32
36
|
add_ideal_column :id, :type => :primary_key
|
33
37
|
end
|
34
38
|
|
39
|
+
table_definition = ActiveRecord::ConnectionAdapters::TableDefinition.new connection
|
40
|
+
ideal_columns.each do |ideal_column|
|
41
|
+
ideal_column.inject table_definition
|
42
|
+
end
|
43
|
+
|
35
44
|
# Table doesn't exist, create it
|
36
45
|
unless connection.table_exists? model.table_name
|
46
|
+
create_table_options ||= DEFAULT_CREATE_TABLE_OPTIONS[database_type]
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
48
|
+
statements = []
|
49
|
+
statements << "CREATE TABLE #{model.quoted_table_name} (#{table_definition.to_sql}) #{create_table_options}"
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
if non_standard_primary_key
|
52
|
+
if postgresql?
|
53
|
+
statements << %{ALTER TABLE #{model.quoted_table_name} ADD PRIMARY KEY (#{model.quoted_primary_key})}
|
54
|
+
elsif mysql?
|
55
|
+
k = model.quoted_primary_key
|
56
|
+
statements.first.sub! /#{k}([^\)]+)\)([^\),]*)/, "#{k}\\1) PRIMARY KEY"
|
57
|
+
end
|
45
58
|
end
|
46
59
|
|
47
|
-
|
48
|
-
|
49
|
-
create_sql = "CREATE TABLE #{model.quoted_table_name} (#{table_definition.to_sql}) #{create_table_options}"
|
50
|
-
|
51
|
-
if sqlite?
|
52
|
-
connection.execute create_sql
|
53
|
-
if non_standard_primary_key
|
54
|
-
add_ideal_index model.primary_key, :unique => true
|
55
|
-
end
|
56
|
-
elsif postgresql?
|
57
|
-
connection.execute create_sql
|
58
|
-
if non_standard_primary_key
|
59
|
-
# can't use add_index method because it won't let you do "PRIMARY KEY"
|
60
|
-
connection.execute "ALTER TABLE #{model.quoted_table_name} ADD PRIMARY KEY (#{model.quoted_primary_key})"
|
61
|
-
end
|
62
|
-
elsif mysql?
|
63
|
-
if non_standard_primary_key
|
64
|
-
k = connection.quote_column_name(model.primary_key)
|
65
|
-
create_sql.sub! /#{k}([^\)]+)\)([^\),]*)/, "#{k}\\1) PRIMARY KEY"
|
66
|
-
end
|
67
|
-
connection.execute create_sql
|
60
|
+
statements.each do |sql|
|
61
|
+
connection.execute sql
|
68
62
|
end
|
69
63
|
safe_reset_column_information
|
70
64
|
end
|
71
65
|
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
if non_standard_primary_key and sqlite?
|
67
|
+
# make sure this doesn't get deleted later
|
68
|
+
add_ideal_index model.primary_key, :unique => true
|
75
69
|
end
|
76
70
|
|
77
71
|
# Remove fields from db no longer in schema
|
@@ -128,11 +122,6 @@ class ActiveRecordInlineSchema::Config
|
|
128
122
|
safe_reset_column_information
|
129
123
|
end
|
130
124
|
|
131
|
-
def clear
|
132
|
-
@ideal_columns = ::Set.new
|
133
|
-
@ideal_indexes = ::Set.new
|
134
|
-
end
|
135
|
-
|
136
125
|
private
|
137
126
|
|
138
127
|
def find_ideal_column(name)
|
@@ -177,14 +166,11 @@ class ActiveRecordInlineSchema::Config
|
|
177
166
|
end
|
178
167
|
|
179
168
|
def connection
|
180
|
-
unless model.connection.active?
|
181
|
-
raise ::RuntimeError, %{[active_record_inline_schema] Must connect to database before running ActiveRecord::Base.auto_upgrade!}
|
182
|
-
end
|
183
169
|
model.connection
|
184
170
|
end
|
185
171
|
|
186
172
|
def database_type
|
187
|
-
if mysql?
|
173
|
+
@database_type ||= if mysql?
|
188
174
|
:mysql
|
189
175
|
elsif postgresql?
|
190
176
|
:postgresql
|
data/spec/models.rb
CHANGED
@@ -34,6 +34,7 @@ class Pet < ActiveRecord::Base
|
|
34
34
|
include SpecHelper
|
35
35
|
|
36
36
|
col :name
|
37
|
+
col :type
|
37
38
|
add_index :name
|
38
39
|
end
|
39
40
|
class Dog < Pet; end
|
@@ -103,6 +104,11 @@ class Pet5 < ActiveRecord::Base
|
|
103
104
|
col :id, :type => :integer
|
104
105
|
end
|
105
106
|
|
107
|
+
class Pet6 < ActiveRecord::Base
|
108
|
+
include SpecHelper
|
109
|
+
col :yesno, :type => :boolean
|
110
|
+
end
|
111
|
+
|
106
112
|
case ENV['DB_ADAPTER']
|
107
113
|
when 'mysql'
|
108
114
|
class CustomMysql < ActiveRecord::Base
|
data/spec/shared_examples.rb
CHANGED
@@ -42,6 +42,11 @@ describe ActiveRecordInlineSchema do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
it "supports boolean columns" do
|
46
|
+
Pet6.auto_upgrade!
|
47
|
+
Pet6.columns_hash['yesno'].type.must_equal :boolean
|
48
|
+
end
|
49
|
+
|
45
50
|
it 'has #key,col,property,attribute inside model' do
|
46
51
|
(!!ActiveRecord::Base.connection.table_exists?(Post.table_name)).must_equal false
|
47
52
|
(!!ActiveRecord::Base.connection.table_exists?(Category.table_name)).must_equal false
|
@@ -56,19 +61,6 @@ describe ActiveRecordInlineSchema do
|
|
56
61
|
post.title.must_equal 'foo'
|
57
62
|
post.body.must_equal 'bar'
|
58
63
|
post.category.must_equal category
|
59
|
-
|
60
|
-
|
61
|
-
# Remove a column
|
62
|
-
Post.inline_schema_config.clear
|
63
|
-
Post.class_eval do
|
64
|
-
col :name
|
65
|
-
col :category_id, :type => :integer
|
66
|
-
end
|
67
|
-
Post.auto_upgrade!
|
68
|
-
post = Post.first
|
69
|
-
post.name.must_be_nil
|
70
|
-
post.category.must_equal category
|
71
|
-
post.wont_respond_to :title
|
72
64
|
end
|
73
65
|
|
74
66
|
it 'has indexes inside model' do
|
data/spec/sqlite3_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path('../spec_helper.rb', __FILE__)
|
2
2
|
|
3
|
-
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
3
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:', :pool => 32)
|
4
4
|
|
5
5
|
# require 'logger'
|
6
6
|
# ActiveRecord::Base.logger = ActiveSupport::BufferedLogger.new($stdout)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_inline_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-07-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|