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
},
name: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
unique: true
},
abbreviation: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false
},
description: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false
},
createdAt: {

View File

@ -48,22 +48,6 @@ module.exports = {
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');

View File

@ -9,12 +9,12 @@ module.exports = {
type: Sequelize.INTEGER
},
name: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false,
unique: true
},
description: {
type: DataTypes.STRING,
type: Sequelize.STRING,
allowNull: false
},
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');
}
};