Skip to main content

Catalyst Upgrade Codemod

The CmAdmin → Catalyst rename ships as a major release with no aliases for old names in host code. Host apps upgrade by running a codemod, rails catalyst:upgrade, which lives in lib/catalyst/upgrade/.

Running it​

bin/rails catalyst:upgrade # dry run: lists the moves, edits and things to change by hand
DIFF=1 bin/rails catalyst:upgrade # also prints a diff of every edited file
APPLY=1 bin/rails catalyst:upgrade # writes the changes

APPLY=1 refuses to run with uncommitted changes, so the result can be reviewed and undone with git, and refuses to run until the Catalyst engine is installed. FORCE=1 skips both checks.

Upgrading a host app​

Host teams follow the v10.0.0 upgrade guide; in short:

  1. Switch the Gemfile to gem "better-platforms-catalyst" in a source block for the private gem server, and bundle install.
  2. Run bin/rails catalyst:upgrade, then APPLY=1 bin/rails catalyst:upgrade, and change by hand what it lists.
  3. Run bin/rails catalyst:install_migrations and bin/rails db:migrate. RenameCmTablesToCatalyst renames the engine's tables (cm_roles → ct_roles) and the columns named after them (cm_role_id → ct_role_id, including users.cm_role_id), rewrites stored class names (CmRole → Catalyst::Role), and on PostgreSQL leaves views under the old table names so servers still on the previous release keep working during a rolling deploy.
  4. Deploy, then run bin/rails catalyst:backfill_class_names for rows those servers wrote in the meantime.
  5. On Catalyst 11, bin/rails catalyst:install_migrations offers DropCmCompatibilityViews, which drops those views. Raw SQL or reporting tools that still read the cm_ names must move to the ct_ names first.

What it changes​

StepExample
Moves cm_admin/ folders under app/ (controllers, policies, helpers, components, views, stylesheets, javascripts, images) and component specs and previews to catalyst/app/policies/cm_admin/user_policy.rb → app/policies/catalyst/user_policy.rb
Moves admin concerns to Catalyst::Admin, without re-indenting themmodule CmAdmin / module BlogPost → module Catalyst / module Admin::BlogPost
Moves host overrides of engine models and gives them the engine's table nameapp/models/api_token.rb → app/models/catalyst/api_token.rb, with self.table_name = "api_tokens"
Moves the initializerconfig/initializers/cm_admin.rb → config/initializers/catalyst.rb
Renames engine models and other Cm/Ct constantsCmRole → Catalyst::Role, "CtFileExport" → "Catalyst::FileExport"
Renames ApiToken, OtpRequest, RubyLlmUsage and Translation only where Ruby parses them as a top-level constant::Translation.count changes; "Translation saved" and I18n::Backend::ActiveRecord::Translation don't
Adds class_name: to associations named after an engine model, and renames plain names in class_name stringsbelongs_to :cm_role → belongs_to :ct_role, class_name: "Catalyst::Role"
Names the class of factories named after an engine modelfactory :cm_role do → factory :ct_role, class: "Catalyst::Role" do
Renames CmAdminCmAdmin.configure → Catalyst.configure
Renames the DSL in files with a cm_admin blockcm_admin do → catalyst do, cm_section → section
Renames cm_admin/ paths, layouts and the top-level locale key"cm_admin/custom" → "catalyst/custom", layout "cm_admin" → layout "catalyst"
Renames engine table names in SQL strings and nested where/joins hasheswhere(cm_roles: {...}) → where(ct_roles: {...}), "cm_roles.name" → "ct_roles.name"
Renames the spec helpers, the hooks hosts define for them, shared examples and metadata, in spec/ and test/ onlycm_admin_sign_in → catalyst_sign_in, "cm_admin pages render" → "catalyst pages render"
Renames calls to the engine's route proxy, and lookups of the renamed locale keycm_admin.cm_index_user_path → catalyst.ct_index_user_path, t("cm_admin.back") → t("catalyst.back")
Renames the action notification"action.cm_admin" → "action.catalyst"
Renames the engine's stylesheet, CSS/data names, JS config and DOM event in templates and assets"cm_admin/cm_admin" → "catalyst/application", .cm-admin → .catalyst, .cm-* → .ct-*, window.cmAdminConfig → window.catalystConfig
Renames the Devise module and strategydevise :cm_admin_authenticatable → devise :catalyst_authenticatable
Removes host copies of the gem's Devise strategy and model, so the gem's implementation runslib/devise/strategies/cm_admin_authenticatable.rb and lib/devise/models/cm_admin_authenticatable.rb are deleted (also catalyst_authenticatable copies)
Removes host registrations of the gem's Devise strategy and model, which the gem registers itselfDevise.add_module(:cm_admin_authenticatable, ...), Warden::Strategies.add(:cm_admin_authenticatable, ...), Devise::Models.autoload and require lines for those files
Renames methods renamed in this releasecm_admin_models → catalyst_models, cm_admin_mail → send_email, cm_recognize_path → catalyst_recognize_path
Inside module Catalyst, qualifies bare references to names the engine now defines thereCurrent.user → ::Current.user

URLs under the engine mount path keep /cm_admin, while engine-model segments and lower-case cm_/cm- names move to ct_/ct-.

It lists for a person to change: cm_admin: rake tasks in CI or scripts, the Gemfile entry, remaining CmAdmin references (for example in JavaScript), references to the deleted Devise strategy or model copies that it could not rewrite, files that define one of the plain names inside another module (Auth::OtpRequest), associations to an engine model whose options continue on the next line, strings that are exactly an old table name (a table or a route key), Ruby files that no longer parse, and files whose new path is already taken.

Names the rename must use​

Catalyst::Upgrade::Names (lib/catalyst/upgrade/names.rb) is the single source of truth for the new names: the codemod rewrites host code to exactly these constants, so the rename must define them. It also assumes that engine views and assets keep their file names when their folder moves from cm_admin/ to catalyst/ (cm_admin/main/_table → catalyst/main/_table). Change the table and the rename together.