Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
Add check constraint to enforce type column on authors
Browse files Browse the repository at this point in the history
  • Loading branch information
Macludde committed Sep 5, 2023
1 parent 57931b4 commit 122e4b7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export async function up(knex: Knex): Promise<void> {
table.enu('type', ['Member', 'Mandate', 'Custom'], { useNative: true, enumName: 'author_type' }).notNullable().defaultTo('Member');
table.uuid('temp_article_id').unsigned().notNullable().references('articles.id')
.comment('Temporary column during migration');

table.check(`type = 'Member' AND mandate_id IS NULL AND custom_id IS NULL
OR type = 'Mandate' AND mandate_id IS NOT NULL AND custom_id IS NULL
OR type = 'Custom' AND mandate_id IS NULL AND custom_id IS NOT NULL`, undefined, 'enforce_author_type');
});
// Get all articles posted by a member, not as a mandate
const memberAuthorArticles = await knex('articles').select('id', 'author_id', 'author_type', 'published_datetime', 'latest_edit_datetime')
Expand Down
2 changes: 1 addition & 1 deletion backend/services/core/src/types/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@ export type ReferenceResolver<TResult, TReference, TContext> = (
type NullableCheck<T, S> = Maybe<T> extends T ? Maybe<ListCheck<NonNullable<T>, S>> : ListCheck<T, S>;
type ListCheck<T, S> = T extends (infer U)[] ? NullableCheck<U, S>[] : GraphQLRecursivePick<T, S>;
export type GraphQLRecursivePick<T, S> = { [K in keyof T & keyof S]: ScalarCheck<T[K], S[K]> };


export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
Expand Down

0 comments on commit 122e4b7

Please sign in to comment.