MySQL json 错误 rails_workflow gem

MySQL json error rails_workflow gem

我正在尝试将其导入 mysql 数据库并收到有关 json 的错误。有没有办法针对 rails 4 和 mysql 更正此问题?此导入与 mysql 兼容还是适用于其他数据库类型?

真的很想试试这个工作流程 gem。所有依赖项似乎都已正确安装。

错误是

undefined method `json' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x611e1e8>D:in `migrate'
NoMethodError: undefined method `json' for #<ActiveRecord::ConnectionAdapters::TableDefinition:0x611e1e8>
D:in `migrate'


class CreateWorkflowProcesses < ActiveRecord::Migration
  def change
    create_tables
    create_columns
    check_json_columns
    create_indexes
  end

  def create_tables
    [
        [:workflow_processes, :rails_workflow_processes],
        [:workflow_operations, :rails_workflow_operations],
        [:workflow_process_templates, :rails_workflow_process_templates],
        [:workflow_operation_templates, :rails_workflow_operation_templates],
        [:workflow_contexts, :rails_workflow_contexts],
        [:workflow_errors, :rails_workflow_errors]
    ].map do |names|
      if table_exists? names[0]
        rename_table names[0], names[1]
      end

      create_table names[1] unless table_exists? names[1]
    end

  end

  def create_indexes
    [
        [:rails_workflow_contexts, [:parent_id, :parent_type]],
        [:rails_workflow_errors, [:parent_id, :parent_type]],
        [:rails_workflow_operation_templates, :process_template_id],
        [:rails_workflow_operations, :process_id],
        [:rails_workflow_operations, :template_id]
    ].each do |idx|
      unless index_exists? idx[0], idx[1]
        add_index idx[0], idx[1]
      end
    end
  end

  def create_columns
    {
      :rails_workflow_contexts => [
        [:integer,  :parent_id],
        [:string,   :parent_type],
        [:json,     :body],
        [:datetime, :created_at],
        [:datetime, :updated_at],
      ],

      :rails_workflow_errors => [
        [:string,   :message],
        [:text,    :stack_trace],
        [:integer,  :parent_id],
        [:string,   :parent_type],
        [:datetime, :created_at],
        [:datetime, :updated_at],
        [:boolean,  :resolved]
      ],

      :rails_workflow_operation_templates => [
          [:string,   :title],
          [:string,   :version],
          [:text,     :source],
          [:json,     :dependencies],
          [:string,   :operation_class],
          [:integer,  :process_template_id],
          [:datetime, :created_at],
          [:datetime, :updated_at],
          [:boolean,  :async],
          [:integer,  :child_process_id],
          [:integer,  :assignment_id],
          [:string,   :assignment_type],
          [:string,   :kind],
          [:string,   :role],
          [:string,   :group],
          [:text,     :instruction],
          [:boolean,  :is_background],
          [:string,   :type],
          [:string,   :partial_name],
      ],

      :rails_workflow_operations => [
          [:integer,  :status],
          [:boolean,  :async],
          [:string,   :version],
          [:string,   :tag],
          [:string,   :title],
          [:datetime, :created_at],
          [:datetime, :updated_at],
          [:integer,  :process_id],
          [:integer,  :template_id],
          [:json,     :dependencies],
          [:integer,  :child_process_id],
          [:integer,  :assignment_id],
          [:string,   :assignment_type],
          [:datetime, :assigned_at],
          [:string,   :type],
          [:boolean,  :is_active],
          [:datetime, :completed_at],
          [:boolean,  :is_background]
      ],

      :rails_workflow_process_templates => [
          [:string,   :title],
          [:text,     :source],
          [:string,   :version],
          [:string,   :manager_class],
          [:string,   :process_class],
          [:datetime, :created_at],
          [:datetime, :updated_at],
          [:string,   :type],
          [:string,   :partial_name]
      ],

      :rails_workflow_processes => [
          [:integer,  :status],
          [:string,   :version],
          [:string,   :tag],
          [:boolean,  :async],
          [:string,   :title],
          [:datetime, :created_at],
          [:datetime, :updated_at],
          [:integer,  :template_id],
          [:string,   :type]
      ]
    }.each do |table, columns|
      columns.map do |column|
        unless column_exists? table, column[1]
          add_column table, column[1], column[0]
        end
      end

    end

  end

  def check_json_columns
    [
        [RailsWorkflow::Operation, :dependencies],
        [RailsWorkflow::OperationTemplate, :dependencies],
        [RailsWorkflow::Context, :body]
    ].map do |check|
      if check[0].columns_hash[check[1].to_s].sql_type != "json"
        change_column check[0].table_name, check[1], "JSON USING #{check[1]}::JSON"
      end
    end
  end
end

我是 gem 的开发者。不确定 MySQL 是否支持 json 数据类型,我通常使用 PostgreSQL。由于很多人需要 MySQL 支持,我想我会增强引擎以使用 Rails JSON 序列化而不是 DB 本机类型。