Sha256: 3b5e8980d7c23403676fbcd57dcee94838b6b26e7f39a12f03c729316a63e671

Contents?: true

Size: 1.86 KB

Versions: 65

Compression:

Stored size: 1.86 KB

Contents

module Souls
  module Api
    module Generate
      class << self
        def create_migration(class_name: "user")
          pluralized_class_name = class_name.underscore.pluralize
          system("rake db:create_migration NAME=create_#{pluralized_class_name}")
          file_path = Dir["db/migrate/*create_#{pluralized_class_name}.rb"].first
          File.open(file_path, "w") do |f|
            f.write(<<~TEXT)
              class Create#{pluralized_class_name.camelize} < ActiveRecord::Migration[6.1]
                def change
                  create_table :#{pluralized_class_name} do |t|

                    t.boolean :is_deleted, null: false, default: false
                    t.timestamps
                  end
                end
              end
            TEXT
          end
        end

        def add_column(class_name: "user")
          pluralized_class_name = class_name.underscore.pluralize
          system("rake db:create_migration NAME=add_column_to_#{pluralized_class_name}")
        end

        def rename_column(class_name: "user")
          pluralized_class_name = class_name.underscore.pluralize
          system("rake db:create_migration NAME=rename_column_to_#{pluralized_class_name}")
        end

        def change_column(class_name: "user")
          pluralized_class_name = class_name.underscore.pluralize
          system("rake db:create_migration NAME=change_column_to_#{pluralized_class_name}")
        end

        def remove_column(class_name: "user")
          pluralized_class_name = class_name.underscore.pluralize
          system("rake db:create_migration NAME=remove_column_to_#{pluralized_class_name}")
        end

        def drop_table(class_name: "user")
          pluralized_class_name = class_name.underscore.pluralize
          system("rake db:create_migration NAME=drop_table_to_#{pluralized_class_name}")
        end
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
souls-0.38.2 lib/souls/api/generate/migration.rb
souls-0.38.1 lib/souls/api/generate/migration.rb
souls-0.38.0 lib/souls/api/generate/migration.rb
souls-0.37.0 lib/souls/api/generate/migration.rb
souls-0.36.4 lib/souls/api/generate/migration.rb
souls-0.36.3 lib/souls/api/generate/migration.rb
souls-0.36.2 lib/souls/api/generate/migration.rb
souls-0.36.1 lib/souls/api/generate/migration.rb
souls-0.36.0 lib/souls/api/generate/migration.rb
souls-0.35.4 lib/souls/api/generate/migration.rb
souls-0.35.3 lib/souls/api/generate/migration.rb
souls-0.35.2 lib/souls/api/generate/migration.rb
souls-0.35.1 lib/souls/api/generate/migration.rb
souls-0.35.0 lib/souls/api/generate/migration.rb
souls-0.34.2 lib/souls/api/generate/migration.rb
souls-0.34.1 lib/souls/api/generate/migration.rb
souls-0.34.0 lib/souls/api/generate/migration.rb
souls-0.33.14 lib/souls/api/generate/migration.rb
souls-0.33.13 lib/souls/api/generate/migration.rb
souls-0.33.12 lib/souls/api/generate/migration.rb