Add rules table migration sql
This commit is contained in:
@ -1651,6 +1651,7 @@ export type Rule = {
|
||||
__typename?: 'Rule';
|
||||
actions: Array<RuleAction>;
|
||||
createdAt: Scalars['Date'];
|
||||
enabled: Scalars['Boolean'];
|
||||
id: Scalars['ID'];
|
||||
name?: Maybe<Scalars['String']>;
|
||||
query: Scalars['String'];
|
||||
@ -1970,6 +1971,7 @@ export enum SetRuleErrorCode {
|
||||
|
||||
export type SetRuleInput = {
|
||||
actions: Array<RuleActionInput>;
|
||||
enabled: Scalars['Boolean'];
|
||||
id?: InputMaybe<Scalars['ID']>;
|
||||
name?: InputMaybe<Scalars['String']>;
|
||||
query: Scalars['String'];
|
||||
@ -4402,6 +4404,7 @@ export type RevokeApiKeySuccessResolvers<ContextType = ResolverContext, ParentTy
|
||||
export type RuleResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['Rule'] = ResolversParentTypes['Rule']> = {
|
||||
actions?: Resolver<Array<ResolversTypes['RuleAction']>, ParentType, ContextType>;
|
||||
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
||||
enabled?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType>;
|
||||
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
|
||||
name?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
|
||||
query?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
|
||||
@ -1159,6 +1159,7 @@ type RevokeApiKeySuccess {
|
||||
type Rule {
|
||||
actions: [RuleAction!]!
|
||||
createdAt: Date!
|
||||
enabled: Boolean!
|
||||
id: ID!
|
||||
name: String
|
||||
query: String!
|
||||
@ -1454,6 +1455,7 @@ enum SetRuleErrorCode {
|
||||
|
||||
input SetRuleInput {
|
||||
actions: [RuleActionInput!]!
|
||||
enabled: Boolean!
|
||||
id: ID
|
||||
name: String
|
||||
query: String!
|
||||
|
||||
25
packages/api/src/resolvers/rules/index.ts
Normal file
25
packages/api/src/resolvers/rules/index.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { authorized } from '../../utils/helpers'
|
||||
import {
|
||||
MutationSetRuleArgs,
|
||||
SetRuleError,
|
||||
SetRuleSuccess,
|
||||
} from '../../generated/graphql'
|
||||
|
||||
export const setRulesResolver = authorized<
|
||||
SetRuleSuccess,
|
||||
SetRuleError,
|
||||
MutationSetRuleArgs
|
||||
>(async (_, { input }, { claims, log }) => {
|
||||
log.info('Setting rules', {
|
||||
input,
|
||||
labels: {
|
||||
source: 'resolver',
|
||||
resolver: 'setRulesResolver',
|
||||
uid: claims.uid,
|
||||
},
|
||||
})
|
||||
|
||||
return {
|
||||
rules,
|
||||
}
|
||||
})
|
||||
@ -1961,6 +1961,7 @@ const schema = gql`
|
||||
name: String
|
||||
query: String!
|
||||
actions: [RuleAction!]!
|
||||
enabled: Boolean!
|
||||
createdAt: Date!
|
||||
updatedAt: Date!
|
||||
}
|
||||
@ -1991,6 +1992,7 @@ const schema = gql`
|
||||
name: String
|
||||
query: String!
|
||||
actions: [RuleActionInput!]!
|
||||
enabled: Boolean!
|
||||
}
|
||||
|
||||
input RuleActionInput {
|
||||
|
||||
19
packages/db/migrations/0099.do.rules.sql
Executable file
19
packages/db/migrations/0099.do.rules.sql
Executable file
@ -0,0 +1,19 @@
|
||||
-- Type: DO
|
||||
-- Name: rules
|
||||
-- Description: Create rules table which contains user defines rules and actions
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TABLE omnivore.rules (
|
||||
id uuid PRIMARY KEY DEFAULT uuid_generate_v1mc(),
|
||||
user_id uuid NOT NULL REFERENCES omnivore.user ON DELETE CASCADE,
|
||||
name text NOT NULL,
|
||||
description text,
|
||||
query text NOT NULL,
|
||||
actions text NOT NULL,
|
||||
enabled boolean NOT NULL DEFAULT true,
|
||||
created_at timestamptz NOT NULL DEFAULT current_timestamp,
|
||||
updated_at timestamptz NOT NULL DEFAULT current_timestamp,
|
||||
);
|
||||
|
||||
COMMIT;
|
||||
9
packages/db/migrations/0099.undo.rules.sql
Executable file
9
packages/db/migrations/0099.undo.rules.sql
Executable file
@ -0,0 +1,9 @@
|
||||
-- Type: UNDO
|
||||
-- Name: rules
|
||||
-- Description: Create rules table which contains user defines rules and actions
|
||||
|
||||
BEGIN;
|
||||
|
||||
DROP TABLE IF EXISTS omnivore.rules;
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user