feat(matches): add fixture type handling and notes to manual match creation; update localization for match types
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 56s
All checks were successful
Deploy tt-tagebuch / deploy (push) Successful in 56s
This commit is contained in:
68
backend/scripts/runMigrations.js
Normal file
68
backend/scripts/runMigrations.js
Normal file
@@ -0,0 +1,68 @@
|
||||
import sequelize from '../database.js';
|
||||
|
||||
const migrations = [
|
||||
{
|
||||
id: '20260819_add_manual_match_fields',
|
||||
async up() {
|
||||
const [fixtureTypeColumns] = await sequelize.query("SHOW COLUMNS FROM `match` LIKE 'fixture_type'");
|
||||
if (fixtureTypeColumns.length === 0) {
|
||||
await sequelize.query("ALTER TABLE `match` ADD COLUMN `fixture_type` VARCHAR(32) NOT NULL DEFAULT 'league'");
|
||||
}
|
||||
|
||||
const [notesColumns] = await sequelize.query("SHOW COLUMNS FROM `match` LIKE 'notes'");
|
||||
if (notesColumns.length === 0) {
|
||||
await sequelize.query('ALTER TABLE `match` ADD COLUMN `notes` TEXT NULL');
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
id: '20260819_create_kaisertisch_tournaments',
|
||||
async up() {
|
||||
await sequelize.query(`
|
||||
CREATE TABLE IF NOT EXISTS kaisertisch_tournaments (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
club_id INT NOT NULL,
|
||||
diary_date_id INT NOT NULL,
|
||||
state JSON NOT NULL,
|
||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY uniq_kaisertisch_tournament_club_date (club_id, diary_date_id),
|
||||
CONSTRAINT fk_kaisertisch_tournament_club FOREIGN KEY (club_id) REFERENCES clubs(id) ON DELETE CASCADE,
|
||||
CONSTRAINT fk_kaisertisch_tournament_date FOREIGN KEY (diary_date_id) REFERENCES diary_dates(id) ON DELETE CASCADE
|
||||
)
|
||||
`);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
async function runMigrations() {
|
||||
await sequelize.authenticate();
|
||||
await sequelize.query(`
|
||||
CREATE TABLE IF NOT EXISTS schema_migrations (
|
||||
id VARCHAR(191) PRIMARY KEY,
|
||||
applied_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
)
|
||||
`);
|
||||
|
||||
const [appliedRows] = await sequelize.query('SELECT id FROM schema_migrations');
|
||||
const applied = new Set(appliedRows.map((row) => row.id));
|
||||
|
||||
for (const migration of migrations) {
|
||||
if (applied.has(migration.id)) continue;
|
||||
console.log(`[migration] Applying ${migration.id}`);
|
||||
await migration.up();
|
||||
await sequelize.query('INSERT INTO schema_migrations (id) VALUES (:id)', {
|
||||
replacements: { id: migration.id },
|
||||
});
|
||||
console.log(`[migration] Applied ${migration.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
runMigrations()
|
||||
.catch((error) => {
|
||||
console.error('[migration] Failed:', error);
|
||||
process.exitCode = 1;
|
||||
})
|
||||
.finally(async () => {
|
||||
await sequelize.close();
|
||||
});
|
||||
Reference in New Issue
Block a user