Skip to content

Commit

Permalink
feat: db の birthday の type を変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kokoichi206 committed Feb 25, 2023
1 parent 2d93232 commit 5077f86
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
27 changes: 24 additions & 3 deletions db/my_models/member_infos.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion db/my_models/member_infos_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions migrations/04_alter_birthday.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE member_infos ALTER COLUMN birthday
TYPE VARCHAR (11) USING CASE
-- locale_id == 1 → en
WHEN locale_id = '1' THEN TO_CHAR(birthday, 'MM/DD/YYYY')
-- locale_id == 2 → ja
WHEN locale_id = '2' THEN TO_CHAR(birthday, 'YYYY年MM月DD日')
END;
5 changes: 5 additions & 0 deletions migrations/04_alter_birthday.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE member_infos ALTER COLUMN birthday
TYPE date USING CASE
WHEN birthday ~ E'^\\d{1,2}/\\d{1,2}/\\d{4}$' THEN TO_DATE(birthday, 'MM/DD/YYYY')
WHEN birthday ~ E'^\\d{4}年\\d{1,2}月\\d{1,2}日$' THEN TO_DATE(birthday, 'YYYY年MM月DD日')
END;

0 comments on commit 5077f86

Please sign in to comment.