diff --git a/src/crags/entities/crag.entity.ts b/src/crags/entities/crag.entity.ts index f4e8725..bfc7ca7 100644 --- a/src/crags/entities/crag.entity.ts +++ b/src/crags/entities/crag.entity.ts @@ -174,7 +174,11 @@ export class Crag extends BaseEntity { @Column({ name: 'user_id', nullable: true }) userId: string; - @Column({ type: 'int', array: true, nullable: true }) - @Field(() => [Int], { nullable: true }) + @Column({ + type: 'int', + array: true, + default: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], + }) + @Field(() => [Int]) activityByMonth: number[]; } diff --git a/src/migration/1696588233248-activityByMonthNonNullable.ts b/src/migration/1696588233248-activityByMonthNonNullable.ts new file mode 100644 index 0000000..022039e --- /dev/null +++ b/src/migration/1696588233248-activityByMonthNonNullable.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner } from 'typeorm'; + +export class activityByMonthNonNullable1696588233248 + implements MigrationInterface +{ + name = 'activityByMonthNonNullable1696588233248'; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "crag" ALTER COLUMN "activity_by_month" SET NOT NULL`, + ); + await queryRunner.query( + `ALTER TABLE "crag" ALTER COLUMN "activity_by_month" SET DEFAULT '{0,0,0,0,0,0,0,0,0,0,0,0}'`, + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query( + `ALTER TABLE "crag" ALTER COLUMN "activity_by_month" DROP DEFAULT`, + ); + await queryRunner.query( + `ALTER TABLE "crag" ALTER COLUMN "activity_by_month" DROP NOT NULL`, + ); + } +} diff --git a/test/e2e/helpers.ts b/test/e2e/helpers.ts index 42bbbcc..fdaf2df 100644 --- a/test/e2e/helpers.ts +++ b/test/e2e/helpers.ts @@ -378,28 +378,28 @@ const seedDatabase = async (qr: QueryRunner, app) => { // Add some crags // published crag await qr.query( - `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id) - VALUES ('${mockData.crags.publishedCrag.id}', 'Kot Tečnik', '${mockData.crags.publishedCrag.slug}', '${mockData.countries.slovenia.id}', 'french', 'sport', 'published', false, '${mockData.users.basicUser1.id}')`, + `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id, activity_by_month) + VALUES ('${mockData.crags.publishedCrag.id}', 'Kot Tečnik', '${mockData.crags.publishedCrag.slug}', '${mockData.countries.slovenia.id}', 'french', 'sport', 'published', false, '${mockData.users.basicUser1.id}', '{0,0,0,0,0,0,0,0,0,0,0,0}')`, ); // in review crag await qr.query( - `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id) - VALUES ('${mockData.crags.inReviewCrag.id}', 'Podstenčnik', 'podstencnik', '${mockData.countries.slovenia.id}', 'french', 'sport', 'in_review', false, '${mockData.users.basicUser1.id}')`, + `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id, activity_by_month) + VALUES ('${mockData.crags.inReviewCrag.id}', 'Podstenčnik', 'podstencnik', '${mockData.countries.slovenia.id}', 'french', 'sport', 'in_review', false, '${mockData.users.basicUser1.id}', '{0,0,0,0,0,0,0,0,0,0,0,0}')`, ); // draft crag await qr.query( - `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id) - VALUES ('${mockData.crags.draftCrag.id}', 'Nova grapa', 'nova-grapa', '${mockData.countries.slovenia.id}', 'french', 'sport', 'draft', false, '${mockData.users.basicUser1.id}')`, + `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id, activity_by_month) + VALUES ('${mockData.crags.draftCrag.id}', 'Nova grapa', 'nova-grapa', '${mockData.countries.slovenia.id}', 'french', 'sport', 'draft', false, '${mockData.users.basicUser1.id}', '{0,0,0,0,0,0,0,0,0,0,0,0}')`, ); // crag with multiple sectors await qr.query( - `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id) - VALUES ('${mockData.crags.cragWithMultipleSectors.id}', 'Cre tata', '${mockData.crags.cragWithMultipleSectors.slug}', '${mockData.countries.slovenia.id}', 'french', 'sport', 'published', false, '${mockData.users.basicUser1.id}')`, + `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id, activity_by_month) + VALUES ('${mockData.crags.cragWithMultipleSectors.id}', 'Cre tata', '${mockData.crags.cragWithMultipleSectors.slug}', '${mockData.countries.slovenia.id}', 'french', 'sport', 'published', false, '${mockData.users.basicUser1.id}', '{0,0,0,0,0,0,0,0,0,0,0,0}')`, ); // simple crag await qr.query( - `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id) - VALUES ('${mockData.crags.simpleCrag.id}', 'Cragus simplus', '${mockData.crags.simpleCrag.slug}', '${mockData.countries.slovenia.id}', 'french', 'sport', 'published', false, '${mockData.users.basicUser1.id}')`, + `INSERT INTO crag (id, name, slug, country_id, default_grading_system_id, type, publish_status, is_hidden, user_id, activity_by_month) + VALUES ('${mockData.crags.simpleCrag.id}', 'Cragus simplus', '${mockData.crags.simpleCrag.slug}', '${mockData.countries.slovenia.id}', 'french', 'sport', 'published', false, '${mockData.users.basicUser1.id}', '{0,0,0,0,0,0,0,0,0,0,0,0}')`, ); // Add some sectors