Browse Source

add datasource and some settings

entities
zarsa 1 year ago
parent
commit
9b7b9e05cc
  1. 19
      db/data-source.ts
  2. 43
      db/migrations/1685871985306-refactoring.ts
  3. 8
      package.json
  4. 15
      src/app.module.ts
  5. 2
      src/entities/point-type.entity.ts

19
db/data-source.ts

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
import { DataSource, DataSourceOptions } from 'typeorm';
export const dataSourceOptions: DataSourceOptions = {
type: 'mssql',
host: '193.176.240.223\\sql2017',
port: 1433,
username: 'sa',
password: 'Zar@Sql2017#1397',
database: 'TirebanClub',
entities: ['dist/**/*.entity{.ts,.js}'],
synchronize: true,
options: {
trustServerCertificate: true,
},
migrations: ['dist/db/migrations/*.js'],
requestTimeout: 300000,
};
const dataSource = new DataSource(dataSourceOptions);
export default dataSource;

43
db/migrations/1685871985306-refactoring.ts

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class Refactoring1685871985306 implements MigrationInterface {
name = 'Refactoring1685871985306';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "group" ("id" int NOT NULL IDENTITY(1,1), "name" nvarchar(255) NOT NULL, CONSTRAINT "PK_256aa0fda9b1de1a73ee0b7106b" PRIMARY KEY ("id"))`,
);
await queryRunner.query(
`CREATE TABLE "person_groups_group" ("personId" int NOT NULL, "groupId" int NOT NULL, CONSTRAINT "PK_2ee7c7f82940eb58121d88a0176" PRIMARY KEY ("personId", "groupId"))`,
);
await queryRunner.query(
`CREATE INDEX "IDX_36e53832ea1beefb3de6cff976" ON "person_groups_group" ("personId") `,
);
await queryRunner.query(
`CREATE INDEX "IDX_267fc87e69a07e823de020a27e" ON "person_groups_group" ("groupId") `,
);
await queryRunner.query(
`ALTER TABLE "person_groups_group" ADD CONSTRAINT "FK_36e53832ea1beefb3de6cff976b" FOREIGN KEY ("personId") REFERENCES "person"("id") ON DELETE CASCADE ON UPDATE CASCADE`,
);
await queryRunner.query(
`ALTER TABLE "person_groups_group" ADD CONSTRAINT "FK_267fc87e69a07e823de020a27e7" FOREIGN KEY ("groupId") REFERENCES "group"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`ALTER TABLE "person_groups_group" DROP CONSTRAINT "FK_267fc87e69a07e823de020a27e7"`,
);
await queryRunner.query(
`ALTER TABLE "person_groups_group" DROP CONSTRAINT "FK_36e53832ea1beefb3de6cff976b"`,
);
await queryRunner.query(
`DROP INDEX "IDX_267fc87e69a07e823de020a27e" ON "person_groups_group"`,
);
await queryRunner.query(
`DROP INDEX "IDX_36e53832ea1beefb3de6cff976" ON "person_groups_group"`,
);
await queryRunner.query(`DROP TABLE "person_groups_group"`);
await queryRunner.query(`DROP TABLE "group"`);
}
}

8
package.json

@ -17,7 +17,13 @@ @@ -17,7 +17,13 @@
"test:watch": "jest --watch",
"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"
"test:e2e": "jest --config ./test/jest-e2e.json",
"typeorm": "npm run build && npx typeorm -d dist/db/data-source.js",
"m:g": "npm run build && npx typeorm migration:generate ./db/migrations/refactoring -d dist/db/data-source.js",
"m:r": "npm run typeorm -- migration:run",
"migration:revert": "npm run typeorm -- migration:revert"
},
"dependencies": {
"@nestjs/common": "^9.0.0",

15
src/app.module.ts

@ -5,22 +5,11 @@ import { TypeOrmModule } from '@nestjs/typeorm'; @@ -5,22 +5,11 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { UsersModule } from './users/users.module';
import { PersonsModule } from './persons/persons.module';
import { GroupsModule } from './groups/groups.module';
import { dataSourceOptions } from 'db/data-source';
@Module({
imports: [
TypeOrmModule.forRoot({
type: 'mssql',
host: '193.176.240.223\\sql2017',
port: 1433,
username: 'sa',
password: 'Zar@Sql2017#1397',
database: 'TirebanClub',
entities: ['dist/**/*.entity{.ts,.js}'],
synchronize: true,
options: {
trustServerCertificate: true,
},
}),
TypeOrmModule.forRoot(dataSourceOptions),
UsersModule,
PersonsModule,
GroupsModule,

2
src/entities/point-type.entity.ts

@ -4,6 +4,6 @@ import { Column, Entity, PrimaryColumn } from 'typeorm'; @@ -4,6 +4,6 @@ import { Column, Entity, PrimaryColumn } from 'typeorm';
export class PointType {
@PrimaryColumn()
code: number;
@Column({ length: 25, type: 'nvarchar' })
@Column({ length: 50, type: 'nvarchar' })
name: string;
}

Loading…
Cancel
Save