From 638b5b1a635b02f1b8a6a9e5175f9b303a5f5c5f Mon Sep 17 00:00:00 2001 From: fab Date: Tue, 5 Jun 2012 14:25:33 +0200 Subject: [PATCH 1/3] SQL fragment (in enabled_in_order) updated: prefixed with 'locales' 'key' alone is a reserved keyword in MySQL. --- app/models/locale.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/locale.rb b/app/models/locale.rb index 5fee070..dbb9984 100644 --- a/app/models/locale.rb +++ b/app/models/locale.rb @@ -6,7 +6,7 @@ class Locale < ActiveRecord::Base validates_uniqueness_of :key, :scope => :project_id def self.enabled_in_order - enabled.order 'key ASC' + enabled.order 'locales.key ASC' end def self.first_enabled From 90d7a243745cfe9268ecc2b9fb28bd977c463175 Mon Sep 17 00:00:00 2001 From: fab Date: Tue, 5 Jun 2012 14:28:08 +0200 Subject: [PATCH 2/3] SQL requests updated to support MySQL This is a (working) temporary solution based on SQL requests provided here: https://github.com/copycopter/copycopter-server/issues/64#issuecomment-5836709. Works for MySLQ and Postres; should be updated with ActiveRecord methods calls to be database agnostic. --- app/models/localization.rb | 49 ++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/app/models/localization.rb b/app/models/localization.rb index e6d7380..061be97 100644 --- a/app/models/localization.rb +++ b/app/models/localization.rb @@ -34,10 +34,18 @@ def latest_version end def self.latest_version - <<-eosql + # https://github.com/copycopter/copycopter-server/issues/64#issuecomment-5836709 + if ActiveRecord::Base.connection_config[:adapter].include? "mysql" + <<-eosql + SELECT DISTINCT localization_id, id, content + FROM versions ORDER BY localization_id DESC, id DESC + eosql + else + <<-eosql SELECT DISTINCT ON (localization_id) localization_id, id, content FROM versions ORDER BY localization_id DESC, id DESC - eosql + eosql + end end def next_version_number @@ -49,17 +57,32 @@ def self.ordered end def self.publish - ActiveRecord::Base.connection.execute <<-eosql - UPDATE localizations - SET published_version_id = latest_version.id, - published_content = latest_version.content, - updated_at = '#{connection.quoted_date(Time.now)}' - FROM ( - #{latest_version} - ) AS latest_version - WHERE latest_version.localization_id = localizations.id - AND localizations.id IN (#{scoped.map(&:id).join(',')}); - eosql + # https://github.com/copycopter/copycopter-server/issues/64#issuecomment-5836709 + if ActiveRecord::Base.connection_config[:adapter].include? "mysql" + ActiveRecord::Base.connection.execute <<-eosql + UPDATE localizations + INNER JOIN ( + #{latest_version} + ) latest_version + ON localizations.id = latest_version.localization_id + SET published_version_id = latest_version.id, + published_content = latest_version.content, + updated_at = '#{connection.quoted_date(Time.now)}' + WHERE localizations.id IN (#{scoped.map(&:id).join(',')}); + eosql + else + ActiveRecord::Base.connection.execute <<-eosql + UPDATE localizations + SET published_version_id = latest_version.id, + published_content = latest_version.content, + updated_at = '#{connection.quoted_date(Time.now)}' + FROM ( + #{latest_version} + ) AS latest_version + WHERE latest_version.localization_id = localizations.id + AND localizations.id IN (#{scoped.map(&:id).join(',')}); + eosql + end end def publish From c8e59229002c8e243faf9c0568ecd6db4f808156 Mon Sep 17 00:00:00 2001 From: fab Date: Tue, 5 Jun 2012 14:30:55 +0200 Subject: [PATCH 3/3] data and hierarchichal_data updated to work with MySQL. The migration alters those fields to LONGTEXT. With TEXT, data were truncated. The :limit => 16777217 forces AR to use LONGTEXT. --- db/migrate/20120605114749_change_text_caches_types.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 db/migrate/20120605114749_change_text_caches_types.rb diff --git a/db/migrate/20120605114749_change_text_caches_types.rb b/db/migrate/20120605114749_change_text_caches_types.rb new file mode 100644 index 0000000..34b1987 --- /dev/null +++ b/db/migrate/20120605114749_change_text_caches_types.rb @@ -0,0 +1,9 @@ +class ChangeTextCachesTypes < ActiveRecord::Migration + def up + change_column(:text_caches, :data, :text, :limit => 16777217) + change_column(:text_caches, :hierarchichal_data, :text, :limit => 16777217) + end + + def down + end +end