feat: 레거시 DB 순차 증분 이관 CLI 추가
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user