Skip to content

Fixup transition model generator for namespaced models#555

Merged
JoeSouthan merged 4 commits intomasterfrom
joesouthan-fixup-generators
Sep 5, 2025
Merged

Fixup transition model generator for namespaced models#555
JoeSouthan merged 4 commits intomasterfrom
joesouthan-fixup-generators

Conversation

@JoeSouthan
Copy link
Copy Markdown
Contributor

@JoeSouthan JoeSouthan commented Sep 5, 2025

Fixes #460, #546

Namespaced models were not having their transition class generated correctly

Also fixes issue where the model is created after the migration.

Output:

# 20250905103710_create_game_chess_transitions.rb
class CreateGameChessTransitions < ActiveRecord::Migration[8.0]
  def change
    create_table :game_chess_transitions do |t|
      t.string :from_state, null: false
      t.string :to_state, null: false
      t.jsonb :metadata, default: {}
      t.integer :sort_key, null: false
      t.integer :game_chess_id, null: false
      t.boolean :most_recent, null: false

      # If you decide not to include an updated timestamp column in your transition
      # table, you'll need to configure the `updated_timestamp_column` setting in your
      # migration class.
      t.timestamps null: false
    end

    # Foreign keys are optional, but highly recommended
    add_foreign_key :game_chess_transitions, :game_chesses

    add_index(:game_chess_transitions,
              %i[game_chess_id sort_key],
              unique: true,
              name: "index_game_chess_transitions_parent_sort")
    add_index(:game_chess_transitions,
              %i[game_chess_id most_recent],
              unique: true,
              where: "most_recent",
              name: "index_game_chess_transitions_parent_most_recent")
  end
end

Fixes #460

Namespaced models were not having their transition class generated
correctly.
@JoeSouthan JoeSouthan marked this pull request as ready for review September 5, 2025 11:24
@JoeSouthan JoeSouthan changed the title Fixup usage of namespaced models for the transition model generator Fixup transition model generator for namespaced models Sep 5, 2025
Comment thread lib/generators/statesman/generator_helpers.rb
Comment thread lib/generators/statesman/templates/create_migration.rb.erb Outdated
Comment thread lib/generators/statesman/templates/update_migration.rb.erb Outdated
Copy link
Copy Markdown
Contributor

@Tabby Tabby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. There's potential for a little more refactoring of the templates, but nothing essential

@JoeSouthan JoeSouthan merged commit 17d08b3 into master Sep 5, 2025
129 checks passed
@JoeSouthan JoeSouthan deleted the joesouthan-fixup-generators branch September 5, 2025 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generator migration file name inconsistent with class name

2 participants