-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MariaDB doesn't not support JSON type. Undefined method 'accessor' #425
Comments
You have a stacktrace I can see? |
The console truncates it, but you can always get a backtrace. begin
mycode
rescue => exception
puts exception.backtrace
end That should print it all out. 👍 |
Ah, here we go:
|
Perfect, thanks! It looks like your Maybe one of the migrations is wrong. |
I just used the standard migration installer: Here's my schema: # This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_09_08_125550) do
create_table "customers", charset: "utf8mb4", force: :cascade do |t|
t.string "email"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "pay_charges", charset: "utf8mb4", force: :cascade do |t|
t.bigint "customer_id", null: false
t.bigint "subscription_id"
t.string "processor_id", null: false
t.integer "amount", null: false
t.string "currency"
t.integer "application_fee_amount"
t.integer "amount_refunded"
t.text "metadata", size: :long, collation: "utf8mb4_bin"
t.text "data", size: :long, collation: "utf8mb4_bin"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["customer_id", "processor_id"], name: "index_pay_charges_on_customer_id_and_processor_id", unique: true
t.index ["subscription_id"], name: "index_pay_charges_on_subscription_id"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`metadata`)", name: "metadata"
t.check_constraint "json_valid(`metadata`)", name: "metadata"
end
create_table "pay_customers", charset: "utf8mb4", force: :cascade do |t|
t.string "owner_type"
t.bigint "owner_id"
t.string "processor", null: false
t.string "processor_id"
t.boolean "default"
t.text "data", size: :long, collation: "utf8mb4_bin"
t.datetime "deleted_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["owner_type", "owner_id", "deleted_at", "default"], name: "pay_customer_owner_index"
t.index ["processor", "processor_id"], name: "index_pay_customers_on_processor_and_processor_id", unique: true
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
end
create_table "pay_merchants", charset: "utf8mb4", force: :cascade do |t|
t.string "owner_type"
t.bigint "owner_id"
t.string "processor", null: false
t.string "processor_id"
t.boolean "default"
t.text "data", size: :long, collation: "utf8mb4_bin"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["owner_type", "owner_id", "processor"], name: "index_pay_merchants_on_owner_type_and_owner_id_and_processor"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
end
create_table "pay_payment_methods", charset: "utf8mb4", force: :cascade do |t|
t.bigint "customer_id", null: false
t.string "processor_id", null: false
t.boolean "default"
t.string "type"
t.text "data", size: :long, collation: "utf8mb4_bin"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["customer_id", "processor_id"], name: "index_pay_payment_methods_on_customer_id_and_processor_id", unique: true
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
end
create_table "pay_subscriptions", charset: "utf8mb4", force: :cascade do |t|
t.bigint "customer_id", null: false
t.string "name", null: false
t.string "processor_id", null: false
t.string "processor_plan", null: false
t.integer "quantity", default: 1, null: false
t.string "status", null: false
t.datetime "trial_ends_at"
t.datetime "ends_at"
t.decimal "application_fee_percent", precision: 8, scale: 2
t.text "metadata", size: :long, collation: "utf8mb4_bin"
t.text "data", size: :long, collation: "utf8mb4_bin"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["customer_id", "processor_id"], name: "index_pay_subscriptions_on_customer_id_and_processor_id", unique: true
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`data`)", name: "data"
t.check_constraint "json_valid(`metadata`)", name: "metadata"
t.check_constraint "json_valid(`metadata`)", name: "metadata"
end
create_table "pay_webhooks", charset: "utf8mb4", force: :cascade do |t|
t.string "processor"
t.string "event_type"
t.text "event", size: :long, collation: "utf8mb4_bin"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.check_constraint "json_valid(`event`)", name: "event"
end
add_foreign_key "pay_charges", "pay_customers", column: "customer_id"
add_foreign_key "pay_charges", "pay_subscriptions", column: "subscription_id"
add_foreign_key "pay_payment_methods", "pay_customers", column: "customer_id"
add_foreign_key "pay_subscriptions", "pay_customers", column: "customer_id"
end |
Ah, yeah your t.text "data", size: :long, collation: "utf8mb4_bin" You're using MySQL? It supports a json column type doesn't it? I run my tests against MySQL and it uses a json column fine. |
Hm. Even when setting the column type in the migration, it still does the same thing 🤔 |
I guess maybe MYSQL uses this to validate that it's a JSON column. t.check_constraint "json_valid(`data`)", name: "data" Tests run on MySQL 8: https://github.com/pay-rails/pay/blob/master/.github/workflows/ci.yml#L97 Which version are you on? |
I'm using MariaDB 10.6.4, which should support it 🤔 |
Do you use the mysql2 gem or something else for mariadb? |
Yep, mysql2. Everything else works fine so I'd rather not move all my apps back to normal MySQL. |
Having a quick Google, I've found this:
I still think Pay should work with any database type, especially seeing as most people are using MariaDB these days. I just tried setting them as text in the migration and it still errors out which makes me think it's a bug with Rails? |
That's unfortunate that MariaDB has implemented them as text columns. Rails will see them as Seems like Rails could be improved to treat them as json, but I'm not sure how you'd reasonably detect that. |
Ah, good find. store :data, accessors: [:stripe_connect_account_id, :onboarding_complete] |
Ah yeah, I didn't think of trying that for some reason. I just tried I guess the solution might be to add Will add a test and confirm that works. Then it'll probably be good to add Maria to the CI. |
I've just tried to set Pay v3 up on my Rails application (and I've also created a basic Rails app to test this error) but I'm running into issues.
When using the Fake Processor, it works fine:
I'm using Rails 6.1.4.1 with MariaDB 10.5.12. I've also tried MariaDB 10.6.4.
Any ideas?
The text was updated successfully, but these errors were encountered: