mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 09:45:37 -04:00
wip: get knex migrations running
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
d67e44f540
commit
6e56e3f99e
2 changed files with 37 additions and 38 deletions
|
@ -6,6 +6,8 @@
|
||||||
import { HttpAdapterHost } from '@nestjs/core';
|
import { HttpAdapterHost } from '@nestjs/core';
|
||||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||||
import { WsAdapter } from '@nestjs/platform-ws';
|
import { WsAdapter } from '@nestjs/platform-ws';
|
||||||
|
import { Knex } from 'knex';
|
||||||
|
import { getConnectionToken } from 'nest-knexjs';
|
||||||
|
|
||||||
import { AppConfig } from './config/app.config';
|
import { AppConfig } from './config/app.config';
|
||||||
import { AuthConfig } from './config/auth.config';
|
import { AuthConfig } from './config/auth.config';
|
||||||
|
@ -42,6 +44,10 @@ export async function setupApp(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const knexConnectionToken = getConnectionToken();
|
||||||
|
const knex: Knex = app.get<Knex>(knexConnectionToken);
|
||||||
|
await knex.migrate.latest();
|
||||||
|
|
||||||
// Setup session handling
|
// Setup session handling
|
||||||
setupSessionMiddleware(
|
setupSessionMiddleware(
|
||||||
app,
|
app,
|
||||||
|
|
|
@ -1,44 +1,36 @@
|
||||||
/*
|
// noinspection ES6PreferShortImport
|
||||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
|
||||||
*
|
/* eslint-disable */
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
|
||||||
*/
|
|
||||||
import { AuthProviderType, NoteType, SpecialGroup } from '@hedgedoc/commons';
|
import { AuthProviderType, NoteType, SpecialGroup } from '@hedgedoc/commons';
|
||||||
import type { Knex } from 'knex';
|
|
||||||
|
|
||||||
import { BackendType } from '../../media/backends/backend-type.enum';
|
import { FieldNameAlias, TableAlias } from '../types/alias';
|
||||||
|
import { FieldNameApiToken, TableApiToken } from '../types/api-token';
|
||||||
import {
|
import {
|
||||||
FieldNameAlias,
|
|
||||||
FieldNameApiToken,
|
|
||||||
FieldNameAuthorshipInfo,
|
FieldNameAuthorshipInfo,
|
||||||
FieldNameGroup,
|
|
||||||
FieldNameGroupUser,
|
|
||||||
FieldNameIdentity,
|
|
||||||
FieldNameMediaUpload,
|
|
||||||
FieldNameNote,
|
|
||||||
FieldNameNoteGroupPermission,
|
|
||||||
FieldNameNoteUserPermission,
|
|
||||||
FieldNameRevision,
|
|
||||||
FieldNameRevisionTag,
|
|
||||||
FieldNameUser,
|
|
||||||
FieldNameUserPinnedNote,
|
|
||||||
TableAlias,
|
|
||||||
TableApiToken,
|
|
||||||
TableAuthorshipInfo,
|
TableAuthorshipInfo,
|
||||||
TableGroup,
|
} from '../types/authorship-info';
|
||||||
TableGroupUser,
|
import { FieldNameGroup, TableGroup } from '../types/group';
|
||||||
TableIdentity,
|
import { FieldNameGroupUser, TableGroupUser } from '../types/group-user';
|
||||||
TableMediaUpload,
|
import { FieldNameIdentity, TableIdentity } from '../types/identity';
|
||||||
TableNote,
|
import { FieldNameMediaUpload, TableMediaUpload } from '../types/media-upload';
|
||||||
|
import { FieldNameNote, TableNote } from '../types/note';
|
||||||
|
import {
|
||||||
|
FieldNameNoteGroupPermission,
|
||||||
TableNoteGroupPermission,
|
TableNoteGroupPermission,
|
||||||
|
} from '../types/note-group-permission';
|
||||||
|
import {
|
||||||
|
FieldNameNoteUserPermission,
|
||||||
TableNoteUserPermission,
|
TableNoteUserPermission,
|
||||||
TableRevision,
|
} from '../types/note-user-permission';
|
||||||
TableRevisionTag,
|
import { FieldNameRevision, TableRevision } from '../types/revision';
|
||||||
TableUser,
|
import { FieldNameRevisionTag, TableRevisionTag } from '../types/revision-tag';
|
||||||
|
import { FieldNameUser, TableUser } from '../types/user';
|
||||||
|
import {
|
||||||
|
FieldNameUserPinnedNote,
|
||||||
TableUserPinnedNote,
|
TableUserPinnedNote,
|
||||||
} from '../types';
|
} from '../types/user-pinned-note';
|
||||||
|
|
||||||
export async function up(knex: Knex): Promise<void> {
|
export async function up(knex) {
|
||||||
// Create the user table first as it's referenced by other tables
|
// Create the user table first as it's referenced by other tables
|
||||||
await knex.schema.createTable(TableUser, (table) => {
|
await knex.schema.createTable(TableUser, (table) => {
|
||||||
table.increments(FieldNameUser.id).primary();
|
table.increments(FieldNameUser.id).primary();
|
||||||
|
@ -319,11 +311,12 @@ export async function up(knex: Knex): Promise<void> {
|
||||||
.enu(
|
.enu(
|
||||||
FieldNameMediaUpload.backendType,
|
FieldNameMediaUpload.backendType,
|
||||||
[
|
[
|
||||||
BackendType.AZURE,
|
/* We need to use the strings here as this mirgation is js code and can't handle enums */
|
||||||
BackendType.FILESYSTEM,
|
'azure', // BackendType.AZURE
|
||||||
BackendType.IMGUR,
|
'filesystem', //BackendType.FILESYSTEM
|
||||||
BackendType.S3,
|
'imgur', // BackendType.IMGUR
|
||||||
BackendType.WEBDAV,
|
's3', // BackendType.S3,
|
||||||
|
'webdav', //BackendType.WEBDAV
|
||||||
],
|
],
|
||||||
{
|
{
|
||||||
useNative: true,
|
useNative: true,
|
||||||
|
@ -358,7 +351,7 @@ export async function up(knex: Knex): Promise<void> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(knex: Knex): Promise<void> {
|
export async function down(knex) {
|
||||||
// Drop tables in reverse order of creation to avoid integer key constraints
|
// Drop tables in reverse order of creation to avoid integer key constraints
|
||||||
await knex.schema.dropTableIfExists(TableUserPinnedNote);
|
await knex.schema.dropTableIfExists(TableUserPinnedNote);
|
||||||
await knex.schema.dropTableIfExists(TableMediaUpload);
|
await knex.schema.dropTableIfExists(TableMediaUpload);
|
Loading…
Add table
Add a link
Reference in a new issue