Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

MySQL support #68

Open
wants to merge 3 commits into from

4 participants

@clarif

MySQL support added. Still need to work on it, especially on the localization model which includes SQL requests for both MySQL and Postgres. But that works; might be useful for those of us willing to use this nice tool with their favorite DB server.

clarif added some commits
@clarif clarif SQL fragment (in enabled_in_order) updated: prefixed with 'locales'
'key' alone is a reserved keyword in MySQL.
638b5b1
@clarif clarif SQL requests updated to support MySQL
This is a (working) temporary solution based on SQL requests provided here: copycopter#64 (comment). Works for MySLQ and Postres; should be updated with ActiveRecord methods calls to be database agnostic.
90d7a24
@clarif clarif 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.
c8e5922
@patricksrobertson

I'd love to see code that doesn't have if statements based on the DB type. We should probably endeavor to either maintain PG solely or make the database calls generic enough to be supported by all/most DB's.

Holding off merging for now.

@opsidao

So, any plans on merging/developing this? We'd love if we were able to run the server against MySQL...

@chuckbutler

All I know is i copied this into my own installation and it worked like a charm. Thanks for the patch Clarif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 5, 2012
  1. @clarif

    SQL fragment (in enabled_in_order) updated: prefixed with 'locales'

    clarif authored
    'key' alone is a reserved keyword in MySQL.
  2. @clarif

    SQL requests updated to support MySQL

    clarif authored
    This is a (working) temporary solution based on SQL requests provided here: copycopter#64 (comment). Works for MySLQ and Postres; should be updated with ActiveRecord methods calls to be database agnostic.
  3. @clarif

    data and hierarchichal_data updated to work with MySQL.

    clarif authored
    The migration alters those fields to LONGTEXT. With TEXT, data were truncated. The :limit => 16777217 forces AR to use LONGTEXT.
This page is out of date. Refresh to see the latest.
View
2  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
View
49 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
View
9 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
Something went wrong with that request. Please try again.