desert 0.5.3 → 0.5.4

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/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ 0.5.4
2
+ - Fixed migration problems when using postgres
3
+
1
4
  0.5.3
2
5
  - optimize load_paths, use uniq!
3
6
  - correct bad SQL for recording migrations in plugin_schema_migrations
@@ -47,4 +50,3 @@
47
50
  0.1.0
48
51
  - Fixed [#13346] ActionController::Base.helper raises error when helper is only in plugin
49
52
  - Desert does not require files that have been required before Desert was loaded
50
-
@@ -1,2 +1,2 @@
1
1
  ---
2
- :version: 0.5.3
2
+ :version: 0.5.4
@@ -2,10 +2,8 @@ ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
2
2
  def initialize_schema_information_with_plugins
3
3
  initialize_schema_information_without_plugins
4
4
 
5
- begin
5
+ unless Desert::PluginMigrations::Migrator.legacy_schema_table_exists?
6
6
  execute "CREATE TABLE #{Desert::PluginMigrations::Migrator.schema_info_table_name} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:integer)})"
7
- rescue ActiveRecord::StatementInvalid
8
- # Schema has been initialized
9
7
  end
10
8
  end
11
9
  alias_method_chain :initialize_schema_information, :plugins
@@ -16,7 +14,7 @@ ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
16
14
  dump = dump_schema_information_without_plugins
17
15
  schema_information << dump if dump
18
16
 
19
- begin
17
+ if Desert::PluginMigrations::Migrator.legacy_schema_table_exists?
20
18
  plugins = ActiveRecord::Base.connection.select_all("SELECT * FROM #{Desert::PluginMigrations::Migrator.schema_info_table_name}")
21
19
  plugins.each do |plugin|
22
20
  if (version = plugin['version'].to_i) > 0
@@ -24,11 +22,9 @@ ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
24
22
  schema_information << "INSERT INTO #{Desert::PluginMigrations::Migrator.schema_info_table_name} (plugin_name, version) VALUES (#{plugin_name}, #{version})"
25
23
  end
26
24
  end
27
- rescue ActiveRecord::StatementInvalid
28
- # No Schema Info
29
25
  end
30
26
 
31
27
  schema_information.join(";\n")
32
28
  end
33
29
  alias_method_chain :dump_schema_information, :plugins
34
- end
30
+ end
@@ -3,7 +3,11 @@ module Desert #:nodoc:
3
3
  class Migrator < ActiveRecord::Migrator
4
4
  class << self
5
5
  def current_version #:nodoc:
6
- result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'")
6
+ if legacy_schema_table_exists?
7
+ result = ActiveRecord::Base.connection.select_one("SELECT version FROM #{schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'")
8
+ else
9
+ result = nil
10
+ end
7
11
  if result
8
12
  result['version'].to_i
9
13
  else
@@ -16,11 +20,13 @@ module Desert #:nodoc:
16
20
  def set_schema_version(version)
17
21
  version = down? ? version.to_i - 1 : version.to_i
18
22
 
19
- if ActiveRecord::Base.connection.select_one("SELECT version FROM #{self.class.schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'").nil?
20
- # We need to create the entry since it doesn't exist
21
- ActiveRecord::Base.connection.execute("INSERT INTO #{self.class.schema_info_table_name} (version, plugin_name) VALUES (#{version},'#{current_plugin.name}')")
22
- else
23
- ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{version} WHERE plugin_name = '#{current_plugin.name}'")
23
+ if self.class.legacy_schema_table_exists?
24
+ if ActiveRecord::Base.connection.select_one("SELECT version FROM #{self.class.schema_info_table_name} WHERE plugin_name = '#{current_plugin.name}'").nil?
25
+ # We need to create the entry since it doesn't exist
26
+ ActiveRecord::Base.connection.execute("INSERT INTO #{self.class.schema_info_table_name} (version, plugin_name) VALUES (#{version},'#{current_plugin.name}')")
27
+ else
28
+ ActiveRecord::Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{version} WHERE plugin_name = '#{current_plugin.name}'")
29
+ end
24
30
  end
25
31
  end
26
32
 
@@ -7,29 +7,29 @@ ActiveRecord::ConnectionAdapters::SchemaStatements.module_eval do
7
7
  unless ActiveRecord::Base.connection.tables.include?(smt)
8
8
  execute "CREATE TABLE #{smt} (plugin_name #{type_to_sql(:string)}, version #{type_to_sql(:string)})"
9
9
  end
10
- plugins_and_versions = select_all("SELECT plugin_name, version from #{Desert::PluginMigrations::Migrator.schema_info_table_name}")
11
- plugins_and_versions.each do |plugin_data|
12
- plugin_name, version = plugin_data["plugin_name"], plugin_data["version"]
13
- plugin = Desert::Manager.find_plugin(plugin_name)
14
- migration_versions = Dir["#{plugin.migration_path}/*.rb"].map do |path|
15
- File.basename(path, ".rb")
16
- end.select do |migration|
17
- # Make sure versions don't start with zero, or Integer will interpret them as octal
18
- version_from_table_stripped = version.sub(/^0*/, '')
19
- migration_version_stripped = migration.split("_").first.sub(/^0*/, '')
20
- Integer(migration_version_stripped) <= Integer(version_from_table_stripped)
21
- end
22
- migration_versions.each do |migration_version|
23
- insert_sql = ActiveRecord::Base.send(:sanitize_sql, [
24
- "INSERT INTO #{Desert::PluginMigrations::Migrator.schema_migrations_table_name}(plugin_name, version) VALUES(?, ?)",
25
- plugin_name,
26
- Integer(migration_version.split("_").first.sub(/^0*/, ''))
27
- ])
28
- execute insert_sql
10
+ if Desert::PluginMigrations::Migrator.legacy_schema_table_exists?
11
+ plugins_and_versions = select_all("SELECT plugin_name, version from #{Desert::PluginMigrations::Migrator.schema_info_table_name}")
12
+ plugins_and_versions.each do |plugin_data|
13
+ plugin_name, version = plugin_data["plugin_name"], plugin_data["version"]
14
+ plugin = Desert::Manager.find_plugin(plugin_name)
15
+ migration_versions = Dir["#{plugin.migration_path}/*.rb"].map do |path|
16
+ File.basename(path, ".rb")
17
+ end.select do |migration|
18
+ # Make sure versions don't start with zero, or Integer will interpret them as octal
19
+ version_from_table_stripped = version.to_s.sub(/^0*/, '')
20
+ migration_version_stripped = migration.split("_").first.sub(/^0*/, '')
21
+ Integer(migration_version_stripped) <= Integer(version_from_table_stripped)
22
+ end
23
+ migration_versions.each do |migration_version|
24
+ insert_sql = ActiveRecord::Base.send(:sanitize_sql, [
25
+ "INSERT INTO #{Desert::PluginMigrations::Migrator.schema_migrations_table_name}(plugin_name, version) VALUES(?, ?)",
26
+ plugin_name,
27
+ Integer(migration_version.split("_").first.sub(/^0*/, ''))
28
+ ])
29
+ execute insert_sql
30
+ end
29
31
  end
30
32
  end
31
- rescue ActiveRecord::StatementInvalid
32
- # Schema has been initialized
33
33
  end
34
34
  end
35
35
  alias_method_chain :initialize_schema_migrations_table, :plugins
@@ -23,7 +23,11 @@ module Desert #:nodoc:
23
23
  def schema_migrations_table_name
24
24
  ActiveRecord::Base.table_name_prefix + 'plugin_schema_migrations' + ActiveRecord::Base.table_name_suffix
25
25
  end
26
+
27
+ def legacy_schema_table_exists?
28
+ ActiveRecord::Base.connection.tables.include? schema_info_table_name
29
+ end
26
30
  end
27
31
  end
28
32
  end
29
- end
33
+ end
@@ -15,22 +15,13 @@ class ActiveRecord::Migration
15
15
  raise ArgumentError, "No plugin found named #{plugin_name}"
16
16
  end
17
17
 
18
- def table_exists?(table_name)
19
- vals = select_all("DESC #{table_name}")
20
- return true
21
- rescue ActiveRecord::StatementInvalid
22
- return false
23
- end
24
-
25
18
  def column_exists?(table_name, column_name)
26
- val = select_one("select #{column_name} from #{table_name}")
27
- return true
28
- rescue ActiveRecord::StatementInvalid
29
- return false
19
+ !ActiveRecord::Base.connection.columns(table_name).detect {|c| c.name == column_name }.nil?
30
20
  end
21
+
31
22
  def table_exists?(table_name)
32
23
  ActiveRecord::Base.connection.tables.include? table_name
33
24
  end
34
25
  end
35
26
  extend DesertMigration
36
- end
27
+ end
metadata CHANGED
@@ -1,15 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: desert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 4
9
+ version: 0.5.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Pivotal Labs
8
13
  - Brian Takita
9
14
  - Parker Thompson
10
- - Adam Milligan
11
- - Joe Moore
12
- - Josh Susser
15
+ - Adam Milligan, Joe Moore
13
16
  autorequire:
14
17
  bindir: bin
15
18
  cert_chain: []
@@ -88,18 +91,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
91
  requirements:
89
92
  - - ">="
90
93
  - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
91
96
  version: "0"
92
- version:
93
97
  required_rubygems_version: !ruby/object:Gem::Requirement
94
98
  requirements:
95
99
  - - ">="
96
100
  - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
97
103
  version: "0"
98
- version:
99
104
  requirements: []
100
105
 
101
106
  rubyforge_project: desert
102
- rubygems_version: 1.3.5
107
+ rubygems_version: 1.3.6
103
108
  signing_key:
104
109
  specification_version: 3
105
110
  summary: Desert is a component framework for Rails that allows your plugins to be packaged as mini Rails apps.