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
14 changes: 7 additions & 7 deletions package-lock.json

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

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vrt-backend",
"version": "1.0.0",
"version": "1.1.0",
"description": "",
"author": "",
"private": true,
Expand All @@ -19,8 +19,7 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"docker:build_api": "npm run test && npm run test:e2e && docker build -t visualregressiontracker/api:$npm_package_version -f ./Dockerfile . && docker push visualregressiontracker/api:$npm_package_version",
"docker:build_migration": "docker build -t visualregressiontracker/migration:1.0.0 -f ./prisma/Dockerfile ./prisma"
"docker:build_api": "npm run test && npm run test:e2e && docker build -t visualregressiontracker/api:$npm_package_version -f ./Dockerfile . && docker push visualregressiontracker/api:$npm_package_version"
},
"dependencies": {
"@nestjs/common": "^7.0.0",
Expand All @@ -30,7 +29,7 @@
"@nestjs/passport": "^7.0.0",
"@nestjs/platform-express": "^7.0.0",
"@nestjs/swagger": "^4.5.1",
"@prisma/client": "^2.0.0-beta.5",
"@prisma/client": "^2.0.0-beta.6",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.2.3",
"class-validator": "^0.11.1",
Expand All @@ -52,7 +51,7 @@
"@nestjs/cli": "^7.0.0",
"@nestjs/schematics": "^7.0.0",
"@nestjs/testing": "^7.0.0",
"@prisma/cli": "^2.0.0-beta.5",
"@prisma/cli": "^2.0.0-beta.6",
"@types/bcryptjs": "^2.4.2",
"@types/express": "^4.17.3",
"@types/jest": "25.1.4",
Expand Down
1 change: 1 addition & 0 deletions prisma/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules
36 changes: 36 additions & 0 deletions prisma/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

/imageUploads
15 changes: 9 additions & 6 deletions prisma/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
FROM node:12-alpine

# Install @prisma/cli for the migration
RUN npm install -g @prisma/cli --unsafe-perm
WORKDIR /app

# Copy schema and migration folder
COPY schema.prisma /schema.prisma
COPY migrations/ /migrations/
COPY . .

CMD [ "prisma", "migrate", "up", "-c", "--experimental"]
RUN npm ci

RUN chmod +x /app/entrypoint.sh

ENTRYPOINT ["/app/entrypoint.sh"]

CMD ["sh"]
12 changes: 12 additions & 0 deletions prisma/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
set -e

echo Start applying migrations...

# apply migration
npx prisma migrate up -c --experimental

echo Seeding data...

# seed data
npx ts-node seed.ts
132 changes: 132 additions & 0 deletions prisma/package-lock.json

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

23 changes: 23 additions & 0 deletions prisma/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "vrt-migration",
"version": "1.1.0",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"docker:build_migration": "docker build -t visualregressiontracker/migration:$npm_package_version -f ./Dockerfile ."
},
"dependencies": {
"@prisma/client": "^2.0.0-beta.6",
"bcryptjs": "^2.4.3",
"uuid-apikey": "^1.4.6"
},
"devDependencies": {
"ts-node": "^8.8.2",
"@prisma/cli": "^2.0.0-beta.6",
"@types/bcryptjs": "^2.4.2",
"@types/uuid-apikey": "^1.4.0",
"typescript": "^3.7.4"
}
}
67 changes: 67 additions & 0 deletions prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { PrismaClient } from '@prisma/client';
import uuidAPIKey from 'uuid-apikey';
import { genSalt, hash } from 'bcryptjs';

const prisma = new PrismaClient({
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() {
const userList = await prisma.user.findMany();
console.log(userList);
if (userList.length === 0) {
const defaultEmail = 'visual-regression-tracker1@example.com';
const defaultPassword = '123456';
const salt = await genSalt(10);
await prisma.user
.create({
data: {
email: defaultEmail,
firstName: 'fname',
lastName: 'lname',
apiKey: uuidAPIKey.create({ noDashes: true }).apiKey,
password: await hash(defaultPassword, salt),
},
})
.then((user) => {
console.log('###########################');
console.log('## CREATING DEFAULT USER ##');
console.log('###########################');
console.log('');
console.log(`The user with the email "${defaultEmail}" and password "${defaultPassword}" was created`);
console.log(`The Api key is: ${user.apiKey}`);
});
}
}

async function createDefaultProject() {
const projectList = await prisma.project.findMany();
console.log(projectList);
if (projectList.length === 0) {
await prisma.project
.create({
data: {
name: 'Default project',
},
})
.then((project) => {
console.log('##############################');
console.log('## CREATING DEFAULT PROJECT ##');
console.log('##############################');
console.log('');
console.log(`Project name ${project.name}`);
console.log(`Project key: ${project.id}`);
});
}
}
17 changes: 17 additions & 0 deletions prisma/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es2018",
"sourceMap": true,
"baseUrl": "./",
"incremental": true,
"skipLibCheck": true,
"esModuleInterop": true
},
"exclude": ["node_modules"]
}

Loading