Skip to content

Commit 6b18faa

Browse files
committed
add better seed data for Studio
1 parent b1d21c6 commit 6b18faa

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

seed/index.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
'use strict';
22

33
const assert = require('assert');
4-
const config = require('../.config');
4+
const localMongoUri = 'mongodb://127.0.0.1:27017/mongoose_local';
5+
6+
process.env.MONGODB_CONNECTION_STRING = localMongoUri;
7+
58
const connect = require('../src/db');
69

7-
assert.ok(config.uri.includes('localhost'), 'Can only seed localhost!');
10+
assert.ok(
11+
process.env.MONGODB_CONNECTION_STRING && process.env.MONGODB_CONNECTION_STRING.includes('127.0.0.1'),
12+
'Can only seed localhost!'
13+
);
814

915
run().catch(err => {
1016
console.log(err);
@@ -16,19 +22,29 @@ async function run() {
1622

1723
await conn.dropDatabase();
1824

19-
const { Subscriber } = conn.models;
20-
21-
await Subscriber.create([
22-
{
23-
githubUsername: 'vkarpov15',
24-
githubUserId: '1620265'
25-
},
26-
{
27-
githubUsername: 'IslandRhythms',
28-
githubUserId: '39510674'
29-
}
30-
]);
31-
32-
console.log('Done');
25+
const { User, Workspace } = conn.models;
26+
27+
const user = await User.create({
28+
email: 'val@karpov.io',
29+
githubUsername: 'vkarpov15',
30+
githubUserId: '1620265',
31+
name: 'Valeri Karpov'
32+
});
33+
await User.create({
34+
email: 'daniel@meanitsoftware.com',
35+
githubUsername: 'IslandRhythms',
36+
githubUserId: '39510674',
37+
name: 'Daniel Diaz'
38+
});
39+
40+
const workspace = await Workspace.create({
41+
name: 'Mongoose Studio Local Test',
42+
apiKey: 'TACO',
43+
ownerId: user._id,
44+
members: [{ userId: user._id, roles: ['owner'] }]
45+
});
46+
47+
console.log(`Created user ${user.email}`);
48+
console.log(`Created workspace ${workspace.name} (${workspace.apiKey})`);
3349
process.exit(0);
34-
}
50+
}

0 commit comments

Comments
 (0)