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

safe-global / safe-client-gateway / 8418527215

22 Mar 2024 02:13PM UTC coverage: 93.322% (+0.003%) from 93.319%
8418527215

push

github

web-flow
Migrate `Message`/`MessageConfirmation` to `zod` (#1315)

This migrates the validation of `Message` to `zod`:

- Remove `MessageValidator` and associated schemas.
- Add test-covered `MessageSchema`/`MessageConfirmationSchema` and infer types from them.
- Propagate type requirements.
- Update tests accordingly.

1849 of 2228 branches covered (82.99%)

Branch coverage included in aggregate %.

17 of 17 new or added lines in 6 files covered. (100.0%)

6480 of 6697 relevant lines covered (96.76%)

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