extract creating of player table into a separate migration file

This commit is contained in:
Sascha Kühl 2025-05-30 13:38:53 +02:00
parent b40824c3e5
commit 3d8bb3f40e
7 changed files with 27 additions and 21 deletions

View File

@ -9,16 +9,16 @@ module.exports = {
type: Sequelize.INTEGER type: Sequelize.INTEGER
}, },
name: { name: {
type: DataTypes.STRING, type: Sequelize.STRING,
allowNull: false, allowNull: false,
unique: true unique: true
}, },
abbreviation: { abbreviation: {
type: DataTypes.STRING, type: Sequelize.STRING,
allowNull: false allowNull: false
}, },
description: { description: {
type: DataTypes.STRING, type: Sequelize.STRING,
allowNull: false allowNull: false
}, },
createdAt: { createdAt: {

View File

@ -48,22 +48,6 @@ module.exports = {
type: Sequelize.DATE 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*/) { async down(queryInterface, /*Sequelize*/) {
await queryInterface.dropTable('Players'); await queryInterface.dropTable('Players');

View File

@ -9,12 +9,12 @@ module.exports = {
type: Sequelize.INTEGER type: Sequelize.INTEGER
}, },
name: { name: {
type: DataTypes.STRING, type: Sequelize.STRING,
allowNull: false, allowNull: false,
unique: true unique: true
}, },
description: { description: {
type: DataTypes.STRING, type: Sequelize.STRING,
allowNull: false allowNull: false
}, },
createdAt: { createdAt: {

View File

@ -0,0 +1,22 @@
/** @type {import('sequelize-cli').Migration} */
module.exports = {
async up(queryInterface, Sequelize) {
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');
}
};