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

safe-global / safe-client-gateway / 7959999835

19 Feb 2024 01:04PM CUT coverage: 93.953% (+0.02%) from 93.936%
7959999835

Pull #1154

github

iamacook
Remove checksum from cache router
Pull Request #1154: Throw custom errors from relayer

1643 of 1954 branches covered (84.08%)

Branch coverage included in aggregate %.

46 of 46 new or added lines in 10 files covered. (100.0%)

3 existing lines in 2 files now uncovered.

6141 of 6331 relevant lines covered (97.0%)

193.77 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';
80✔
2
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
80✔
3
import * as shift from 'postgres-shift';
80✔
4
import postgres from 'postgres';
80✔
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 {
80✔
15
  private static LOCK_MAGIC_NUMBER = 132;
80✔
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