Skip to content

Commit 6e94694

Browse files
migrations
1 parent d124264 commit 6e94694

File tree

6 files changed

+124
-98
lines changed

6 files changed

+124
-98
lines changed

package.json

Lines changed: 79 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,81 @@
11
{
2-
"name": "team-code",
3-
"version": "0.0.1",
4-
"description": "",
5-
"author": "",
6-
"private": true,
7-
"license": "UNLICENSED",
8-
"scripts": {
9-
"prebuild": "rimraf dist",
10-
"build": "nest build",
11-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
12-
"start": "nest start",
13-
"start:dev": "nest start --watch",
14-
"start:debug": "nest start --debug --watch",
15-
"start:prod": "node dist/main",
16-
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
17-
"test": "jest",
18-
"test:watch": "jest --watch",
19-
"test:cov": "jest --coverage",
20-
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
21-
"test:e2e": "jest --config ./test/jest-e2e.json"
22-
},
23-
"dependencies": {
24-
"@nestjs/common": "^7.6.15",
25-
"@nestjs/config": "^0.6.3",
26-
"@nestjs/core": "^7.6.15",
27-
"@nestjs/platform-express": "^7.6.15",
28-
"@nestjs/typeorm": "^7.1.5",
29-
"dotenv": "^10.0.0",
30-
"pg": "^8.6.0",
31-
"reflect-metadata": "^0.1.13",
32-
"rimraf": "^3.0.2",
33-
"rxjs": "^6.6.6",
34-
"typeorm": "^0.2.34"
35-
},
36-
"devDependencies": {
37-
"@nestjs/cli": "^7.6.0",
38-
"@nestjs/schematics": "^7.3.0",
39-
"@nestjs/testing": "^7.6.15",
40-
"@types/express": "^4.17.11",
41-
"@types/jest": "^26.0.22",
42-
"@types/node": "^14.14.36",
43-
"@types/pg": "^8.6.0",
44-
"@types/supertest": "^2.0.10",
45-
"@typescript-eslint/eslint-plugin": "^4.19.0",
46-
"@typescript-eslint/parser": "^4.19.0",
47-
"eslint": "^7.22.0",
48-
"eslint-config-prettier": "^8.1.0",
49-
"eslint-plugin-prettier": "^3.3.1",
50-
"jest": "^26.6.3",
51-
"prettier": "^2.2.1",
52-
"supertest": "^6.1.3",
53-
"ts-jest": "^26.5.4",
54-
"ts-loader": "^8.0.18",
55-
"ts-node": "^9.1.1",
56-
"tsconfig-paths": "^3.9.0",
57-
"typescript": "^4.2.3"
58-
},
59-
"jest": {
60-
"moduleFileExtensions": [
61-
"js",
62-
"json",
63-
"ts"
64-
],
65-
"rootDir": "src",
66-
"testRegex": ".*\\.spec\\.ts$",
67-
"transform": {
68-
"^.+\\.(t|j)s$": "ts-jest"
2+
"name": "team-code",
3+
"version": "0.0.1",
4+
"description": "",
5+
"author": "",
6+
"private": true,
7+
"license": "UNLICENSED",
8+
"scripts": {
9+
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
10+
"migrations:generate": "npm run typeorm -- migration:generate -n",
11+
"migrations:run": "npm run typeorm -- migration:run",
12+
"migrations:show": "npm run typeorm -- migration:show",
13+
14+
"prebuild": "rimraf dist",
15+
"build": "nest build",
16+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
17+
"start": "nest start",
18+
"start:dev": "nest start --watch",
19+
"start:debug": "nest start --debug --watch",
20+
"start:prod": "node dist/main",
21+
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
22+
"test": "jest",
23+
"test:watch": "jest --watch",
24+
"test:cov": "jest --coverage",
25+
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
26+
"test:e2e": "jest --config ./test/jest-e2e.json"
6927
},
70-
"collectCoverageFrom": [
71-
"**/*.(t|j)s"
72-
],
73-
"coverageDirectory": "../coverage",
74-
"testEnvironment": "node"
75-
}
76-
}
28+
"dependencies": {
29+
"@nestjs/common": "^7.6.15",
30+
"@nestjs/config": "^0.6.3",
31+
"@nestjs/core": "^7.6.15",
32+
"@nestjs/platform-express": "^7.6.15",
33+
"@nestjs/typeorm": "^7.1.5",
34+
"dotenv": "^10.0.0",
35+
"pg": "^8.6.0",
36+
"reflect-metadata": "^0.1.13",
37+
"rimraf": "^3.0.2",
38+
"rxjs": "^6.6.6",
39+
"typeorm": "^0.2.34"
40+
},
41+
"devDependencies": {
42+
"@nestjs/cli": "^7.6.0",
43+
"@nestjs/schematics": "^7.3.0",
44+
"@nestjs/testing": "^7.6.15",
45+
"@types/express": "^4.17.11",
46+
"@types/jest": "^26.0.22",
47+
"@types/node": "^14.14.36",
48+
"@types/pg": "^8.6.0",
49+
"@types/supertest": "^2.0.10",
50+
"@typescript-eslint/eslint-plugin": "^4.19.0",
51+
"@typescript-eslint/parser": "^4.19.0",
52+
"eslint": "^7.22.0",
53+
"eslint-config-prettier": "^8.1.0",
54+
"eslint-plugin-prettier": "^3.3.1",
55+
"jest": "^26.6.3",
56+
"prettier": "^2.2.1",
57+
"supertest": "^6.1.3",
58+
"ts-jest": "^26.5.4",
59+
"ts-loader": "^8.0.18",
60+
"ts-node": "^9.1.1",
61+
"tsconfig-paths": "^3.9.0",
62+
"typescript": "^4.2.3"
63+
},
64+
"jest": {
65+
"moduleFileExtensions": [
66+
"js",
67+
"json",
68+
"ts"
69+
],
70+
"rootDir": "src",
71+
"testRegex": ".*\\.spec\\.ts$",
72+
"transform": {
73+
"^.+\\.(t|j)s$": "ts-jest"
74+
},
75+
"collectCoverageFrom": [
76+
"**/*.(t|j)s"
77+
],
78+
"coverageDirectory": "../coverage",
79+
"testEnvironment": "node"
80+
}
81+
}

