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

safe-global / safe-client-gateway / 7085686543

04 Dec 2023 11:06AM UTC coverage: 89.935% (+0.2%) from 89.734%
7085686543

Pull #895

github

fmrsabino
Add test for unknown recovery transaction
Pull Request #895: Add test for unknown recovery transaction attempt

1412 of 1701 branches covered (0.0%)

Branch coverage included in aggregate %.

45 of 47 new or added lines in 11 files covered. (95.74%)

23 existing lines in 6 files now uncovered.

5272 of 5731 relevant lines covered (91.99%)

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

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

22
  async onModuleInit() {
UNCOV
23
    this.loggingService.info('Checking migrations');
×
UNCOV
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.
UNCOV
29
      await this
×
30
        .sql`SELECT pg_advisory_lock(${PostgresDatabaseMigrationHook.LOCK_MAGIC_NUMBER})`;
31
      // Perform migration
UNCOV
32
      await shift({ sql: this.sql });
×
UNCOV
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)
UNCOV
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

© 2026 Coveralls, Inc