Skip to content

[Known Issue/BUG] MySQL/MariaDB does not support .json type in migration #524

@Yuliia7-1

Description

@Yuliia7-1

Basic checks

  • I searched existing issues - this hasn't been reported
  • I can reproduce this consistently
  • This is a RubyLLM bug, not my application code

What's broken?

I encountered a migration issue when using RubyLLM with a MariaDB/MySQL database.
The current migration uses several t.json columns, but MySQL/MariaDB versions do not fully support this column type (especially MariaDB, where JSON is only an alias for LONGTEXT and may not behave as expected).

Migration:

class CreateModels < ActiveRecord::Migration[7.2]
  def change
    create_table :models do |t|
      t.string :model_id, null: false
      t.string :name, null: false
      t.string :provider, null: false
      t.string :family
      t.datetime :model_created_at
      t.integer :context_window
      t.integer :max_output_tokens
      t.date :knowledge_cutoff

      t.json :modalities, default: {}, null: false
      t.json :capabilities, default: [], null: false
      t.json :pricing, default: {}, null: false
      t.json :metadata, default: {}, null: false

      t.timestamps

      t.index [:provider, :model_id], unique: true
      t.index :provider
      t.index :family

    end

    # Load models from JSON
    say_with_time "Loading models from models.json" do
      RubyLLM.models.load_from_json!
      Model.save_to_database
    end
  end
end

When running the migration on MariaDB/MySQL, it fails because these databases do not support t.json

How to reproduce

Run the upgrade generator

rails generate ruby_llm:upgrade_to_v1_9

Run migrations

rails db:migrate

During the migration, the process also fails when executing:

RubyLLM.models.load_from_json!
Model.save_to_database

This step cannot complete due to the JSON column incompatibility in MySQL/MariaDB.

Expected behavior

Either:

  • Replace t.json with t.jsonb or t.text for MySQL/MariaDB compatibility, or
  • Provide separate migrations depending on the adapter, similar to other gems that support multiple databases.

What actually happened

Migration fails with an error related to an unsupported JSON column type.

Environment

  • DB: MariaDB / MySQL
  • Rails version: 7.2
  • RubyLLM version: 1.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions