Sha256: aab3c7a9402a25df58df459c9cef2b761a19d38fb14501b0c2ef12a410ecad64

Contents?: true

Size: 959 Bytes

Versions: 9

Compression:

Stored size: 959 Bytes

Contents

require_relative 'model_attribute'

module Hippo
    module Command
        module MigrationSupport
            def create_migration
                migration = existing_migration ||
                  migration_timestamp + "_create_#{table_name}.rb"
                self.fields = fields.map{ |field| ModelAttribute.parse(field) }
                template "db/create_table_migration.rb", "db/migrate/#{migration}"
            end

          private

            def existing_migration
                migrations = Pathname.glob("#{destination_root}/db/migrate/[0-9]*_create_#{table_name}.rb")
                migrations.any? ? migrations.first.basename.to_s : nil
            end

            def migration_timestamp
                ENV['MIGRATION_TIMESTAMP'] || Time.now.utc.strftime("%Y%m%d%H%M%S")
            end

            def fields_with_index
                fields.select { |a| !a.reference? && a.has_index? }
            end
        end
    end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hippo-fw-0.9.9 lib/hippo/command/migration_support.rb
hippo-fw-0.9.8 lib/hippo/command/migration_support.rb
hippo-fw-0.9.7 lib/hippo/command/migration_support.rb
hippo-fw-0.9.6 lib/hippo/command/migration_support.rb
hippo-fw-0.9.5 lib/hippo/command/migration_support.rb
hippo-fw-0.9.4 lib/hippo/command/migration_support.rb
hippo-fw-0.9.3 lib/hippo/command/migration_support.rb
hippo-fw-0.9.2 lib/hippo/command/migration_support.rb
hippo-fw-0.9.1 lib/hippo/command/migration_support.rb