src/entities/project.entity.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { PrimaryGeneratedColumn, Column, Entity } from 'typeorm';
1+
import {
2+
PrimaryGeneratedColumn,
3+
Column,
4+
Entity,
5+
CreateDateColumn,
6+
UpdateDateColumn
7+
} from 'typeorm';
28

39
@Entity()
410
export class Project {
@@ -13,4 +19,10 @@ export class Project {
1319

1420
@Column({ type: 'varchar' })
1521
location: string;
22+
23+
@CreateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
24+
creationDate: string;
25+
26+
@UpdateDateColumn({ type: 'timestamptz', default: () => 'CURRENT_TIMESTAMP' })
27+
upadatenDate: string;
1628
}

src/migrations/1623610521160-init.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {MigrationInterface, QueryRunner} from "typeorm";
2+
3+
export class init1623610521160 implements MigrationInterface {
4+
name = 'init1623610521160'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`CREATE TABLE "project" ("id" SERIAL NOT NULL, "name" character varying(255) NOT NULL, "description" text NOT NULL, "location" character varying NOT NULL, CONSTRAINT "UQ_dedfea394088ed136ddadeee89c" UNIQUE ("name"), CONSTRAINT "PK_4d68b1358bb5b766d3e78f32f57" PRIMARY KEY ("id"))`);
8+
}
9+
10+
public async down(queryRunner: QueryRunner): Promise<void> {
11+
await queryRunner.query(`DROP TABLE "project"`);
12+
}
13+
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {MigrationInterface, QueryRunner} from "typeorm";
2+
3+
export class someDates1623611219385 implements MigrationInterface {
4+
name = 'someDates1623611219385'
5+
6+
public async up(queryRunner: QueryRunner): Promise<void> {
7+
await queryRunner.query(`ALTER TABLE "project" ADD "creationDate" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`);
8+
await queryRunner.query(`ALTER TABLE "project" ADD "upadatenDate" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now()`);
9+
}
10+
11+
public async down(queryRunner: QueryRunner): Promise<void> {
12+
await queryRunner.query(`ALTER TABLE "project" DROP COLUMN "upadatenDate"`);
13+
await queryRunner.query(`ALTER TABLE "project" DROP COLUMN "creationDate"`);
14+
}
15+
16+
}

src/modules/database/database.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ client.connect();*/
2020
username,
2121
password,
2222
database,
23-
synchronize: true,
23+
synchronize: false,
2424
autoLoadEntities: true,
2525
}
2626
}

src/services/database/database.service.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, Inject, NotFoundException } from '@nestjs/common';
22
import { Client } from 'pg';
33
import { InjectRepository } from '@nestjs/typeorm';
4-
import { Repository } from 'typeorm'; // 👈 import
4+
import { Repository } from 'typeorm';
55

66
import { Project } from './../../entities/project.entity';
77
@Injectable()
@@ -12,27 +12,6 @@ export class DatabaseService {
1212
) {
1313
//this.clientPg.query("SELECT * FROM projects")
1414
}
15-
db = {
16-
projects: {
17-
"0": {
18-
name: "project1",
19-
year: 2020
20-
},
21-
"1": {
22-
name: "project2",
23-
year: 2020
24-
},
25-
"2": {
26-
name: "project3",
27-
year: 2021
28-
},
29-
},
30-
languages: {
31-
"0": "python",
32-
"1": "javascript",
33-
"2": "rust"
34-
}
35-
}
3615
async createProject(name: string, description: string, location: string): Promise<object> {
3716
let poject = this.projectRepo.create({ name, description, location })
3817
await this.projectRepo.save(poject)

0 commit comments

Comments
 (0)