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

timgit / pg-boss / 10192012457

01 Aug 2024 04:27AM UTC coverage: 93.023% (-7.0%) from 100.0%
10192012457

Pull #425

github

web-flow
Merge de00c1a19 into f1c1636ca
Pull Request #425: v10

453 of 535 branches covered (84.67%)

381 of 407 new or added lines in 10 files covered. (93.61%)

40 existing lines in 5 files now uncovered.

880 of 946 relevant lines covered (93.02%)

877.69 hits per line

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

58.54
/src/contractor.js
1
const assert = require('assert')
4✔
2
const plans = require('./plans')
4✔
3
const { DEFAULT_SCHEMA } = plans
4✔
4
const migrationStore = require('./migrationStore')
4✔
5
const schemaVersion = require('../version.json').schema
4✔
6

7
class Contractor {
8
  static constructionPlans (schema = DEFAULT_SCHEMA) {
×
9
    return plans.create(schema, schemaVersion)
1✔
10
  }
11

12
  static migrationPlans (schema = DEFAULT_SCHEMA, version = schemaVersion - 1) {
×
UNCOV
13
    return migrationStore.migrate(schema, version)
×
14
  }
15

16
  static rollbackPlans (schema = DEFAULT_SCHEMA, version = schemaVersion) {
×
UNCOV
17
    return migrationStore.rollback(schema, version)
×
18
  }
19

20
  constructor (db, config) {
21
    this.config = config
183✔
22
    this.db = db
183✔
23
    this.migrations = this.config.migrations || migrationStore.getAll(this.config.schema)
183✔
24

25
    // exported api to index
26
    this.functions = [
183✔
27
      this.schemaVersion,
28
      this.isInstalled
29
    ]
30
  }
31

32
  async schemaVersion () {
33
    const result = await this.db.executeSql(plans.getVersion(this.config.schema))
4✔
34
    return result.rows.length ? parseInt(result.rows[0].version) : null
4!
35
  }
36

37
  async isInstalled () {
38
    const result = await this.db.executeSql(plans.versionTableExists(this.config.schema))
183✔
39
    return !!result.rows[0].name
182✔
40
  }
41

42
  async start () {
43
    const installed = await this.isInstalled()
183✔
44

45
    if (installed) {
182✔
46
      const version = await this.schemaVersion()
4✔
47

48
      if (schemaVersion > version) {
4!
NEW
49
        throw new Error('Migrations are not supported to v10')
×
50
        // await this.migrate(version)
51
      }
52
    } else {
53
      await this.create()
178✔
54
    }
55
  }
56

57
  async check () {
NEW
58
    const installed = await this.isInstalled()
×
59

NEW
60
    if (!installed) {
×
NEW
61
      throw new Error('pg-boss is not installed')
×
62
    }
63

NEW
64
    const version = await this.schemaVersion()
×
65

NEW
66
    if (schemaVersion !== version) {
×
NEW
67
      throw new Error('pg-boss database requires migrations')
×
68
    }
69
  }
70

71
  async create () {
72
    try {
178✔
73
      const commands = plans.create(this.config.schema, schemaVersion)
178✔
74
      await this.db.executeSql(commands)
178✔
75
    } catch (err) {
76
      assert(err.message.includes(plans.CREATE_RACE_MESSAGE), err)
19✔
77
    }
78
  }
79

80
  async migrate (version) {
UNCOV
81
    try {
×
UNCOV
82
      const commands = migrationStore.migrate(this.config, version, this.migrations)
×
UNCOV
83
      await this.db.executeSql(commands)
×
84
    } catch (err) {
UNCOV
85
      assert(err.message.includes(plans.MIGRATE_RACE_MESSAGE), err)
×
86
    }
87
  }
88

89
  async next (version) {
UNCOV
90
    const commands = migrationStore.next(this.config.schema, version, this.migrations)
×
UNCOV
91
    await this.db.executeSql(commands)
×
92
  }
93

94
  async rollback (version) {
UNCOV
95
    const commands = migrationStore.rollback(this.config.schema, version, this.migrations)
×
UNCOV
96
    await this.db.executeSql(commands)
×
97
  }
98
}
99

100
module.exports = Contractor
4✔
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