schema_plus 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb0e9e9c0ae722f3745bf153ca27e10feba32557
4
- data.tar.gz: 475c3532ec3953c3b34c68357dec44b69b5554e5
3
+ metadata.gz: 0d5b988ea47657ad4e1be912509f3d17c4c4e329
4
+ data.tar.gz: e4fcc4ac3d1ca3003e4a9c7fc1c0a48e687dd197
5
5
  SHA512:
6
- metadata.gz: b0e183c3f7af709ebe5b8fb73f9278a3c5a9cf1a9d31ae39934d12ef727df309772edc43dfbf5e06b4202a5216f19307d4438da67c883e6a974ec2c581b0692d
7
- data.tar.gz: 5fe1d3eaacef6220fa894d3b491fddeac460856567e32972a63d95373e590e9a0ddc58111bd6ee198dd3baa1e520ee834cedc81dc798f1e5f3bd19735c904dfa
6
+ metadata.gz: 4ea4f3e69dd6fd4705146b05123e7ec245414ef77de85382a5ada63bebfce065088d4447ea9f411b82444d33c94d7a9ce6ad96a76061816a7a851023a9672e8f
7
+ data.tar.gz: 9251ec18b5b5f416627162c4adecff472c22c82ac23076461d7b8d045f40744f246827da14580c17d5957efb45218a7b235d71ffbcc1092e1b7486a4547cc3f2
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.9.3
3
3
  - 2.0.0
4
+ - 2.1.0
4
5
  - jruby
5
6
  gemfile:
6
7
  - gemfiles/rails-3.2/Gemfile.postgresql
@@ -10,48 +11,38 @@ gemfile:
10
11
  - gemfiles/rails-4.0/Gemfile.postgresql
11
12
  - gemfiles/rails-4.0/Gemfile.sqlite3
12
13
  - gemfiles/rails-4.0/Gemfile.mysql2
13
- - gemfiles/rails-edge/Gemfile.postgresql
14
- - gemfiles/rails-edge/Gemfile.sqlite3
15
- - gemfiles/rails-edge/Gemfile.mysql2
14
+ - gemfiles/rails-4.1/Gemfile.postgresql
15
+ - gemfiles/rails-4.1/Gemfile.sqlite3
16
+ - gemfiles/rails-4.1/Gemfile.mysql2
16
17
  before_script:
17
18
  - rake create_databases
18
19
  after_script:
19
20
  - rake drop_databases
20
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
21
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
21
22
  notifications:
22
23
  recipients:
23
24
  - michal.lomnicki@gmail.com
24
25
  - ronen@barzel.org
25
26
  matrix:
26
- allow_failures:
27
- - gemfile: gemfiles/rails-edge/Gemfile.postgresql
28
- - gemfile: gemfiles/rails-edge/Gemfile.sqlite3
29
- - gemfile: gemfiles/rails-edge/Gemfile.mysql2
30
27
  exclude:
31
28
  - rvm: jruby
32
29
  gemfile: gemfiles/rails-3.2/Gemfile.sqlite3
33
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
34
- - rvm: jruby
35
- gemfile: gemfiles/rails-3.2/Gemfile.mysql
36
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
37
- - rvm: jruby
38
- gemfile: gemfiles/rails-3.2/Gemfile.mysql2
39
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
30
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
40
31
  - rvm: jruby
41
32
  gemfile: gemfiles/rails-4.0/Gemfile.postgresql
42
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
33
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
43
34
  - rvm: jruby
44
35
  gemfile: gemfiles/rails-4.0/Gemfile.sqlite3
45
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
36
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
46
37
  - rvm: jruby
47
38
  gemfile: gemfiles/rails-4.0/Gemfile.mysql2
48
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
39
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
49
40
  - rvm: jruby
50
- gemfile: gemfiles/rails-edge/Gemfile.postgresql
51
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
41
+ gemfile: gemfiles/rails-4.1/Gemfile.postgresql
42
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
52
43
  - rvm: jruby
