2

Prisma - Backup System

 2 years ago
source link: https://dev.to/daxsoft/prisma-backup-system-n6f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Backup System

// start

Hi everyone!
GitHub of the Project


Use this module to create a backup measure for your project that uses Prisma. You can either backup the information, or use them to migrate to another database, or just to reset the database.
Example: Let's say that you need to change a unique key (email) to another like (code). You can backup first,
then change the schema.prisma, and use this module to inject the old information.


// How To Use

Basic example using the Prisma, let's imagine that we have two models, User & Post. And the Post model is related to the User model.

import { PrismaClient } from '@prisma/client';
import { backup } from '@vorlefan/prisma-backup';

const prisma = new PrismaClient();

void (async function () {
    const [user, post] = await prisma.$transaction([prisma.user.findMany({}), prisma.post.findMany({})]);

    // w/out encrypt

    await backup({
        models: {
            user,
        },
    });

    // encrypting the models

    await backup({
        models: {
            user,
        },
        encrypt: true,
        password: 'pwd123',
        backupFolderName: 'encrypted'
    });
})();

Enter fullscreen mode

Exit fullscreen mode


// End

There a lot of feature that I'm planning for this module, then if you want to, please contribute or follow up the news xD


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK