mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 22:54:42 -04:00
Seed: Generate multiple notes and authorships
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
f6d430c23f
commit
6abcb686ca
1 changed files with 36 additions and 11 deletions
47
src/seed.ts
47
src/seed.ts
|
@ -5,6 +5,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createConnection } from 'typeorm';
|
import { createConnection } from 'typeorm';
|
||||||
|
import { Author } from './authors/author.entity';
|
||||||
|
import { Session } from './users/session.entity';
|
||||||
import { User } from './users/user.entity';
|
import { User } from './users/user.entity';
|
||||||
import { Note } from './notes/note.entity';
|
import { Note } from './notes/note.entity';
|
||||||
import { Revision } from './revisions/revision.entity';
|
import { Revision } from './revisions/revision.entity';
|
||||||
|
@ -37,22 +39,45 @@ createConnection({
|
||||||
Tag,
|
Tag,
|
||||||
AuthToken,
|
AuthToken,
|
||||||
Identity,
|
Identity,
|
||||||
|
Author,
|
||||||
|
Session,
|
||||||
],
|
],
|
||||||
synchronize: true,
|
synchronize: true,
|
||||||
logging: false,
|
logging: false,
|
||||||
|
dropSchema: true,
|
||||||
})
|
})
|
||||||
.then(async (connection) => {
|
.then(async (connection) => {
|
||||||
const user = User.create('hardcoded', 'Test User');
|
const users = [];
|
||||||
const note = Note.create(undefined, 'test');
|
users.push(User.create('hardcoded', 'Test User 1'));
|
||||||
const revision = Revision.create(
|
users.push(User.create('hardcoded_2', 'Test User 2'));
|
||||||
'This is a test note',
|
users.push(User.create('hardcoded_3', 'Test User 3'));
|
||||||
'This is a test note',
|
const notes: Note[] = [];
|
||||||
);
|
notes.push(Note.create(undefined, 'test'));
|
||||||
note.revisions = Promise.all([revision]);
|
notes.push(Note.create(undefined, 'test2'));
|
||||||
note.userPermissions = [];
|
notes.push(Note.create(undefined, 'test3'));
|
||||||
note.groupPermissions = [];
|
|
||||||
user.ownedNotes = [note];
|
for (let i = 0; i < 3; i++) {
|
||||||
await connection.manager.save([user, note, revision]);
|
const author = connection.manager.create(Author, Author.create(1));
|
||||||
|
const user = connection.manager.create(User, users[i]);
|
||||||
|
author.user = user;
|
||||||
|
const revision = Revision.create(
|
||||||
|
'This is a test note',
|
||||||
|
'This is a test note',
|
||||||
|
);
|
||||||
|
const authorship = Authorship.create(author, 1, 42);
|
||||||
|
revision.authorships = [authorship];
|
||||||
|
notes[i].revisions = Promise.all([revision]);
|
||||||
|
notes[i].userPermissions = [];
|
||||||
|
notes[i].groupPermissions = [];
|
||||||
|
user.ownedNotes = [notes[i]];
|
||||||
|
await connection.manager.save([
|
||||||
|
notes[i],
|
||||||
|
user,
|
||||||
|
revision,
|
||||||
|
authorship,
|
||||||
|
author,
|
||||||
|
]);
|
||||||
|
}
|
||||||
const foundUser = await connection.manager.findOne(User);
|
const foundUser = await connection.manager.findOne(User);
|
||||||
if (!foundUser) {
|
if (!foundUser) {
|
||||||
throw new Error('Could not find freshly seeded user. Aborting.');
|
throw new Error('Could not find freshly seeded user. Aborting.');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue