add migration
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
2025-12-31 09:55:01 +03:00
parent 85c4a36e17
commit 765fd6ad66
5 changed files with 65 additions and 2 deletions

View File

@ -19,7 +19,11 @@
"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",
"clean": "rm -rf dist node_modules"
"clean": "rm -rf dist node_modules",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js -d src/data-source.ts",
"migration:generate": "npm run typeorm -- migration:generate",
"migration:run": "npm run typeorm -- migration:run",
"migration:revert": "npm run typeorm -- migration:revert"
},
"dependencies": {
"@nestjs/common": "^11.0.1",
@ -30,6 +34,7 @@
"@nestjs/typeorm": "^11.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.3",
"dotenv": "^16.4.7",
"pg": "^8.16.3",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",

View File

@ -21,7 +21,9 @@ import { IdeasModule } from './ideas/ideas.module';
password: configService.get('DB_PASSWORD', 'teamplanner'),
database: configService.get('DB_DATABASE', 'teamplanner'),
entities: [__dirname + '/**/*.entity{.ts,.js}'],
synchronize: true, // Only for development!
migrations: [__dirname + '/migrations/*{.ts,.js}'],
migrationsRun: true,
synchronize: false,
}),
}),
IdeasModule,

View File

@ -0,0 +1,16 @@
import { DataSource } from 'typeorm';
import { config } from 'dotenv';
config();
export const AppDataSource = new DataSource({
type: 'postgres',
host: process.env.DB_HOST ?? 'localhost',
port: parseInt(process.env.DB_PORT ?? '5432', 10),
username: process.env.DB_USERNAME ?? 'teamplanner',
password: process.env.DB_PASSWORD ?? 'teamplanner',
database: process.env.DB_DATABASE ?? 'teamplanner',
entities: [__dirname + '/**/*.entity{.ts,.js}'],
migrations: [__dirname + '/migrations/*{.ts,.js}'],
synchronize: false,
});

View File

@ -0,0 +1,39 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class InitialMigration1735660800000 implements MigrationInterface {
name = 'InitialMigration1735660800000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TYPE "public"."ideas_status_enum" AS ENUM('backlog', 'todo', 'in_progress', 'done', 'cancelled')`,
);
await queryRunner.query(
`CREATE TYPE "public"."ideas_priority_enum" AS ENUM('low', 'medium', 'high', 'critical')`,
);
await queryRunner.query(`
CREATE TABLE "ideas" (
"id" uuid NOT NULL DEFAULT uuid_generate_v4(),
"title" character varying NOT NULL,
"description" text,
"status" "public"."ideas_status_enum" NOT NULL DEFAULT 'backlog',
"priority" "public"."ideas_priority_enum" NOT NULL DEFAULT 'medium',
"module" character varying(100),
"target_audience" character varying(255),
"pain" text,
"ai_role" text,
"verification_method" text,
"color" character varying(20),
"order" integer NOT NULL DEFAULT '0',
"created_at" TIMESTAMP NOT NULL DEFAULT now(),
"updated_at" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "PK_ideas_id" PRIMARY KEY ("id")
)
`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "ideas"`);
await queryRunner.query(`DROP TYPE "public"."ideas_priority_enum"`);
await queryRunner.query(`DROP TYPE "public"."ideas_status_enum"`);
}
}

1
package-lock.json generated
View File

@ -31,6 +31,7 @@
"@nestjs/typeorm": "^11.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.3",
"dotenv": "^16.4.7",
"pg": "^8.16.3",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",