libsql-migrate
Advanced tools
+1
-1
| { | ||
| "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": { |
+7
-7
@@ -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]); |
+29
-9
@@ -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 { |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
36376
1.95%716
2.43%