Skip to content

Commit

Permalink
feat: added opt out option of backup migrations - fix #56 (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
pagoru authored Feb 2, 2025
1 parent 98fd247 commit 43ba2d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/modules/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ import type {
import { join } from "@std/path";
import { getUtilDate } from "../utils/date.utils.ts";

export const getDb = (
{ pathname, backupsPathname }: DbProps = {
pathname: "./database",
backupsPathname: "./database-backups",
export const getDb = ({
pathname = "./database",
backups: {
pathname: backupsPathname = "./database-backups",
onMigration: backupOnMigration = true,
} = {
pathname: "./database-backups",
onMigration: true,
},
): DbMutable => {
}: DbProps): DbMutable => {
let db: Deno.Kv;

const $migrations: DbMigrationsMutable = ((): DbMigrationsMutable => {
Expand Down Expand Up @@ -51,7 +55,7 @@ export const getDb = (
console.log(`- Migration ${migration.id} was already applied!`);
continue;
}
await backup(`_migration_${migration.id}`);
if (backupOnMigration) await backup(`_migration_${migration.id}`);

try {
await migration.up(dbMutables);
Expand Down
5 changes: 4 additions & 1 deletion src/types/db.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export type DbProps = {
pathname?: string;
backupsPathname?: string;
backups?: {
pathname?: string;
onMigration?: boolean;
};
};

export type Migration = {
Expand Down

0 comments on commit 43ba2d8

Please sign in to comment.