53
- gemfile: gemfiles/rails-edge/Gemfile.sqlite3
54
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
44
+ gemfile: gemfiles/rails-4.1/Gemfile.sqlite3
45
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
55
46
  - rvm: jruby
56
- gemfile: gemfiles/rails-edge/Gemfile.mysql2
57
- env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER=""'
47
+ gemfile: gemfiles/rails-4.1/Gemfile.mysql2
48
+ env: 'POSTGRES_DB_USER=postgres MYSQL_DB_USER="travis"'
data/README.md CHANGED
@@ -17,19 +17,16 @@ For added rails DRYness see also the gems
17
17
 
18
18
  SchemaPlus supports all combinations of:
19
19
 
20
- * Rails 3.2 or Rails 4
20
+ * Rails 3.2, 4.0, and 4.1 (currently 4.1.0beta3)
21
21
  * PostgreSQL, MySQL (using mysql2 gem; mysql gem only supported with Rails
22
22
  3.2), or SQLite3 (using sqlite3 >= 3.7.7 which has foreign key support)
23
- * MRI Ruby 1.9.3 or 2.0.0
23
+ * MRI Ruby 1.9.3, 2.0.0, or 2.1.0
24
24
 
25
25
  And also supports:
26
26
 
27
- * jruby with Rails 3.2 and PostgreSQL
27
+ * jruby with Rails 3.2 and PostgreSQL or MySQL
28
28
 
29
29
 
30
- Note: As of version 1.0.0, SchemaPlus no longer supports Rails 2.3, 3.0 and
31
- 3.1, and also no longer supports MRI Ruby 1.8.7; the last version
32
- to support them was 0.4.1. As of version 1.2.0, SchemaPlus no longer supports MRI Ruby 1.9.2
33
30
 
34
31
  ## Installation
35
32
 
@@ -300,6 +297,12 @@ of foreign key constraints, you can re-enable it:
300
297
 
301
298
  * *nothing currently waiting to be released*
302
299
 
