Improvements for migrations

This commit is contained in:
navaneeth 2021-07-09 16:22:03 +05:30
parent 1a6e53fcf1
commit 0041201f8a
7 changed files with 27 additions and 14 deletions

View file

@ -47,12 +47,14 @@ export class CreateUsers1625814801417 implements MigrationInterface {
{
name: "created_at",
type: "timestamp",
isNullable: true
isNullable: true,
default: "now()"
},
{
name: "updated_at",
type: "timestamp",
isNullable: true
isNullable: true,
default: "now()"
}
]
}), true)

View file

@ -1,4 +1,3 @@
import { User } from "./src/users/user.entity";
module.exports = {
type: 'postgres',
@ -9,7 +8,6 @@ module.exports = {
database: process.env.PG_DB,
synchronize: false,
logging: true,
entities: [User],
migrations: ["migrations/*.ts"],
cli: {
migrationsDir: "migrations"

View file

@ -19,7 +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",
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
"typeorm": "node --require ts-node/register ./node_modules/typeorm/cli.js"
},
"dependencies": {
"@nestjs/common": "^8.0.0",

View file

@ -6,7 +6,7 @@ import { AuthService } from './auth/auth.service';
export class AppController {
constructor(private authService: AuthService) {}
@Post('auth/login')
@Post('authenticate')
async login(@Request() req) {
return this.authService.login(req.body);
}

View file

@ -4,12 +4,22 @@ import { AppService } from './app.service';
import { AuthModule } from './auth/auth.module';
import { UsersModule } from './users/users.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Connection } from 'typeorm';
import { Connection, getConnectionOptions } from 'typeorm';
import { User } from './users/user.entity';
@Module({
imports: [
TypeOrmModule.forRoot(),
TypeOrmModule.forRoot({
type: 'postgres',
host: process.env.PG_HOST,
port: parseInt(process.env.PG_PORT) || 5432,
username: process.env.PG_USER,
password: process.env.PG_PASS,
database: process.env.PG_DB,
entities: ["dist/**/*.entity{ .ts,.js}"],
synchronize: false,
logging: true
}),
AuthModule,
UsersModule
],

View file

@ -2,7 +2,10 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await NestFactory.create(AppModule, {
logger: ['error', 'log', 'verbose'],
});
app.enableCors();
await app.listen(3000);
}
bootstrap();

View file

@ -1,4 +1,4 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn, UpdateDateColumn } from 'typeorm';
@Entity({ name: "users" })
export class User {
@ -17,10 +17,10 @@ export class User {
@Column({ name: 'password_digest' })
passwordDigest: string
@Column({ type: 'timestamp', name: 'created_at', default: () => 'LOCALTIMESTAMP' })
createDate: string;
@CreateDateColumn({ default: () => 'now()', name: 'created_at' })
createAt: Date;
@Column({ type: 'timestamp', name: 'updated_at', default: () => 'LOCALTIMESTAMP' })
updateDate: string;
@UpdateDateColumn({ default: () => 'now()', name: 'updated_at' })
updateAt: Date;
}