Skip to content

Commit

Permalink
Merge pull request #364 from amplication/auth-basic-add-seed-template
Browse files Browse the repository at this point in the history
fix(plugins): add seed template to auth-basic plugin
  • Loading branch information
mulygottlieb authored Mar 20, 2024
2 parents c73f882 + e115a8e commit eba9128
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/auth-basic/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@amplication/plugin-auth-basic",
"version": "1.4.12",
"version": "1.4.13",
"description": "set basic auth for Amplication build",
"main": "dist/index.js",
"nx": {},
Expand Down
44 changes: 44 additions & 0 deletions plugins/auth-basic/src/templates/seed.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***
* This file was auto-generated by Amplication and should not be modified by hand.
* The file will be re-generated with every new build, and all changes will be lost.
* To add a custom seed script, you can safely edit the content of ./customSeed.ts
***/

import * as dotenv from "dotenv";
import { PrismaClient } from "@prisma/client";
import { customSeed } from "./customSeed";

declare const DATA: { username: string };

if (require.main === module) {
dotenv.config();

const { BCRYPT_SALT } = process.env;

if (!BCRYPT_SALT) {
throw new Error("BCRYPT_SALT environment variable must be defined");
}

seed().catch((error) => {
console.error(error);
process.exit(1);
});
}

async function seed() {
console.info("Seeding database...");

const client = new PrismaClient();
const data = DATA;
await client.user.upsert({
where: { username: data.username },
update: {},
create: data,
});
void client.$disconnect();

console.info("Seeding database with custom seed...");
customSeed();

console.info("Seeded database successfully");
}

0 comments on commit eba9128

Please sign in to comment.