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

u-wave / core / 11980927100

22 Nov 2024 10:11PM UTC coverage: 78.471% (-0.02%) from 78.492%
11980927100

Pull #657

github

goto-bus-stop
SQLite Key-value store to replace Redis
Pull Request #657: SQLite Key-value store to replace Redis

760 of 915 branches covered (83.06%)

Branch coverage included in aggregate %.

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

117 existing lines in 4 files now uncovered.

8691 of 11129 relevant lines covered (78.09%)

70.74 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 }) {
92✔
12
  const { db } = uw;
92✔
13

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

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

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

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

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

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

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

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

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

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

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

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

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

92✔
131
  await db.schema.alterTable('users')
92✔
132
    .addColumn('active_playlist_id', 'uuid', (col) => col.references('playlists.id'))
92✔
133
    .execute();
92✔
134
}
92✔
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