26 行
718 B
Ruby
26 行
718 B
Ruby
class CreateRegions < ActiveRecord::Migration[8.0]
|
|
def up
|
|
create_table :regions, id: { type: :integer, limit: 2 }, primary_key: :code do |t|
|
|
t.column :alpha_code, 'CHAR(2)'
|
|
t.string :name, null: false
|
|
t.datetime :deprecated_at, index: true
|
|
t.datetime :created_at, null: false
|
|
|
|
t.check_constraint "REGEXP_LIKE(alpha_code, '^[A-Z]{2}$', 'c')",
|
|
name: 'regions_alpha_code_check'
|
|
t.index [:alpha_code], unique: true
|
|
end
|
|
|
|
execute <<~SQL
|
|
INSERT INTO
|
|
regions(code, alpha_code, name, created_at)
|
|
VALUES
|
|
(392, 'JP', '日本国', #{ connection.quote Time.current })
|
|
SQL
|
|
end
|
|
|
|
def down
|
|
drop_table :regions
|
|
end
|
|
end
|