• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway / 8080543737

28 Feb 2024 12:42PM CUT coverage: 93.642% (-0.06%) from 93.699%
8080543737

Pull #1215

github

hectorgomezv
Add min to random values of CacheHooksController tests
Pull Request #1215: Align FakeCacheService and RedisCacheService implementations

1676 of 2005 branches covered (83.59%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

2 existing lines in 1 file now uncovered.

6145 of 6347 relevant lines covered (96.82%)

347.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.5
/src/datasources/db/postgres-database.migration.hook.ts
1
import { Inject, Injectable, OnModuleInit } from '@nestjs/common';
82✔
2
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
82✔
3
import * as shift from 'postgres-shift';
82✔
4
import postgres from 'postgres';
82✔
5

6
/**
7
 * The {@link PostgresDatabaseMigrationHook} is a Module Init hook meaning
8
 * that it will be executed once the dependencies are resolved.
9
 *
10
 * This happens before the Application Bootstraps, so route listeners are not
11
 * initiated and potentially generating queries.
12
 */
13
@Injectable({})
14
export class PostgresDatabaseMigrationHook implements OnModuleInit {
82✔
15
  private static LOCK_MAGIC_NUMBER = 132;
82✔
16

17
  constructor(
18
    @Inject('DB_INSTANCE') private readonly sql: postgres.Sql,
×
19
    @Inject(LoggingService) private readonly loggingService: ILoggingService,
×
20
  ) {}
21

22
  async onModuleInit(): Promise<void> {
23
    this.loggingService.info('Checking migrations');
×
24
    try {
×
25
      // Acquire lock to perform a migration.
26
      // If the lock is not acquired, then a migration is being executed by another instance.
27
      // Migrations should strive to be idempotent as they can be executed by multiple instances
28
      // on the same database.
29
      await this
×
30
        .sql`SELECT pg_advisory_lock(${PostgresDatabaseMigrationHook.LOCK_MAGIC_NUMBER})`;
31
      // Perform migration
32
      await shift({ sql: this.sql });
×
33
      this.loggingService.info('Pending migrations executed');
×
34
    } catch (e) {
35
      // If there's an error performing a migration, we should throw the error
36
      // and prevent the service from starting
37
      this.loggingService.error(e);
×
38
      throw e;
×
39
    } finally {
40
      // the lock should be released if the migration completed (successfully or not)
41
      await this
×
42
        .sql`SELECT pg_advisory_unlock(${PostgresDatabaseMigrationHook.LOCK_MAGIC_NUMBER})`;
43
    }
44
  }
45
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc