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

u-wave / core / 11980915260

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

push

github

web-flow
Switch to a relational database (#637)

* It boots from SQL

* progress on loading playlists

* Use uppercase ID

* Search based on SQL media

* add userID to history entry schema

* stash

* Migrate history, read history

* Typed IDs; move mostly to new schema types

* Migrate authentication model to SQL

* Update unique constraints

* Fix lodash import

* Select the right stuff from users

* Use Object.groupBy

* Use order column for playlist sorting?

The other option is to have a JSON column with IDs on the playlists
table.

* Add linting for JSDoc

* SQL config store

* stash

* Bump kysely

* Different way to store playlist item order

* Opaque -> Tagged

* Port bans

* deps: update better-sqlite3

* Remove mongodb connection code

* Adding playlist items with sql?

* Revert "Remove mongodb connection code"

This reverts commit 8b2ae37e6.

* Make migrations work in sql

* Try with SQLite

* Migrate auth passwords

* Better Date support for SQLite

* Use json_each

* use json_array_length

* SQLite utility functions

* Fix property name in test

* playlist shuffle and cycle with sqlite

* Use a flat list of permissions

* Various test fixes

* Ban test sorta working

* small test fixes

* acl fixes

* some more json sqlite fixes

* serialize active playlist id

* Implement playlist updates with sql

* More JSON fun

* users test fixes

* test fixes for bans and /now

* finish redis connection before changing configs

* User avatar / roles return values

* test ID fix

* Fix playlist item serialization

* implement removing playlist items

* put comment

* Fix issues due to playlist position options

* disable sql query logging

* various sql booth fixes

* Test fixes by moving to new data structure

* Inline the email function

* Fix email test

* This map is a multi map

* fix playlist item filte... (continued)

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