Merged PR 810: アカウント退避テーブル作成

## 概要
[Task3848: アカウント退避テーブル作成](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3848)

- アカウントテーブルと同様の構造をしたアカウント退避テーブルを作成
  - ※差分:  company_nameを削除、active_worktype_idの外部キー制約を削除

## レビューポイント
- 上記要素以外はaccountsテーブルの要素と同等であるか
- 張られたインデックスに不足はないか
- 想定と違う構造になっていないか

## 動作確認状況
- npm run migrate:up/downを実施
- EXPLAINでindexが機能していそうな事を確認
```
EXPLAIN SELECT * FROM omds_ccb.accounts_archive where parent_account_id=1;
---------------------------------------------------
# id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'accounts_archive', NULL, 'ref', 'idx_accounts_archive_parent_account_id', 'idx_accounts_archive_parent_account_id', '9', 'const', '1', '100.00', NULL
```

```
EXPLAIN SELECT * FROM omds_ccb.accounts_archive where tier=2;
---------------------------------------------------
# id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'accounts_archive', NULL, 'ref', 'idx_accounts_archive_tier', 'idx_accounts_archive_tier', '4', 'const', '2', '100.00', NULL
```
```
EXPLAIN SELECT * FROM omds_ccb.accounts_archive where parent_account_id=1 AND tier=1;
----------------------------------------------------
# id, select_type, table, partitions, type, possible_keys, key, key_len, ref, rows, filtered, Extra
'1', 'SIMPLE', 'accounts_archive', NULL, 'ref', 'idx_accounts_archive_parent_account_id,idx_accounts_archive_tier', 'idx_accounts_archive_parent_account_id', '9', 'const', '1', '50.00', 'Using where'
```
This commit is contained in:
湯本 開 2024-03-08 05:20:00 +00:00
parent 146b8a6e40
commit 869cbd43e0

View File

@ -0,0 +1,24 @@
-- +migrate Up
CREATE TABLE IF NOT EXISTS `accounts_archive` (
`id` BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY COMMENT 'ID',
`parent_account_id` BIGINT UNSIGNED COMMENT '親アカウントID',
`tier` INT UNSIGNED NOT NULL COMMENT '商流における階層',
`country` VARCHAR(16) NOT NULL COMMENT '国名(ISO 3166-1 alpha-2)',
`delegation_permission` BOOLEAN NOT NULL DEFAULT 0 COMMENT '上位階層からの代行操作を許可しているか',
`locked` BOOLEAN NOT NULL DEFAULT 0 COMMENT 'アカウントがロック済みであるか',
`verified` BOOLEAN NOT NULL DEFAULT 0 COMMENT 'email認証が完了済みであるか',
`primary_admin_user_id` BIGINT UNSIGNED COMMENT 'プライマリ管理者ユーザーID',
`secondary_admin_user_id` BIGINT UNSIGNED COMMENT 'セカンダリ管理者ユーザーID',
`active_worktype_id` BIGINT UNSIGNED COMMENT 'アカウントで利用するデフォルトのWorkTypeIDActive WorktypeIDの内部ID',
`auto_file_delete` BOOLEAN NOT NULL DEFAULT 0 COMMENT '自動ファイル削除をするかどうか',
`file_retention_days` INT UNSIGNED COMMENT '文字起こし完了してから自動ファイル削除するまでのファイル保持日数',
`deleted_at` TIMESTAMP COMMENT '削除時刻',
`created_by` VARCHAR(255) COMMENT '作成者',
`created_at` TIMESTAMP DEFAULT now() COMMENT '作成時刻',
`updated_by` VARCHAR(255) COMMENT '更新者',
`updated_at` TIMESTAMP DEFAULT now() COMMENT '更新時刻',
INDEX `idx_accounts_archive_tier` (`tier`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci;
-- +migrate Down
DROP TABLE `accounts_archive`;