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

u-wave / core / 11980840475

22 Nov 2024 10:04PM UTC coverage: 78.492% (-1.7%) from 80.158%
11980840475

Pull #637

github

goto-bus-stop
ci: add node 22
Pull Request #637: Switch to a relational database

757 of 912 branches covered (83.0%)

Branch coverage included in aggregate %.

2001 of 2791 new or added lines in 52 files covered. (71.69%)

9 existing lines in 7 files now uncovered.

8666 of 11093 relevant lines covered (78.12%)

70.72 hits per line

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

90.32
/src/plugins/migrations.js
1
import { fileURLToPath } from 'node:url';
1✔
2
import RedLock from 'redlock';
1✔
3
import { Umzug } from 'umzug';
1✔
4

1✔
5
/**
1✔
6
 * @typedef {import('../Uwave.js').default} Uwave
1✔
7
 */
1✔
8

1✔
9
const kyselyStorage = {
1✔
10
  /**
1✔
11
   * @param {import('umzug').MigrationParams<Uwave>} params
1✔
12
   */
1✔
13
  async logMigration({ name, context: uw }) {
1✔
14
    const { db } = uw;
276✔
15

276✔
16
    await db.insertInto('migrations')
276✔
17
      .values({ name })
276✔
18
      .execute();
276✔
19
  },
1✔
20

1✔
21
  /**
1✔
22
   * @param {import('umzug').MigrationParams<Uwave>} params
1✔
23
   */
1✔
24
  async unlogMigration({ name, context: uw }) {
1✔
NEW
25
    const { db } = uw;
×
26

×
NEW
27
    await db.deleteFrom('migrations')
×
NEW
28
      .where('name', '=', name)
×
NEW
29
      .execute();
×
30
  },
1✔
31

1✔
32
  /**
1✔
33
   * @param {{ context: Uwave }} params
1✔
34
   */
1✔
35
  async executed({ context: uw }) {
1✔
36
    const { db } = uw;
92✔
37
    const rows = await db.selectFrom('migrations').select(['name']).execute();
92✔
38

92✔
39
    return rows.map((row) => row.name);
92✔
40
  },
1✔
41
};
1✔
42

1✔
43
/**
1✔
44
 * @typedef {import('umzug').InputMigrations<Uwave>} MigrateOptions
1✔
45
 * @typedef {(opts: MigrateOptions) => Promise<void>} Migrate
1✔
46
 */
1✔
47

1✔
48
/**
1✔
49
 * @param {Uwave} uw
1✔
50
 */
1✔
51
async function migrationsPlugin(uw) {
92✔
52
  const { schema } = uw.db;
92✔
53
  const redLock = new RedLock([uw.redis]);
92✔
54

92✔
55
  schema.createTable('migrations')
92✔
56
    .ifNotExists()
92✔
57
    .addColumn('name', 'text', (col) => col.notNull().unique())
92✔
58
    .execute();
92✔
59

92✔
60
  /** @type {Migrate} */
92✔
61
  async function migrate(migrations) {
92✔
62
    const migrator = new Umzug({
92✔
63
      migrations,
92✔
64
      context: uw,
92✔
65
      storage: kyselyStorage,
92✔
66
      logger: uw.logger.child({ ns: 'uwave:migrations' }),
92✔
67
    });
92✔
68

92✔
69
    await redLock.using(['migrate'], 10000, async () => {
92✔
70
      await migrator.up();
92✔
71
    });
92✔
72
  }
92✔
73
  uw.migrate = migrate;
92✔
74

92✔
75
  try {
92✔
76
    await uw.migrate({
92✔
77
      glob: ['*.cjs', { cwd: fileURLToPath(new URL('../migrations', import.meta.url)) }],
92✔
78
    });
92✔
79
  } catch (err) {
92!
NEW
80
    if (err.migration) err.migration.context = null;
×
NEW
81
    throw err;
×
NEW
82
  }
×
83
}
92✔
84

1✔
85
export default migrationsPlugin;
1✔
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