From d11067b4fa3bf4c4edfce1be28bae90ae60c3de9 Mon Sep 17 00:00:00 2001 From: Hampton Lintorn-Catlin Date: Fri, 27 Feb 2026 14:11:45 -0600 Subject: [PATCH] Fix MySQL JSON default and load engine migrations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove 'default: {}' from JSON metadata columns in both engine and app migrations (MySQL doesn't support defaults on JSON/BLOB/TEXT columns) - Add initializer to append engine migration paths so Rails picks them up - Remove duplicate table creation from app migration — engine owns the schema, app migration only handles data migration and FK rewiring Amp-Thread-ID: https://ampcode.com/threads/T-019c9ba5-621e-7769-81b4-99b46ff27501 Co-authored-by: Amp --- ...260226200001_create_coplan_users_and_migrate.rb | 14 +------------- .../migrate/20260226200000_create_coplan_users.rb | 2 +- engine/lib/coplan/engine.rb | 7 +++++++ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/db/migrate/20260226200001_create_coplan_users_and_migrate.rb b/db/migrate/20260226200001_create_coplan_users_and_migrate.rb index 3f0f4eb..d17cb37 100644 --- a/db/migrate/20260226200001_create_coplan_users_and_migrate.rb +++ b/db/migrate/20260226200001_create_coplan_users_and_migrate.rb @@ -1,16 +1,6 @@ class CreateCoplanUsersAndMigrate < ActiveRecord::Migration[8.1] def up - create_table :coplan_users, id: { type: :string, limit: 36 } do |t| - t.string :external_id, null: false - t.string :name, null: false - t.boolean :admin, default: false, null: false - t.json :metadata, default: {} - t.timestamps - end - - add_index :coplan_users, :external_id, unique: true - - # Migrate existing users — reuse the same id so FK columns stay valid + # Table created by engine migration; migrate existing users data execute <<~SQL INSERT INTO coplan_users (id, external_id, name, admin, metadata, created_at, updated_at) SELECT id, id, name, (role = 'admin'), '{}', created_at, updated_at @@ -47,7 +37,5 @@ def down add_foreign_key :coplan_plan_collaborators, :users, column: :user_id add_foreign_key :coplan_plan_collaborators, :users, column: :added_by_user_id add_foreign_key :coplan_plans, :users, column: :created_by_user_id - - drop_table :coplan_users end end diff --git a/engine/db/migrate/20260226200000_create_coplan_users.rb b/engine/db/migrate/20260226200000_create_coplan_users.rb index 36074b8..3194b20 100644 --- a/engine/db/migrate/20260226200000_create_coplan_users.rb +++ b/engine/db/migrate/20260226200000_create_coplan_users.rb @@ -4,7 +4,7 @@ def change t.string :external_id, null: false t.string :name, null: false t.boolean :admin, default: false, null: false - t.json :metadata, default: {} + t.json :metadata t.timestamps end diff --git a/engine/lib/coplan/engine.rb b/engine/lib/coplan/engine.rb index b62f16e..8d89369 100644 --- a/engine/lib/coplan/engine.rb +++ b/engine/lib/coplan/engine.rb @@ -18,6 +18,13 @@ class Engine < ::Rails::Engine app.config.assets.paths << Engine.root.join("app/javascript") end + initializer "coplan.append_migrations", before: :load_config_initializers do |app| + config.paths["db/migrate"].expanded.each do |path| + app.config.paths["db/migrate"] << path + ActiveRecord::Migrator.migrations_paths << path + end + end + initializer "coplan.factories", after: "factory_bot.set_factory_paths" do if defined?(FactoryBot) FactoryBot.definition_file_paths << Engine.root.join("spec", "factories")