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

u-wave / core / 11085094286

28 Sep 2024 03:39PM UTC coverage: 79.715% (-0.4%) from 80.131%
11085094286

Pull #637

github

web-flow
Merge 11ccf3b06 into 14c162f19
Pull Request #637: Switch to a relational database, closes #549

751 of 918 branches covered (81.81%)

Branch coverage included in aggregate %.

1891 of 2530 new or added lines in 50 files covered. (74.74%)

13 existing lines in 7 files now uncovered.

9191 of 11554 relevant lines covered (79.55%)

68.11 hits per line

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

99.46
/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%T', '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('media')
92✔
20
    .addColumn('id', 'uuid', (col) => col.primaryKey())
92✔
21
    .addColumn('source_type', 'text', (col) => col.notNull())
92✔
22
    .addColumn('source_id', 'text', (col) => col.notNull())
92✔
23
    .addColumn('source_data', 'jsonb')
92✔
24
    .addColumn('artist', 'text', (col) => col.notNull())
92✔
25
    .addColumn('title', 'text', (col) => col.notNull())
92✔
26
    .addColumn('duration', 'integer', (col) => col.notNull())
92✔
27
    .addColumn('thumbnail', 'text', (col) => col.notNull())
92✔
28
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
29
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
30
    .addUniqueConstraint('media_source_key', ['source_type', 'source_id'])
92✔
31
    .execute();
92✔
32

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

92✔
46
  await db.schema.createTable('roles')
92✔
47
    .addColumn('id', 'text', (col) => col.primaryKey())
92✔
48
    .addColumn('permissions', 'jsonb', (col) => col.notNull())
92✔
49
    .execute();
92✔
50

92✔
51
  await db.schema.createTable('user_roles')
92✔
52
    .addColumn('userID', 'uuid', (col) => col.references('users.id'))
92✔
53
    .addColumn('role', 'text', (col) => col.references('roles.id'))
92✔
54
    .addUniqueConstraint('unique_user_role', ['userID', 'role'])
92✔
55
    .execute();
92✔
56

92✔
57
  await db.schema.createTable('bans')
92✔
58
    .addColumn('user_id', 'uuid', (col) => col.primaryKey().references('users.id'))
92✔
59
    .addColumn('moderator_id', 'uuid', (col) => col.notNull().references('users.id'))
92✔
60
    .addColumn('expires_at', 'timestamp')
92✔
61
    .addColumn('reason', 'text')
92✔
62
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
63
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
64
    .execute();
92✔
65

92✔
66
  await db.schema.createTable('auth_services')
92✔
67
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
92✔
68
    .addColumn('service', 'text', (col) => col.notNull())
92✔
69
    .addColumn('service_id', 'text', (col) => col.notNull())
92✔
70
    .addColumn('service_avatar', 'text')
92✔
71
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
72
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
73
    .addUniqueConstraint('user_auth_service', ['user_id', 'service'])
92✔
74
    .addUniqueConstraint('auth_service', ['service', 'service_id'])
92✔
75
    .execute();
92✔
76

92✔
77
  await db.schema.createTable('playlists')
92✔
78
    .addColumn('id', 'uuid', (col) => col.primaryKey())
92✔
79
    .addColumn('name', 'text', (col) => col.notNull())
92✔
80
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
92✔
81
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
82
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
83
    .addColumn('items', 'jsonb', (col) => col.notNull().defaultTo(emptyArray))
92✔
84
    .execute();
92✔
85

92✔
86
  await db.schema.createTable('playlist_items')
92✔
87
    .addColumn('id', 'uuid', (col) => col.primaryKey())
92✔
88
    .addColumn('playlist_id', 'uuid', (col) => col.notNull().references('playlists.id'))
92✔
89
    .addColumn('media_id', 'uuid', (col) => col.notNull().references('media.id'))
92✔
90
    .addColumn('artist', 'text', (col) => col.notNull())
92✔
91
    .addColumn('title', 'text', (col) => col.notNull())
92✔
92
    .addColumn('start', 'integer', (col) => col.notNull())
92✔
93
    .addColumn('end', 'integer', (col) => col.notNull())
92✔
94
    .addColumn('created_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
95
    .addColumn('updated_at', 'timestamp', (col) => col.notNull().defaultTo(now))
92✔
96
    .execute();
92✔
97

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

92✔
110
  /*
92✔
111
  await db.schema.createTable('feedback')
92✔
112
    .addColumn('user_id', 'uuid', (col) => col.notNull().references('users.id'))
92✔
113
    .addColumn('history_id', 'uuid', (col) => col.notNull().references('history_entries.id'))
92✔
114
    // +1 or -1
92✔
115
    .addColumn('vote', 'integer')
92✔
116
    .addColumn('favorite', 'boolean')
92✔
117
    .execute();
92✔
118
  */
92✔
119

92✔
120
  await db.schema.alterTable('users')
92✔
121
    .addColumn('active_playlist_id', 'uuid', (col) => col.references('playlists.id'))
92✔
122
    .execute();
92✔
123
}
92✔
124

1✔
125
/**
1✔
126
 * @param {import('umzug').MigrationParams<import('../Uwave').default>} params
1✔
127
 */
1✔
NEW
128
async function down() {}
×
129

1✔
130
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