Sha256: e1a235d136843fb32f87f8bd0a01fc784780c55ebd979f4fd4b69e08c66787bf

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

require "rails/generators"
require "rails/generators/active_record/migration"

module EasyML
  module Generators
    module Migration
      class MigrationGenerator < Rails::Generators::Base
        include Rails::Generators::Migration
        namespace "easy_ml:migration"

        # Set the source directory for templates
        source_root File.expand_path("../../templates/migration", __dir__)

        # Define the migration name
        desc "Generates migrations for EasyMLModel, Dataset, and TunerRun"

        # Specify the next migration number
        def self.next_migration_number(dirname)
          if ActiveRecord.version < Gem::Version.new("7")
            Time.now.utc.strftime("%Y%m%d%H%M%S")
          elsif ActiveRecord.timestamped_migrations
            Time.now.utc.strftime("%Y%m%d%H%M%S")
          else
            format("%.3d", (current_migration_number(dirname) + 1))
          end
        end

        # Generate the migration files using the templates
        def create_migration_files
          create_easy_ml_models_migration
        end

        private

        # Generate the migration file for EasyMLModel using the template
        def create_easy_ml_models_migration
          migration_template(
            "create_easy_ml_models.rb.tt",
            "db/migrate/create_easy_ml_models.rb"
          )
        end

        # Get the next migration number
        def next_migration_number
          self.class.next_migration_number(Rails.root.join("db/migrate"))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
easy_ml-0.1.4 lib/easy_ml/railtie/generators/migration/migration_generator.rb
easy_ml-0.1.3 lib/easy_ml/railtie/generators/migration/migration_generator.rb
easy_ml-0.1.2 lib/easy_ml/railtie/generators/migration/migration_generator.rb