'use strict'; module.exports = { async up(queryInterface, Sequelize) { // Users テーブルの作成 await queryInterface.createTable('users', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, discordId: { type: Sequelize.STRING }, username: { type: Sequelize.STRING }, email: { type: Sequelize.STRING }, isAccountSetupComplete: { type: Sequelize.BOOLEAN }, createdAt: { allowNull: false, type: Sequelize.DATE }, updatedAt: { allowNull: false, type: Sequelize.DATE } }); // Isotopesテーブルの作成(Botsからリネーム) await queryInterface.createTable('isotopes', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.BIGINT }, name: { type: Sequelize.STRING, allowNull: false }, user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'id' }, onDelete: 'CASCADE' }, first_person: { type: Sequelize.STRING, allowNull: false, defaultValue: 'ワタシ' }, personality: { type: Sequelize.STRING, allowNull: true }, tone: { type: Sequelize.STRING, allowNull: true }, background_story: { type: Sequelize.TEXT, allowNull: true }, likes: { type: Sequelize.STRING, allowNull: true }, dislikes: { type: Sequelize.STRING, allowNull: true }, created_at: { allowNull: false, type: Sequelize.DATE, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') }, updated_at: { allowNull: false, type: Sequelize.DATE, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') } }); // ChatMessages テーブルの作成 await queryInterface.createTable('chat_messages', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.BIGINT }, user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'id' }, onDelete: 'CASCADE' }, isotope_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'isotopes', key: 'id' }, onDelete: 'CASCADE' }, role: { type: Sequelize.ENUM('user', 'assistant'), allowNull: false, defaultValue: 'user' }, message: { type: Sequelize.TEXT, allowNull: false }, created_at: { allowNull: false, type: Sequelize.DATE, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') }, updated_at: { allowNull: false, type: Sequelize.DATE, defaultValue: Sequelize.literal('CURRENT_TIMESTAMP') } }); }, async down(queryInterface, Sequelize) { // ChatMessages テーブルの削除 await queryInterface.dropTable('chat_messages'); // Isotopes テーブルの削除 await queryInterface.dropTable('isotopes'); // Users テーブルの削除 await queryInterface.dropTable('Users'); } };