🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

libsql-migrate

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libsql-migrate - npm Package Compare versions

Comparing version
1.2.0
to
1.2.1
+1
-1
package.json
{
"name": "libsql-migrate",
"version": "1.2.0",
"version": "1.2.1",
"description": "Database migration and seed management for libsql with configurable options.",

@@ -5,0 +5,0 @@ "bin": {

@@ -152,8 +152,8 @@ # libsql Migrate

| Hook Name | Called When |
| ----------------------------------------- | -------------------------------------------------------------------- |
| `beforeMigration(action, name)` | Before each migration is executed |
| `afterMigration(action, name, result)` | After each migration is successfully executed |
| `afterMigrations(action, names, results)` | **Only** called after all migrations when using the `latest` command |
| `onError(action, name, error)` | When a migration fails |
| Hook Name | Called When |
| ----------------------------------------- | ---------------------------------------------------------------------- |
| `beforeMigration(action, name)` | Before each migration is executed |
| `afterMigration(action, name, result)` | After each migration is successfully executed |
| `afterMigrations(action, names, results)` | Called after all migrations when using commands `latest` or `rollback` |
| `onError(action, name, error)` | When a migration fails |

@@ -217,3 +217,3 @@ ### Hook Parameters

afterMigrations: (action, names, results) => {
console.log(`[${action}] All migrations completed via "latest":`);
console.log(`[${action}] All migrations completed:`);
names.forEach((name, i) => {

@@ -220,0 +220,0 @@ console.log(` - ${name}`, results[i]);

@@ -23,8 +23,27 @@ import { createClient } from "@libsql/client";

migrations.latestBatch = migrations.completed.filter(
(migration) => migration.batch === batch,
);
migrations.latestBatch = migrations.completed
.filter((migration) => migration.batch === batch)
.reverse();
const results = [];
for (const migration of migrations.latestBatch) {
await migration.down(client);
if (typeof config.hooks?.beforeMigration === "function") {
await config.hooks.beforeMigration("down", migration.name);
}
let result;
try {
result = await migration.down(client);
results.push(result);
} catch (err) {
if (typeof config.hooks?.onError === "function") {
config.hooks.onError("down", migration.name, err);
}
throw err;
}
if (typeof config.hooks?.afterMigration === "function") {
await config.hooks.afterMigration("down", migration.name, result);
}
await client.execute({

@@ -41,10 +60,11 @@ sql: `

const names = migrations.latestBatch
.map((migration) => migration.name)
.join(", ");
const names = migrations.latestBatch.map((migration) => migration.name);
const plural = migrations.latestBatch.length !== 1;
if (typeof config.hooks?.afterMigrations === "function") {
await config.hooks.afterMigrations("down", names, results);
}
logger.info(
`Rolled back ${migrations.latestBatch.length} migration${plural ? "s" : ""}: ${names}.`,
`Rolled back ${migrations.latestBatch.length} migration${plural ? "s" : ""}: ${names.join(", ")}.`,
);

@@ -51,0 +71,0 @@ } else {