You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
2.0 KiB
33 lines
2.0 KiB
-- ============================================
|
|
-- データ初期化およテストデータ投入スクリプト
|
|
-- 対象テーブル:users, tasks
|
|
-- 実行順に注意(外部キー制約あり)
|
|
-- ============================================
|
|
|
|
-- 1. 既存データの削除(テーブル自体は削除されません)
|
|
-- tasksテーブルはusersに外部キー参照しているため、削除順は tasks → users
|
|
DELETE FROM tasks;
|
|
DELETE FROM users;
|
|
|
|
-- 2. usersテーブルへ初期ユーザーデータを挿入
|
|
-- パスワードは事前にBCrypt(ラウンド回数10)でハッシュ化しておくこと
|
|
-- ハッシュ生成例:https://toolbase.cc/text/bcrypt などを使用
|
|
|
|
-- パスワード対応表(すべてラウンド10で生成済み):
|
|
-- "password1" → $2a$10$QvmWALLG44WrDJ/y9Jh7p.fehSkDZfC84bXiM4ZQteM3T6x/1aEDK
|
|
-- "password2" → $2a$10$O8QS5GcMVSz7pFD3pY7c0e6SsbmDtKVLNAL7zKhnfn3hEm6.P6vvO
|
|
-- "password3" → $2a$10$5k/c3/R29iyZ7Oe9vso6ZeQvcEYkyQMS7rJ1CVNGiY9dwCL05J9VK
|
|
|
|
INSERT INTO users (id, username, password, name, email) VALUES
|
|
(1, 'testuser1', '$2a$10$QvmWALLG44WrDJ/y9Jh7p.fehSkDZfC84bXiM4ZQteM3T6x/1aEDK', 'testuser1', 'test1@test.test'),
|
|
(2, 'testuser2', '$2a$10$O8QS5GcMVSz7pFD3pY7c0e6SsbmDtKVLNAL7zKhnfn3hEm6.P6vvO', 'testuser2', 'test2@test.test'),
|
|
(3, 'testuser3', '$2a$10$5k/c3/R29iyZ7Oe9vso6ZeQvcEYkyQMS7rJ1CVNGiY9dwCL05J9VK', 'testuser3', 'test3@test.test');
|
|
|
|
-- 3. tasksテーブルへ初期タスクデータを挿入
|
|
-- created_at / updated_at は明示的に設定
|
|
-- user_id は上記で追加した users.id を参照
|
|
|
|
INSERT INTO tasks (id, title, description, completed, user_id, created_at, updated_at) VALUES
|
|
(1, 'テストタスク1', '説明1', true, 1, '2025-06-01 00:00:00', '2025-06-01 00:00:00'),
|
|
(2, 'テストタスク2', '説明2', true, 2, '2025-06-01 01:00:00', '2025-06-01 01:00:00'),
|
|
(3, 'テストタスク3', '説明3', false, 3, '2025-06-01 02:00:00', '2025-06-01 02:00:00'); |