Release v2.6.20
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
|
||||
require('../src/common');
|
||||
|
||||
const { runMigrations } = require('../src/db/migrations');
|
||||
|
||||
function createPool(responses) {
|
||||
const queries = [];
|
||||
return {
|
||||
queries,
|
||||
async query(sql, params) {
|
||||
queries.push([sql, params]);
|
||||
const text = String(sql);
|
||||
for (const response of responses) {
|
||||
if (response.match(text, params)) {
|
||||
return response.result;
|
||||
}
|
||||
}
|
||||
return [[]];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
test('timetable rename migration does not depend on legacy timezone column', async () => {
|
||||
const pool = createPool([
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('FROM information_schema.COLUMNS') && sql.includes('TABLE_NAME = ?') && sql.includes('COLUMN_NAME = ?');
|
||||
},
|
||||
result: [[{ column_count: 0 }]]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('FROM information_schema.TABLES') && sql.includes('TABLE_NAME = ?');
|
||||
},
|
||||
result: [[{ table_count: 1 }]]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT id, name, short_description,') && sql.includes("'Europe/London' AS timezone") && sql.includes('FROM i_schedule_groups');
|
||||
},
|
||||
result: [{}]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT id, schedule_group_id, title, short_description, start_datetime, end_datetime, created_at, created_by, modified_at, modified_by FROM i_schedule_entries');
|
||||
},
|
||||
result: [{}]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT COALESCE(MAX(id), 0) AS max_id FROM i_timetable_groups');
|
||||
},
|
||||
result: [[{ max_id: 1 }]]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT COALESCE(MAX(id), 0) AS max_id FROM i_timetable_entries');
|
||||
},
|
||||
result: [[{ max_id: 2 }]]
|
||||
}
|
||||
]);
|
||||
|
||||
await runMigrations(pool, { currentVersion: '2.6.17' });
|
||||
|
||||
assert.ok(pool.queries.some(function ([sql]) {
|
||||
return String(sql).includes("SELECT id, name, short_description, 'Europe/London' AS timezone") && String(sql).includes('FROM i_schedule_groups');
|
||||
}));
|
||||
|
||||
assert.ok(!pool.queries.some(function ([sql]) {
|
||||
return String(sql).includes('SELECT id, name, short_description, timezone, created_at, created_by, modified_at, modified_by') && String(sql).includes('FROM i_schedule_groups');
|
||||
}));
|
||||
});
|
||||
|
||||
test('timetable timezone migrations use timetable tables when legacy tables are gone', async () => {
|
||||
const pool = createPool([
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('FROM information_schema.COLUMNS') && sql.includes('TABLE_NAME = ?') && sql.includes('COLUMN_NAME = ?');
|
||||
},
|
||||
result: [[{ column_count: 0 }]]
|
||||
},
|
||||
{
|
||||
match(_sql, params) {
|
||||
return Array.isArray(params) && params[0] === 'i_timetable_groups';
|
||||
},
|
||||
result: [[{ table_count: 1 }]]
|
||||
},
|
||||
{
|
||||
match(_sql, params) {
|
||||
return Array.isArray(params) && params[0] === 'i_timetable_entries';
|
||||
},
|
||||
result: [[{ table_count: 1 }]]
|
||||
},
|
||||
{
|
||||
match(_sql, params) {
|
||||
return Array.isArray(params) && params[0] === 'i_schedule_groups';
|
||||
},
|
||||
result: [[{ table_count: 0 }]]
|
||||
},
|
||||
{
|
||||
match(_sql, params) {
|
||||
return Array.isArray(params) && params[0] === 'i_schedule_entries';
|
||||
},
|
||||
result: [[{ table_count: 0 }]]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT id, start_datetime, end_datetime FROM i_timetable_entries ORDER BY id ASC');
|
||||
},
|
||||
result: [[{ id: 1, start_datetime: '2026-08-09 09:00:00', end_datetime: '2026-08-09 10:00:00' }]]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT COALESCE(MAX(id), 0) AS max_id FROM i_timetable_groups');
|
||||
},
|
||||
result: [[{ max_id: 1 }]]
|
||||
},
|
||||
{
|
||||
match(sql) {
|
||||
return sql.includes('SELECT COALESCE(MAX(id), 0) AS max_id FROM i_timetable_entries');
|
||||
},
|
||||
result: [[{ max_id: 1 }]]
|
||||
}
|
||||
]);
|
||||
|
||||
await runMigrations(pool, { currentVersion: '2.6.15' });
|
||||
|
||||
assert.ok(pool.queries.some(function ([sql]) {
|
||||
return String(sql).includes('ALTER TABLE i_timetable_groups ADD COLUMN timezone');
|
||||
}));
|
||||
|
||||
assert.ok(pool.queries.some(function ([sql]) {
|
||||
return String(sql).includes('UPDATE i_timetable_groups SET timezone = ?');
|
||||
}));
|
||||
|
||||
assert.ok(pool.queries.some(function ([sql]) {
|
||||
return String(sql).includes('UPDATE i_timetable_entries SET start_datetime = ?, end_datetime = ? WHERE id = ?');
|
||||
}));
|
||||
|
||||
assert.ok(!pool.queries.some(function ([sql]) {
|
||||
return String(sql).includes('i_schedule_groups') || String(sql).includes('i_schedule_entries');
|
||||
}));
|
||||
});
|
||||
Reference in New Issue
Block a user