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

u-wave / core / 12018572686

25 Nov 2024 08:51PM UTC coverage: 82.056% (-0.03%) from 82.089%
12018572686

Pull #657

github

web-flow
Merge 3742dbfd0 into cbb61457b
Pull Request #657: SQLite Key-value store to replace Redis

840 of 1010 branches covered (83.17%)

Branch coverage included in aggregate %.

26 of 37 new or added lines in 2 files covered. (70.27%)

109 existing lines in 4 files now uncovered.

9115 of 11122 relevant lines covered (81.95%)

89.39 hits per line

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

99.51
/src/migrations/002-sql.cjs
1
'use strict';
1✔
2

1✔
3
const { sql } = require('kysely');
1✔
4

1✔
5
const now = sql`(strftime('%FT%TZ', 'now'))`;
1✔
6
const emptyArray = sql`(jsonb('[]'))`;
1✔
7

1✔
8
/**
1✔
9
 * @param {import('umzug').MigrationParams<import('../Uwave').default>} params
1✔
10
 */
1✔
11
async function up({ context: uw }) {
132✔
12
  const { db } = uw;
132✔
13

132✔
14
  await db.schema.createTable('configuration')
132✔
15
    .addColumn('name', 'text', (col) => col.primaryKey())
132✔
16
    .addColumn('value', 'jsonb')
132✔
17
    .execute();
132✔
18

132✔
19
  await db.schema.createTable('keyval')
132✔
20
    .addColumn('key', 'text', (col) => col.primaryKey())
132✔
21
    .addColumn('value', 'jsonb')
132✔
22
    .execute();
132✔
23

132✔
24
  await db.schema.createTable('media')
132✔
25
    .addColumn('id', 'uuid', (col) => col.primaryKey())
132✔
26
    .addColumn('source_type', 'text', (col) => col.notNull())
132✔
27
    .addColumn('source_id', 'text', (col) => col.notNull())
132✔
28
    .addColumn('source_data', 'jsonb')
132✔
29
    .addColumn('artist', 'text', (col) => col.notNull())
132✔
30
    .addColumn('title', 'text', (col) => col.notNull())
132✔
31
    .addColumn('duration', 'integer', (col) => col.notNull())
132✔
32
    .addColumn('thumbnail', 'text', (col) => col.notNull())
132✔
33
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
34
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
35
    .addUniqueConstraint('media_source_key', ['source_type', 'source_id'])
132✔
36
    .execute();
132✔
37

132✔
38
  await db.schema.createTable('users')
132✔
39
    .addColumn('id', 'uuid', (col) => col.primaryKey())
132✔
40
    .addColumn('username', 'text', (col) => col.notNull().unique())
132✔
41
    .addColumn('email', 'text')
132✔
42
    .addColumn('password', 'text')
132✔
43
    .addColumn('slug', 'text', (col) => col.notNull().unique())
132✔
44
    .addColumn('avatar', 'text')
132✔
45
    .addColumn('pending_activation', 'boolean', (col) => col.defaultTo(null))
132✔
46
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
47
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
48
    .addUniqueConstraint('user_email', ['email'])
132✔
49
    .execute();
132✔
50

132✔
51
  await db.schema.createTable('roles')
132✔
52
    .addColumn('id', 'text', (col) => col.primaryKey())
132✔
53
    .addColumn('permissions', 'jsonb', (col) => col.notNull())
132✔
54
    .execute();
132✔
55

132✔
56
  await db.schema.createTable('user_roles')
132✔
57
    .addColumn('userID', 'uuid', (col) => col.references('users.id'))
132✔
58
    .addColumn('role', 'text', (col) => col.references('roles.id'))
132✔
59
    .addUniqueConstraint('unique_user_role', ['userID', 'role'])
132✔
60
    .execute();
132✔
61

132✔
62
  await db.schema.createTable('bans')
132✔
63
    .addColumn('user_id', 'uuid', (col) => col.primaryKey().references('users.id'))
132✔
64
    .addColumn('moderator_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
65
    .addColumn('expires_at', 'timestamp')
132✔
66
    .addColumn('reason', 'text')
132✔
67
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
68
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
69
    .execute();
132✔
70

132✔
71
  await db.schema.createTable('mutes')
132✔
72
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
73
    .addColumn('moderator_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
74
    .addColumn('expires_at', 'timestamp', (col) => col.notNull())
132✔
75
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
76
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
77
    .execute();
132✔
78

132✔
79
  await db.schema.createTable('auth_services')
132✔
80
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
81
    .addColumn('service', 'text', (col) => col.notNull())
132✔
82
    .addColumn('service_id', 'text', (col) => col.notNull())
132✔
83
    .addColumn('service_avatar', 'text')
132✔
84
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
85
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
86
    .addUniqueConstraint('user_auth_service', ['user_id', 'service'])
132✔
87
    .addUniqueConstraint('auth_service', ['service', 'service_id'])
132✔
88
    .execute();
132✔
89

132✔
90
  await db.schema.createTable('playlists')
132✔
91
    .addColumn('id', 'uuid', (col) => col.primaryKey())
132✔
92
    .addColumn('name', 'text', (col) => col.notNull())
132✔
93
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
94
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
95
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
96
    .addColumn('items', 'jsonb', (col) => col.notNull().defaultTo(emptyArray))
132✔
97
    .execute();
132✔
98

132✔
99
  await db.schema.createTable('playlist_items')
132✔
100
    .addColumn('id', 'uuid', (col) => col.primaryKey())
132✔
101
    .addColumn('playlist_id', 'uuid', (col) => col.notNull().references('playlists.id'))
132✔
102
    .addColumn('media_id', 'uuid', (col) => col.notNull().references('media.id'))
132✔
103
    .addColumn('artist', 'text', (col) => col.notNull())
132✔
104
    .addColumn('title', 'text', (col) => col.notNull())
132✔
105
    .addColumn('start', 'integer', (col) => col.notNull())
132✔
106
    .addColumn('end', 'integer', (col) => col.notNull())
132✔
107
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
108
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
109
    .execute();
132✔
110

132✔
111
  await db.schema.createTable('history_entries')
132✔
112
    .addColumn('id', 'uuid', (col) => col.primaryKey())
132✔
113
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
114
    .addColumn('media_id', 'uuid', (col) => col.notNull().references('media.id'))
132✔
115
    .addColumn('artist', 'text', (col) => col.notNull())
132✔
116
    .addColumn('title', 'text', (col) => col.notNull())
132✔
117
    .addColumn('start', 'integer', (col) => col.notNull())
132✔
118
    .addColumn('end', 'integer', (col) => col.notNull())
132✔
119
    .addColumn('source_data', 'jsonb')
132✔
120
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
132✔
121
    .execute();
132✔
122

132✔
123
  await db.schema.createTable('feedback')
132✔
124
    .addColumn('history_entry_id', 'uuid', (col) => col.notNull().references('historyEntries.id'))
132✔
125
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
132✔
126
    .addColumn('vote', 'integer', (col) => col.defaultTo(0))
132✔
127
    .addColumn('favorite', 'integer', (col) => col.defaultTo(0))
132✔
128
    .addUniqueConstraint('one_vote_per_user', ['history_entry_id', 'user_id'])
132✔
129
    .execute();
132✔
130

132✔
131
  await db.schema.alterTable('users')
132✔
132
    .addColumn('active_playlist_id', 'uuid', (col) => col.references('playlists.id'))
132✔
133
    .execute();
132✔
134
}
132✔
135

1✔
136
/**
1✔
137
 * @param {import('umzug').MigrationParams<import('../Uwave').default>} params
1✔
138
 */
1✔
UNCOV
139
async function down() {}
×
140

1✔
141
module.exports = { up, down };
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