300
+ ### 1.4.0
301
+
302
+ * Supports jruby & mysql, thanks to [@rzenha](https://github.com/razenha)
303
+ * Works with MRI ruby & rails 4.1.0beta3
304
+ * Run tests against MRI 2.1.0
305
+
303
306
  ### 1.3.3
304
307
 
305
308
  * Bug fix, dump unique index with expression (Issue #142)
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec :path => File.expand_path('../../..', __FILE__)
4
+ gem "rails", "~> 4.1.0.beta1"
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "mysql2"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcmysql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "pg"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcpostgresql-adapter'
10
+ end
@@ -0,0 +1,10 @@
1
+ require "pathname"
2
+ eval(Pathname.new(__FILE__).dirname.join("Gemfile.base").read, binding)
3
+
4
+ platform :ruby do
5
+ gem "sqlite3"
6
+ end
7
+
8
+ platform :jruby do
9
+ gem 'activerecord-jdbcsqlite3-adapter', '>=1.3.0.beta2'
10
+ end
@@ -78,7 +78,15 @@ module SchemaPlus
78
78
  end
79
79
 
80
80
  def _build_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {}) #:nodoc:
81
- ForeignKeyDefinition.new(options[:name] || ForeignKeyDefinition.default_name(table_name, column_names), table_name, column_names, ::ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
81
+ ForeignKeyDefinition.new(options[:name] || ForeignKeyDefinition.default_name(table_name, column_names), table_name, column_names, AbstractAdapter.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
82
+ end
83
+
84
+ def self.proper_table_name(name)
85
+ if ::ActiveRecord::Migration.instance_methods(false).include? :proper_table_name
86
+ proper_name = ::ActiveRecord::Migration.new.proper_table_name(name) # Rails >= 4.1
87
+ else
88
+ proper_name = ::ActiveRecord::Migrator.proper_table_name(name) # Rails <= 4.0 ; Deprecated in 4.1
89
+ end
82
90
  end
83
91
 
84
92
  # Remove a foreign key constraint
@@ -60,7 +60,12 @@ module SchemaPlus
60
60
  # implement cascade by removing foreign keys
61
61
  def drop_table(name, options={})
62
62
  reverse_foreign_keys(name).each{ |foreign_key| remove_foreign_key(foreign_key.table_name, foreign_key.name) } if options[:cascade]
63
- super
63
+ sql = "DROP"
64
+ sql += " TEMPORARY" if options[:temporary]
65
+ sql += " TABLE"
66
+ sql += " IF EXISTS" if options[:if_exists]
67
+ sql += " #{quote_table_name(name)}"
68
+ execute sql
64
69
  end
65
70
 
66
71
  def remove_index_sql(table_name, options)
@@ -82,15 +87,16 @@ module SchemaPlus
82
87
  end
83
88
 
84
89
  def foreign_keys(table_name, name = nil)
85
- results = execute("SHOW CREATE TABLE #{quote_table_name(table_name)}", name)
90
+ results = select_all("SHOW CREATE TABLE #{quote_table_name(table_name)}", name)
86
91
 
87
92
  table_name = table_name.to_s
88
93
  namespace_prefix = table_namespace_prefix(table_name)
89
94
 
90
95
  foreign_keys = []
91
96
 
92
- results.each do |row|
93
- row[1].lines.each do |line|
97
+ results.each do |result|
98
+ create_table_sql = result["Create Table"]
99
+ create_table_sql.lines.each do |line|
94
100
  if line =~ /^ CONSTRAINT [`"](.+?)[`"] FOREIGN KEY \([`"](.+?)[`"]\) REFERENCES [`"](.+?)[`"] \((.+?)\)( ON DELETE (.+?))?( ON UPDATE (.+?))?,?$/
95
101
  name = $1
96
102
  column_names = $2
@@ -114,7 +120,7 @@ module SchemaPlus
114
120
  end
115
121
 
116
122
  def reverse_foreign_keys(table_name, name = nil)
117
- results = execute(<<-SQL, name)
123
+ results = select_all(<<-SQL, name)
118
124
  SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name
119
125
  FROM information_schema.key_column_usage
120
126
  WHERE table_schema = #{table_schema_sql(table_name)}
@@ -127,18 +133,18 @@ module SchemaPlus
127
133
  namespace_prefix = table_namespace_prefix(table_name)
128
134
 
129
135
  results.each do |row|
130
- next unless table_name_without_namespace(table_name).casecmp(row[3]) == 0
131
- if current_foreign_key != row[0]
132
- referenced_table_name = row[1]
136
+ next unless table_name_without_namespace(table_name).casecmp(row["referenced_table_name"]) == 0
137
+ if current_foreign_key != row["constraint_name"]
138
+ referenced_table_name = row["table_name"]
133
139
  referenced_table_name = namespace_prefix + referenced_table_name if table_namespace_prefix(referenced_table_name).blank?
134
- references_table_name = row[3]
140
+ references_table_name = row["referenced_table_name"]
135
141
  references_table_name = namespace_prefix + references_table_name if table_namespace_prefix(references_table_name).blank?
136
- foreign_keys << ForeignKeyDefinition.new(row[0], referenced_table_name, [], references_table_name, [])
137
- current_foreign_key = row[0]
142
+ foreign_keys << ForeignKeyDefinition.new(row["constraint_name"], referenced_table_name, [], references_table_name, [])
143
+ current_foreign_key = row["constraint_name"]
138
144
  end
139
145
 
140
- foreign_keys.last.column_names << row[2]
141
- foreign_keys.last.references_column_names << row[4]
146
+ foreign_keys.last.column_names << row["column_name"]
147
+ foreign_keys.last.references_column_names << row["referenced_column_name"]
142
148
  end
143
149
 
144
150
  foreign_keys
@@ -146,19 +152,19 @@ module SchemaPlus
146
152
 
147
153
  def views(name = nil)
148
154
  views = []
149
- execute("SELECT table_name FROM information_schema.views WHERE table_schema = SCHEMA()", name).each do |row|
150
- views << row[0]
155
+ select_all("SELECT table_name FROM information_schema.views WHERE table_schema = SCHEMA()", name).each do |row|
156
+ views << row["table_name"]
151
157
  end
152
158
  views
153
159
  end
154
160
 
155
161
  def view_definition(view_name, name = nil)
156
- result = execute("SELECT view_definition, check_option FROM information_schema.views WHERE table_schema = SCHEMA() AND table_name = #{quote(view_name)}", name)
157
- return nil unless (result.respond_to?(:num_rows) ? result.num_rows : result.to_a.size) > 0 # mysql vs mysql2
158
- row = result.respond_to?(:fetch_row) ? result.fetch_row : result.first
159
- sql = row[0]
162
+ results = select_all("SELECT view_definition, check_option FROM information_schema.views WHERE table_schema = SCHEMA() AND table_name = #{quote(view_name)}", name)
163
+ return nil unless results.any?
164
+ row = results.first
165
+ sql = row["view_definition"]
160
166
  sql.gsub!(%r{#{quote_table_name(current_database)}[.]}, '')
161
- case row[1]
167
+ case row["check_option"]
162
168
  when "CASCADED" then sql += " WITH CASCADED CHECK OPTION"
163
169
  when "LOCAL" then sql += " WITH LOCAL CHECK OPTION"
164
170
  end
@@ -142,7 +142,7 @@ module SchemaPlus::ActiveRecord::ConnectionAdapters
142
142
  end
143
143
 
144
144
  def foreign_key(column_names, references_table_name, references_column_names, options = {})
145
- @foreign_keys << ForeignKeyDefinition.new(options[:name] || ForeignKeyDefinition.default_name(self.name, column_names), self.name, column_names, ::ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
145
+ @foreign_keys << ForeignKeyDefinition.new(options[:name] || ForeignKeyDefinition.default_name(self.name, column_names), self.name, column_names, AbstractAdapter.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
146
146
  self
147
147
  end
148
148
 
@@ -1,3 +1,3 @@
1
1
  module SchemaPlus
2
- VERSION = "1.3.3"
2
+ VERSION = "1.4.0"
3
3
  end
data/runspecs CHANGED
@@ -5,8 +5,8 @@ require 'ostruct'
5
5
  require 'shellwords'
6
6
  require 'tempfile'
7
7
 
8
- RUBY_VERSIONS = %W[jruby 1.9.3 2.0.0]
9
- RAILS_VERSIONS = %W[3.2 edge 4.0]
8
+ RUBY_VERSIONS = %W[jruby 1.9.3 2.0.0 2.1.0]
9
+ RAILS_VERSIONS = %W[3.2 4.0 4.1]
10
10
  DB_ADAPTERS = %W[postgresql mysql mysql2 sqlite3]
11
11
 
12
12
  o = OpenStruct.new
@@ -68,7 +68,9 @@ combos = o.ruby_versions.product(o.rails_versions, o.db_adapters).map{|product|
68
68
  when combo.rails >= "4" && combo.db_adapter == "mysql" then false
69
69
  when combo.ruby == "jruby"
70
70
  case
71
- when combo.rails == "3.2" && combo.db_adapter == "postgresql" then true
71
+ when combo.rails > "3.2" then false
72
+ when combo.db_adapter == "postgresql" then true
73
+ when combo.db_adapter =~ /mysql/ then true
72
74
  else false
73
75
  end
74
76
  else true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema_plus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronen Barzel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-04 00:00:00.000000000 Z
12
+ date: 2014-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -135,6 +135,10 @@ files:
135
135
  - gemfiles/rails-4.0/Gemfile.mysql2
136
136
  - gemfiles/rails-4.0/Gemfile.postgresql
137
137
  - gemfiles/rails-4.0/Gemfile.sqlite3
138
+ - gemfiles/rails-4.1/Gemfile.base
139
+ - gemfiles/rails-4.1/Gemfile.mysql2
140
+ - gemfiles/rails-4.1/Gemfile.postgresql
141
+ - gemfiles/rails-4.1/Gemfile.sqlite3
138
142
  - gemfiles/rails-edge/Gemfile.base
139
143
  - gemfiles/rails-edge/Gemfile.mysql2
140
144
  - gemfiles/rails-edge/Gemfile.postgresql