Skip to content

Commit 5099496

Browse files
Isolate MongoDB references to its migration (#673)
* Move mongoose models into SQLite migration * Remove references to mongo, except in migration
1 parent 77fa696 commit 5099496

18 files changed

+412
-487
lines changed

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The backend server for üWave, the collaborative listening platform.
1414
The server on its own only provides an HTTP API, so you must also run the web
1515
client to actually use it.
1616

17-
üWave requires MongoDB and Redis databases.
17+
üWave requires a Redis database.
1818

1919
## Usage
2020

@@ -35,10 +35,9 @@ Environment Variables:
3535
- `SECRET` - A secret key used for encrypting passwords. Must be a 64-character
3636
hexadecimal string (= 256 bits).
3737
- `PORT` - Port to listen on. Defaults to 6042.
38+
- `SQLITE_PATH` - Path to the database file to use. Defaults to `uwave.sqlite`.
3839
- `REDIS_URL` - URL of the Redis instance to connect to. Defaults to
3940
`redis://localhost:6379/`.
40-
- `MONGODB_URL` - URL of the MongoDB database to use. Defaults to
41-
`mongodb://localhost:27017/uwave`.
4241
- `YOUTUBE_API_KEY` (optional) - Your YouTube Data API key.
4342

4443
## Development
@@ -58,7 +57,7 @@ of the repository.
5857
```bash
5958
# Database connection URLs.
6059
REDIS_URL=redis://localhost:6379/
61-
MONGODB_URL=mongodb://localhost:27017/uwave_dev
60+
SQLITE_PATH=uwave_dev.sqlite
6261

6362
# Enables the YouTube media source if given.
6463
YOUTUBE_API_KEY=your key
@@ -80,7 +79,7 @@ Create and start a üWave server.
8079

8180
**Parameters**
8281

83-
- `mongo` - A MongoDB connection URL.
82+
- `sqlite` - Path to the SQLite database file.
8483
- `redis` - A Redis connection URL.
8584

8685
### uw.source(sourcePlugin, options={})
@@ -103,7 +102,6 @@ Stops the üWave server.
103102

104103
[MIT][]
105104

106-
[Mongoose]: http://mongoosejs.com/
107105
[IORedis]: https://github.com/luin/ioredis
108106
[u-wave-source keyword]: https://www.npmjs.com/browse/keyword/u-wave-source
109107

bin/u-wave-core.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ const envSchema = {
4242
format: 'uri',
4343
default: 'redis://localhost:6379',
4444
},
45-
MONGODB_URL: {
45+
SQLITE_PATH: {
4646
type: 'string',
47-
format: 'uri',
48-
default: 'mongodb://localhost:27017/uwave',
47+
default: 'uwave.sqlite',
4948
},
5049
SECRET: {
5150
type: 'string',
@@ -74,10 +73,10 @@ if (argv.h || argv.help || !validConfig) {
7473
console.log(' A secret key used for encrypting passwords. Must be a 64-character hexadecimal string (= 256 bits).');
7574
console.log(' PORT');
7675
console.log(' Port to listen on. Defaults to 6042.');
76+
console.log(' SQLITE_PATH');
77+
console.log(' Path to the database file. Defaults to uwave.sqlite.');
7778
console.log(' REDIS_URL');
7879
console.log(' URL of the Redis instance to connect to. Defaults to redis://localhost:6379/.');
79-
console.log(' MONGODB_URL');
80-
console.log(' URL of the MongoDB database to use. Defaults to mongodb://localhost:27017/uwave.');
8180
console.log(' YOUTUBE_API_KEY [optional]');
8281
console.log(' Your YouTube Data API key.');
8382
console.log();
@@ -107,14 +106,10 @@ const secret = Buffer.from(config.SECRET, 'hex');
107106
const uw = uwave({
108107
port,
109108
redis: config.REDIS_URL,
110-
mongo: config.MONGODB_URL,
109+
sqlite: config.SQLITE_PATH,
111110
secret,
112111
});
113112

114-
uw.on('mongoError', (err) => {
115-
throw explain(err, 'Could not connect to MongoDB. Is it installed and running?');
116-
});
117-
118113
uw.on('redisError', (err) => {
119114
throw explain(err, 'Could not connect to the Redis server. Is it installed and running?');
120115
});

dev/u-wave-dev-server.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ async function start() {
4141
const uw = uwave({
4242
port,
4343
redis: process.env.REDIS_URL,
44-
mongo: process.env.MONGODB_URL ?? 'mongodb://localhost/uwave',
44+
sqlite: process.env.SQLITE_PATH ?? 'uwave.sqlite',
4545
logger: { level: 'trace' },
4646
secret,
4747
mailTransport: testTransport,
@@ -54,10 +54,6 @@ async function start() {
5454
instance.express.set('json spaces', 2);
5555
});
5656

57-
uw.on('mongoError', (err) => {
58-
throw explain(err, 'Could not connect to MongoDB. Is it installed and running?');
59-
});
60-
6157
uw.on('redisError', (err) => {
6258
throw explain(err, 'Could not connect to the Redis server. Is it installed and running?');
6359
});

example/docker-compose.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
version: "3.1"
22
services:
3-
mongo:
4-
image: mongo
53
redis:
64
image: redis
75
u-wave:
@@ -10,7 +8,6 @@ services:
108
ports:
119
- "${PORT}:${PORT}"
1210
links:
13-
- mongo
1411
- redis
1512
env_file:
1613
- .env

example/example.env

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
PORT=6042
2-
MONGO_CONNECTION_URL=mongodb://mongo/uwave
32
REDIS_CONNECTION_URL=redis://redis
43

54
SECRET=USE_YOUR_OWN
65
YOUTUBE_API_KEY=USE_YOUR_OWN
7-
SOUNDCLOUD_API_KEY=USE_YOUR_OWN
6+
SOUNDCLOUD_API_KEY=USE_YOUR_OWN

example/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ dotenv.config();
1111
const port = process.env.PORT ?? 80;
1212
const secret = Buffer.from(process.env.SECRET, 'hex');
1313

14-
const DEFAULT_MONGO_URL = 'mongodb://localhost:27017/uwave';
14+
const DEFAULT_SQLITE_PATH = 'uwave.sqlite';
1515
const DEFAULT_REDIS_URL = 'redis://localhost:6379';
1616

1717
const uw = uwave({
18-
mongo: process.env.MONGO_CONNECTION_URL ?? DEFAULT_MONGO_URL,
18+
sqlite: process.env.SQLITE_PATH ?? DEFAULT_SQLITE_PATH,
1919
redis: process.env.REDIS_CONNECTION_URL ?? DEFAULT_REDIS_URL,
2020
port,
2121
secret,

src/Uwave.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import passport from './plugins/passport.js';
2222
import migrations from './plugins/migrations.js';
2323
import { SqliteDateColumnsPlugin, connect as connectSqlite } from './utils/sqlite.js';
2424

25-
const DEFAULT_MONGO_URL = 'mongodb://localhost:27017/uwave';
25+
const DEFAULT_SQLITE_PATH = './uwave.sqlite';
2626
const DEFAULT_REDIS_URL = 'redis://localhost:6379';
2727

2828
class UwCamelCasePlugin extends CamelCasePlugin {
@@ -49,7 +49,6 @@ class UwCamelCasePlugin extends CamelCasePlugin {
4949
* @typedef {{
5050
* port?: number,
5151
* sqlite?: string,
52-
* mongo?: string,
5352
* redis?: string | RedisOptions,
5453
* logger?: import('pino').LoggerOptions,
5554
* } & import('./HttpApi.js').HttpApiOptions} Options
@@ -146,15 +145,15 @@ class UwaveServer extends EventEmitter {
146145
this.locale = i18n.cloneInstance();
147146

148147
this.options = {
149-
mongo: DEFAULT_MONGO_URL,
148+
sqlite: DEFAULT_SQLITE_PATH,
150149
redis: DEFAULT_REDIS_URL,
151150
...options,
152151
};
153152

154153
/** @type {Kysely<import('./schema.js').Database>} */
155154
this.db = new Kysely({
156155
dialect: new SqliteDialect({
157-
database: () => connectSqlite(options.sqlite ?? 'uwave_local.sqlite'),
156+
database: () => connectSqlite(options.sqlite ?? DEFAULT_SQLITE_PATH),
158157
}),
159158
// dialect: new PostgresDialect({
160159
// pool: new pg.Pool({

0 commit comments

Comments
 (0)