small adjustment for database_config
Oleg
committed Aug 31, 2011
commit 0bce4b0ac3cb3dcdefc068d3ce8c25ab5d054ca3
Showing 15
changed files with
66 additions
and 34 deletions
app/models/cms/block.rb
+3
-2
| @@ | @@ -1,6 +1,7 @@ |
| class Cms::Block < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| set_table_name :cms_blocks | |
app/models/cms/categorization.rb
+4
-3
| @@ | @@ -1,8 +1,9 @@ |
| class Cms::Categorization < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| - | |
| + | |
| set_table_name :cms_categorizations | |
| # -- Relationships -------------------------------------------------------- | |
app/models/cms/category.rb
+4
-3
| @@ | @@ -1,8 +1,9 @@ |
| class Cms::Category < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| - | |
| + | |
| set_table_name :cms_categories | |
| # -- Relationships -------------------------------------------------------- | |
app/models/cms/file.rb
+3
-2
| @@ | @@ -1,6 +1,7 @@ |
| class Cms::File < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| set_table_name :cms_files | |
app/models/cms/layout.rb
+3
-2
| @@ | @@ -1,6 +1,7 @@ |
| class Cms::Layout < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| set_table_name :cms_layouts | |
app/models/cms/page.rb
+3
-2
| @@ | @@ -1,6 +1,7 @@ |
| class Cms::Page < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| set_table_name :cms_pages | |
app/models/cms/revision.rb
+4
-3
| @@ | @@ -1,8 +1,9 @@ |
| class Cms::Revision < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| - | |
| + | |
| set_table_name :cms_revisions | |
| serialize :data | |
app/models/cms/site.rb
+4
-3
| @@ | @@ -1,8 +1,9 @@ |
| class Cms::Site < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| - | |
| + | |
| set_table_name :cms_sites | |
| # -- Relationships -------------------------------------------------------- | |
app/models/cms/snippet.rb
+4
-3
| @@ | @@ -1,8 +1,9 @@ |
| class Cms::Snippet < ActiveRecord::Base | |
| - | unless Rails.env == 'test' |
| - | establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| end | |
| - | |
| + | |
| set_table_name :cms_snippets | |
| cms_is_categorized | |
migrate/01_create_cms.rb b/db/migrate/01_create_cms.rb
+9
-2
| @@ | @@ -1,7 +1,11 @@ |
| class CreateCms < ActiveRecord::Migration | |
| def self.up | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| + | |
| # -- Sites -------------------------------------------------------------- | |
| create_table :cms_sites do |t| | |
| t.string :label | |
| @@ | @@ -108,7 +112,10 @@ class CreateCms < ActiveRecord::Migration |
| end | |
| def self.down | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| drop_table :cms_sites | |
| drop_table :cms_layouts | |
migrate/upgrades/02_upgrade_to_1_1_0.rb b/db/migrate/upgrades/02_upgrade_to_1_1_0.rb
+6
-2
| @@ | @@ -1,6 +1,8 @@ |
| class UpgradeTo110 < ActiveRecord::Migration | |
| def self.up | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| rename_column :cms_layouts, :cms_site_id, :site_id | |
| rename_column :cms_pages, :cms_site_id, :site_id | |
| rename_column :cms_pages, :cms_layout_id, :layout_id | |
| @@ | @@ -10,7 +12,9 @@ class UpgradeTo110 < ActiveRecord::Migration |
| end | |
| def self.down | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| rename_column :cms_uploads, :site_id, :cms_site_id | |
| rename_column :cms_snippets, :site_id, :cms_site_id | |
| rename_column :cms_blocks, :page_id, :cms_page_id | |
migrate/upgrades/03_upgrade_to_1_2_0.rb b/db/migrate/upgrades/03_upgrade_to_1_2_0.rb
+6
-2
| @@ | @@ -1,6 +1,8 @@ |
| class UpgradeTo120 < ActiveRecord::Migration | |
| def self.up | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| create_table :cms_revisions, :force => true do |t| | |
| t.string :record_type | |
| t.integer :record_id | |
| @@ | @@ -11,7 +13,9 @@ class UpgradeTo120 < ActiveRecord::Migration |
| end | |
| def self.down | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| drop_table :cms_revisions | |
| end | |
| end | |
| \ No newline at end of file | |
migrate/upgrades/04_upgrade_to_1_3_0.rb b/db/migrate/upgrades/04_upgrade_to_1_3_0.rb
+6
-2
| @@ | @@ -1,6 +1,8 @@ |
| class UpgradeTo130 < ActiveRecord::Migration | |
| def self.up | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| add_column :cms_sites, :is_mirrored, :boolean, :null => false, :default => false | |
| add_column :cms_sites, :path, :string | |
| add_column :cms_sites, :locale, :string, :null => false, :default => 'en' | |
| @@ | @@ -12,7 +14,9 @@ class UpgradeTo130 < ActiveRecord::Migration |
| end | |
| def self.down | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| remove_index :cms_sites, :is_mirrored | |
| remove_column :cms_sites, :path | |
| remove_column :cms_sites, :is_mirrored | |
migrate/upgrades/05_upgrade_to_1_4_0.rb b/db/migrate/upgrades/05_upgrade_to_1_4_0.rb
+6
-2
| @@ | @@ -1,6 +1,8 @@ |
| class UpgradeTo140 < ActiveRecord::Migration | |
| def self.up | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| rename_table :cms_uploads, :cms_files | |
| add_column :cms_files, :label, :string | |
| add_column :cms_files, :description, :string, :limit => 2048 | |
| @@ | @@ -23,7 +25,9 @@ class UpgradeTo140 < ActiveRecord::Migration |
| end | |
| def self.down | |
| - | ActiveRecord::Base.establish_connection "#{ComfortableMexicanSofa.config.database_config}#{Rails.env}" |
| + | if ComfortableMexicanSofa.config.database_config && !Rails.env.test? |
| + | establish_connection "#{ComfortableMexicanSofa.config.database_config}_#{Rails.env}" |
| + | end |
| remove_index :cms_files, [:site_id, :label] | |
| remove_column :cms_files, :description | |
| remove_column :cms_files, :label | |
comfortable_mexican_sofa/configuration.rb b/lib/comfortable_mexican_sofa/configuration.rb
+1
-1
| @@ | @@ -45,7 +45,7 @@ class ComfortableMexicanSofa::Configuration |
| # Database prefix. If you want to keep your comfortable mexican sofa tables | |
| # in a location other than the default databases add a database_config. | |
| - | # Using a prefix of `cms_` will look for a cms_#{Rails.env} definition |
| + | # Setting this to `cms` will look for a cms_#{Rails.env} database definition |
| # in your database.yml file | |
| attr_accessor :database_config | |