Skip to content

Commit

Permalink
Files added
Browse files Browse the repository at this point in the history
  • Loading branch information
dallascrichmond committed Dec 17, 2024
1 parent 643e367 commit 9e0e4c7
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
8 changes: 8 additions & 0 deletions backend/prisma/data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @summary All seed data for dev
*/
const regions = [
{ id: 1, name: 'Cariboo' },
];

export default regions;
42 changes: 42 additions & 0 deletions backend/prisma/seed.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { PrismaClient } from '@prisma/client';
import dotenv from 'dotenv';
import regions from './data.mjs';

const prisma = new PrismaClient();

dotenv.config();

// const environment = process.env.NODE_ENV || 'production';

/**
* @summary Seeds all the necessary base data in both dev and prod.
* Checks for any changes to existing tables and updates accordingly
*/
async function seedBase() {
const seedingPromises = [];

seedingPromises.push(
...regions.map((range) => prisma.salaryRange.upsert({
where: { id: range.id },
create: range,
update: range,
})),
);

await Promise.all(seedingPromises);
}

(async () => {
try {
await seedBase();
// if (environment === 'development') {
// await seedUsers();
// await seedInquiries();
// }
} catch (error) {
// eslint-disable-next-line no-console
console.error('Error during seeding:', error);
} finally {
await prisma.$disconnect();
}
})();
4 changes: 3 additions & 1 deletion backend/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ pwd
# Run migrations
npx prisma db push --schema='prisma/schema.prisma' --skip-generate
# Seed data
# npx prisma db seed
npx prisma db seed
# Start the application
npm run dev
8 changes: 8 additions & 0 deletions backend/startDev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
pwd
# Run migrations
npx prisma db push --schema='prisma/schema.prisma' --skip-generate
# Seed data
npx prisma db seed
# Start the application
npm run dev

0 comments on commit 9e0e4c7

Please sign in to comment.