From 6ce62ea2c1e2f81568e515bb18395d0324a13a47 Mon Sep 17 00:00:00 2001 From: Alexis Rico Date: Fri, 15 Mar 2024 12:00:16 +0100 Subject: [PATCH] Update migrator Signed-off-by: Alexis Rico --- drizzle-orm/src/xata-http/migrator.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drizzle-orm/src/xata-http/migrator.ts b/drizzle-orm/src/xata-http/migrator.ts index f93f45e03..6ef2f61ce 100644 --- a/drizzle-orm/src/xata-http/migrator.ts +++ b/drizzle-orm/src/xata-http/migrator.ts @@ -1,6 +1,6 @@ import type { MigrationConfig } from '~/migrator.ts'; import { readMigrationFiles } from '~/migrator.ts'; -import { type SQL, sql } from '~/sql/sql.ts'; +import { sql } from '~/sql/sql.ts'; import type { XataHttpDatabase } from './driver.ts'; /** @@ -32,18 +32,18 @@ export async function migrate>(db: XataH }>(sql`select id, hash, created_at from ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} order by created_at desc limit 1`); const lastDbMigration = dbMigrations[0]; - const rowsToInsert: SQL[] = []; + for await (const migration of migrations) { if (!lastDbMigration || Number(lastDbMigration.created_at) < migration.folderMillis) { for (const stmt of migration.sql) { await db.session.execute(sql.raw(stmt)); } - rowsToInsert.push(sql`insert into ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${migration.folderMillis})`); + await db.session.execute( + sql`insert into ${sql.identifier(migrationsSchema)}.${sql.identifier(migrationsTable)} ("hash", "created_at") values(${migration.hash}, ${ + migration.folderMillis + })` + ); } } - - for await (const rowToInsert of rowsToInsert) { - await db.session.execute(rowToInsert); - } }