-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from amplication/auth-basic-add-seed-template
fix(plugins): add seed template to auth-basic plugin
- Loading branch information
Showing
3 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} |