Class: RailsPulse::Generators::ConvertToMigrationsGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/rails_pulse/convert_to_migrations_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



9
10
11
12
# File 'lib/generators/rails_pulse/convert_to_migrations_generator.rb', line 9

def self.next_migration_number(path)
  next_migration_number = current_migration_number(path) + 1
  ActiveRecord::Migration.next_migration_number(next_migration_number)
end

Instance Method Details

#check_schema_fileObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/generators/rails_pulse/convert_to_migrations_generator.rb', line 14

def check_schema_file
  unless File.exist?("db/rails_pulse_schema.rb")
    # Only show message in non-test environments to reduce test noise
    unless Rails.env.test?
      say "No db/rails_pulse_schema.rb file found. Run 'rails generate rails_pulse:install' first.", :red
      exit 1
    else
      return false
    end
  end

  if rails_pulse_tables_exist?
    unless Rails.env.test?
      say "Rails Pulse tables already exist. No conversion needed.", :yellow
      say "Use 'rails generate rails_pulse:upgrade' to update existing installation.", :blue
      exit 0
    else
      return false
    end
  end

  true
end

#create_conversion_migrationObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/rails_pulse/convert_to_migrations_generator.rb', line 38

def create_conversion_migration
  # Only create migration if schema file check passes
  return unless check_schema_file

  say "Converting db/rails_pulse_schema.rb to migration...", :green

  migration_template(
    "migrations/install_rails_pulse_tables.rb",
    "db/migrate/install_rails_pulse_tables.rb"
  )
end

#display_completion_messageObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/generators/rails_pulse/convert_to_migrations_generator.rb', line 50

def display_completion_message
  # Only display completion message if migration was created
  return unless File.exist?("db/rails_pulse_schema.rb")

  say <<~MESSAGE

    Conversion complete!

    Next steps:
    1. Run: rails db:migrate
    2. Restart your Rails server

    The schema file db/rails_pulse_schema.rb remains as your single source of truth.
    Future Rails Pulse updates will come as regular migrations in db/migrate/

  MESSAGE
end