Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ src/assets/iconify-icons/generated-icons.css
sendgrid.env

# production
app-data/.seeded
/app-data/*
!/app-data/.gitkeep
Empty file added app-data/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- NODE_ENV=production
depends_on:
- postgres
command: sh -c "cd src && npx prisma migrate deploy && [ -f /app/data/.seeded ] || (npx prisma db seed && touch /app/data/.seeded) && cd .. && npm start"
command: sh -c "cd src && npx prisma migrate deploy && mkdir -p /app/data && [ -f /app/data/.seeded ] || (npx prisma db seed && touch /app/data/.seeded) && cd .. && npm start"
networks:
- app-network
volumes:
Expand Down
4 changes: 3 additions & 1 deletion src/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { prisma } from './client'
import { initialiseUsersAndResponses } from './seeds/users'
import { initialiseAdmin, initialiseUsersAndResponses } from './seeds/users'

async function initialiseQuestions() {
const NMSK1 = await prisma.question.create({
Expand Down Expand Up @@ -315,6 +315,8 @@ async function main() {

if (process.env.NODE_ENV === 'development') {
await initialiseUsersAndResponses()
} else if (process.env.NODE_ENV === 'production') {
await initialiseAdmin()
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/prisma/seeds/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ async function generateMultipleResearcher(num_researcher = 2) {
}
}

export async function initialiseAdmin() {
const hashedPassword = await bcrypt.hash('1234567', 10)

await prisma.user.create({
data: {
email: 'admin1@mail.com',
hashedPassword: hashedPassword,
firstName: 'admin1',
lastName: 'admin1',
role: Role.ADMIN
}
})
}

export async function initialiseUsersAndResponses() {
const hashedPassword = await bcrypt.hash('1234567', 10)

Expand Down
Loading