Skip to content

Commit

Permalink
Merge pull request #166 from plezanje-net/fix/crag-entity-activity-by…
Browse files Browse the repository at this point in the history
…-month

Make activityByMonth field of crag entity non nullable.
  • Loading branch information
demshy authored Oct 7, 2023
2 parents 7e368b6 + 4ea1e5b commit be2ea3d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
8 changes: 6 additions & 2 deletions src/crags/entities/crag.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
25 changes: 25 additions & 0 deletions src/migration/1696588233248-activityByMonthNonNullable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { MigrationInterface, QueryRunner } from 'typeorm';

export class activityByMonthNonNullable1696588233248
implements MigrationInterface
{
name = 'activityByMonthNonNullable1696588233248';

public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
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`,
);
}
}
20 changes: 10 additions & 10 deletions test/e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be2ea3d

Please sign in to comment.