Skip to content

Instantly share code, notes, and snippets.

@smapira
Last active September 23, 2021 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smapira/dc3df2f585f506a0227fe29f3baba91e to your computer and use it in GitHub Desktop.
Save smapira/dc3df2f585f506a0227fe29f3baba91e to your computer and use it in GitHub Desktop.
namespace :db do
task 'migrate_custom' do
ActiveRecord::ConnectionAdapters::TableDefinition.prepend(
CoreExtensions::ActiveRecord::ConnectionAdapters::TableDefinition
)
Rake::Task['db:migrate'].invoke
end
end
module CoreExtensions
module ActiveRecord
module ConnectionAdapters
module TableDefinition
def coordinate(*args)
options = args.extract_options!
options.reverse_merge!({ precision: 12, scale: 7, default: 0.0 })
column_names = args
type = :decimal
column_names.each { |name| column(name, type, options) }
end
def postal_code(*args)
options = args.extract_options!
options.reverse_merge!({ limit: 7, default: '', comment: '郵便番号' })
column_names = args
type = :string
column_names.each { |name| column(name, type, options) }
end
def credit_card_number(*args)
options = args.extract_options!
options.reverse_merge!({ limit: 16, default: '', comment: 'クレジットカード番号' })
column_names = args
type = :string
column_names.each { |name| column(name, type, options) }
end
def bank_account_number(*args)
options = args.extract_options!
options.reverse_merge!({ limit: 7, default: '', comment: '銀行口座番号' })
column_names = args
type = :string
column_names.each { |name| column(name, type, options) }
end
def phone_number(*args)
options = args.extract_options!
options.reverse_merge!({ limit: 11, default: '', comment: '電話番号' })
column_names = args
type = :string
column_names.each { |name| column(name, type, options) }
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment