-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* vrt - add seed support Signed-off-by: André Bauer <[email protected]> * fix superlinter Signed-off-by: André Bauer <[email protected]> * update postgres Signed-off-by: André Bauer <[email protected]> --------- Signed-off-by: André Bauer <[email protected]>
- Loading branch information
Showing
7 changed files
with
141 additions
and
2 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -6,13 +6,13 @@ sources: | |
- https://github.com/Visual-Regression-Tracker/Visual-Regression-Tracker | ||
- https://github.com/kokuwaio/helm-charts/tree/main/charts/visual-regression-tracker | ||
type: application | ||
version: 3.0.0 | ||
version: 3.1.0 | ||
appVersion: "5.0.3" | ||
maintainers: | ||
- name: monotek | ||
email: [email protected] | ||
dependencies: | ||
- name: postgresql | ||
version: 13.2.23 | ||
version: 13.3.0 | ||
repository: https://charts.bitnami.com/bitnami | ||
condition: vrtConfig.postgresql.enabled |
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,98 @@ | ||
/** | ||
* @see https://www.prisma.io/docs/guides/migrate/seed-database | ||
*/ | ||
import { PrismaClient, Role } from '@prisma/client'; | ||
import { genSalt, hash } from 'bcryptjs'; | ||
|
||
const prisma = new PrismaClient({ | ||
// 'info' | 'query' | 'warn' | 'error' | ||
log: ['query'], | ||
}); | ||
|
||
async function seed() { | ||
await prisma.$connect(); | ||
console.log('Seeding default data...'); | ||
await Promise.all([createDefaultUser(), createDefaultProject()]); | ||
await prisma.$disconnect(); | ||
} | ||
|
||
seed() | ||
.catch((e) => console.error('e', e)) | ||
.finally(async () => await prisma.$disconnect()); | ||
|
||
async function createDefaultUser() { | ||
let userList = []; | ||
try { | ||
userList = await prisma.user.findMany(); | ||
console.log(userList); | ||
} | ||
catch (error) { | ||
// Expected to see that "user" table does not exist | ||
console.log(error.message); | ||
} | ||
|
||
const defaultApiKey = '{{ .Values.vrtConfig.defaults.apiKey }}'; | ||
const defaultEmail = '{{ .Values.vrtConfig.defaults.email }}'; | ||
const defaultPassword = '{{ .Values.vrtConfig.defaults.pass }}'; | ||
const salt = await genSalt(10); | ||
|
||
await prisma.user | ||
.upsert({ | ||
where: { | ||
email: defaultEmail, | ||
}, | ||
update: { | ||
role: Role.admin, | ||
}, | ||
create: { | ||
email: defaultEmail, | ||
firstName: 'fname', | ||
lastName: 'lname', | ||
role: Role.admin, | ||
apiKey: defaultApiKey, | ||
password: await hash(defaultPassword, salt), | ||
}, | ||
}) | ||
.then((user) => { | ||
console.log('###########################'); | ||
console.log('####### DEFAULT USER ######'); | ||
console.log('###########################'); | ||
console.log(''); | ||
console.log( | ||
`The user with the email "${defaultEmail}" and password "${defaultPassword}" was created (if not changed before)` | ||
); | ||
console.log(`The Api key is: ${user.apiKey}`); | ||
}); | ||
} | ||
|
||
async function createDefaultProject() { | ||
let projectList = []; | ||
try { | ||
projectList = await prisma.project.findMany(); | ||
console.log(projectList); | ||
} | ||
catch (error) { | ||
// Expected to see that "project" table does not exist | ||
console.log(error.message); | ||
} | ||
|
||
const defaultProject = '{{ .Values.vrtConfig.defaults.project }}'; | ||
|
||
if (projectList.length === 0) { | ||
await prisma.project | ||
.create({ | ||
data: { | ||
name: defaultProject, | ||
}, | ||
}) | ||
.then((project) => { | ||
console.log('##############################'); | ||
console.log('## CREATING DEFAULT PROJECT ##'); | ||
console.log('##############################'); | ||
console.log(''); | ||
console.log(`Project key: ${project.id}`); | ||
console.log(`Project name ${project.name}`); | ||
console.log(`Project name ${project.mainBranchName}`); | ||
}); | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -6,6 +6,11 @@ imagePullSecrets: [] | |
vrtConfig: | ||
appFrontendUrl: "http://localhost:8080" | ||
bodyParserJsonLimit: "5mb" | ||
defaults: | ||
apiKey: "DEFAULT_USER_API_KEY_TO_BE_CHANGED" | ||
email: "[email protected]" | ||
pass: "Change_Me" | ||
project: "Default" | ||
elasticsearch: | ||
host: "" | ||
pass: "" | ||
|
@@ -166,6 +171,10 @@ persistence: | |
annotations: {} | ||
|
||
secrets: | ||
defaults: | ||
useExisting: false | ||
secretName: vrt | ||
secretKey: seed.ts | ||
elasticsearch: | ||
useExisting: false | ||
secretKey: es-pass | ||
|