imaginar/migrations/20241019023548-initial-schema.js
2024-10-19 20:24:54 +09:00

151 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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');
}
};