mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-06-07 01:51:36 -04:00
feat: add seeding
This allows us to get a pre-populated database to develop new functionality Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
06d5113477
commit
294f79fc87
9 changed files with 333 additions and 209 deletions
48
backend/src/database/seeds/01_user.ts
Normal file
48
backend/src/database/seeds/01_user.ts
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { Knex } from 'knex';
|
||||
|
||||
import { ProviderType } from '../../auth/provider-type.enum';
|
||||
import { hashPassword } from '../../utils/password';
|
||||
import {
|
||||
FieldNameIdentity,
|
||||
FieldNameUser,
|
||||
TableIdentity,
|
||||
TableUser,
|
||||
} from '../types';
|
||||
|
||||
export async function seed(knex: Knex): Promise<void> {
|
||||
// Clear tables beforehand
|
||||
await knex(TableUser).del();
|
||||
await knex(TableIdentity).del();
|
||||
|
||||
// Insert user accounts and identities
|
||||
await knex(TableUser).insert([
|
||||
{
|
||||
[FieldNameUser.username]: null,
|
||||
[FieldNameUser.guestUuid]: '55b4618a-d5f3-4320-93d3-f3501c73d72b',
|
||||
[FieldNameUser.displayName]: null,
|
||||
[FieldNameUser.photoUrl]: null,
|
||||
[FieldNameUser.email]: null,
|
||||
[FieldNameUser.authorStyle]: 1,
|
||||
},
|
||||
{
|
||||
[FieldNameUser.username]: 'test',
|
||||
[FieldNameUser.guestUuid]: null,
|
||||
[FieldNameUser.displayName]: 'Local Test User',
|
||||
[FieldNameUser.photoUrl]: null,
|
||||
[FieldNameUser.email]: null,
|
||||
[FieldNameUser.authorStyle]: 2,
|
||||
},
|
||||
]);
|
||||
await knex(TableIdentity).insert({
|
||||
[FieldNameIdentity.userId]: 2,
|
||||
[FieldNameIdentity.providerType]: ProviderType.LOCAL,
|
||||
[FieldNameIdentity.providerIdentifier]: null,
|
||||
[FieldNameIdentity.providerUserId]: null,
|
||||
[FieldNameIdentity.passwordHash]: await hashPassword('test123'),
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue