feat: 레거시 DB 순차 증분 이관 CLI 추가

This commit is contained in:
2026-08-18 12:35:24 +00:00
parent e910a635e6
commit da0e32f422
21 changed files with 1375 additions and 104 deletions
+12 -2
View File
@@ -68,12 +68,13 @@ export const paginateSource = async function* (
pool: MariaPool,
table: string,
idColumn: string,
batchSize: number
batchSize: number,
afterId: bigint = -1n
): AsyncGenerator<SourceRow[]> {
if (!MARIA_IDENTIFIER.test(table) || !MARIA_IDENTIFIER.test(idColumn)) {
throw new Error('Unsafe MariaDB table or ID column');
}
let lastId = -1n;
let lastId = afterId;
for (;;) {
const rows = await querySource(
pool,
@@ -88,6 +89,15 @@ export const paginateSource = async function* (
}
};
export const sourceMaxId = async (pool: MariaPool, table: string, idColumn: string): Promise<bigint | null> => {
if (!MARIA_IDENTIFIER.test(table) || !MARIA_IDENTIFIER.test(idColumn)) {
throw new Error('Unsafe MariaDB table or ID column');
}
const rows = await querySource(pool, `SELECT MAX(\`${idColumn}\`) AS max_id FROM \`${table}\``);
const value = rows[0]?.max_id;
return value === null || value === undefined ? null : toBigInt(value, `${table}.${idColumn}`);
};
const targetValue = (value: unknown): unknown => {
if (value instanceof JsonParameter) {
return JSON.stringify(value.value);