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:
Philip Molares 2025-03-14 00:41:36 +01:00 committed by Erik Michelson
parent 06d5113477
commit 294f79fc87
No known key found for this signature in database
GPG key ID: DB99ADDDC5C0AF82
9 changed files with 333 additions and 209 deletions

View 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'),
});
}