/** @type {import('sequelize-cli').Migration} */ module.exports = { async up(queryInterface, Sequelize) { await queryInterface.createTable('Players', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, userId: { type: Sequelize.INTEGER, references: { model: 'Users', key: 'id' }, onUpdate: 'CASCADE', onDelete: 'CASCADE' }, height: { type: Sequelize.INTEGER }, weight: { type: Sequelize.INTEGER }, gender: { allowNull: false, type: Sequelize.ENUM('male', 'female', 'other'), }, bats: { type: Sequelize.ENUM('left', 'right', 'both'), }, throws: { type: Sequelize.ENUM('left', 'right', 'both'), }, jerseyNumber: { type: Sequelize.INTEGER, }, state: { type: Sequelize.ENUM('active', 'injured', 'inactive'), }, createdAt: { allowNull: false, type: Sequelize.DATE }, updatedAt: { allowNull: false, type: Sequelize.DATE } }); // 2. Kopiere Daten von Users nach Players await queryInterface.sequelize.query(` INSERT INTO "Players" ("userId", "height", "weight", "gender", "bats", "throws", "createdAt", "updatedAt") SELECT "id" as "userId", "height", "weight", "gender"::text::"enum_Players_gender", "handedness"::text::"enum_Players_bats", "handedness"::text::"enum_Players_throws", "createdAt", "updatedAt" FROM "Users" `); }, async down(queryInterface, /*Sequelize*/) { await queryInterface.dropTable('Players'); } };