mirror of
https://github.com/docmost/docmost.git
synced 2026-08-22 22:32:35 +10:00
feat: integrations
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
import { type Kysely, sql } from 'kysely';
|
||||
|
||||
export async function up(db: Kysely<any>): Promise<void> {
|
||||
await db.schema
|
||||
.createTable('integrations')
|
||||
.addColumn('id', 'uuid', (col) =>
|
||||
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||
)
|
||||
.addColumn('workspace_id', 'uuid', (col) =>
|
||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('type', 'text', (col) => col.notNull())
|
||||
.addColumn('is_enabled', 'boolean', (col) => col.notNull().defaultTo(true))
|
||||
.addColumn('settings', 'jsonb')
|
||||
.addColumn('installed_by_id', 'uuid', (col) =>
|
||||
col.references('users.id').onDelete('set null'),
|
||||
)
|
||||
.addColumn('created_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addColumn('deleted_at', 'timestamptz')
|
||||
.addUniqueConstraint('uq_integrations_workspace_type', [
|
||||
'workspace_id',
|
||||
'type',
|
||||
])
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable('integration_connections')
|
||||
.addColumn('id', 'uuid', (col) =>
|
||||
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||
)
|
||||
.addColumn('integration_id', 'uuid', (col) =>
|
||||
col.references('integrations.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('user_id', 'uuid', (col) =>
|
||||
col.references('users.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('workspace_id', 'uuid', (col) =>
|
||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('provider_user_id', 'text')
|
||||
.addColumn('access_token', 'text', (col) => col.notNull())
|
||||
.addColumn('refresh_token', 'text')
|
||||
.addColumn('token_expires_at', 'timestamptz')
|
||||
.addColumn('scopes', 'text')
|
||||
.addColumn('metadata', 'jsonb')
|
||||
.addColumn('created_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addUniqueConstraint('uq_integration_connections_integration_user', [
|
||||
'integration_id',
|
||||
'user_id',
|
||||
])
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createTable('integration_webhooks')
|
||||
.addColumn('id', 'uuid', (col) =>
|
||||
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||
)
|
||||
.addColumn('integration_id', 'uuid', (col) =>
|
||||
col.references('integrations.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('workspace_id', 'uuid', (col) =>
|
||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||
)
|
||||
.addColumn('event_type', 'text', (col) => col.notNull())
|
||||
.addColumn('webhook_url', 'text')
|
||||
.addColumn('secret', 'text')
|
||||
.addColumn('is_enabled', 'boolean', (col) => col.notNull().defaultTo(true))
|
||||
.addColumn('created_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||
col.notNull().defaultTo(sql`now()`),
|
||||
)
|
||||
.execute();
|
||||
|
||||
await db.schema
|
||||
.createIndex('idx_integration_webhooks_integration_event')
|
||||
.on('integration_webhooks')
|
||||
.columns(['integration_id', 'event_type'])
|
||||
.execute();
|
||||
}
|
||||
|
||||
export async function down(db: Kysely<any>): Promise<void> {
|
||||
await db.schema.dropTable('integration_webhooks').execute();
|
||||
await db.schema.dropTable('integration_connections').execute();
|
||||
await db.schema.dropTable('integrations').execute();
|
||||
}
|
||||
+42
@@ -390,6 +390,45 @@ export interface Watchers {
|
||||
createdAt: Generated<Timestamp>;
|
||||
}
|
||||
|
||||
export interface Integrations {
|
||||
id: Generated<string>;
|
||||
workspaceId: string;
|
||||
type: string;
|
||||
isEnabled: Generated<boolean>;
|
||||
settings: Json | null;
|
||||
installedById: string | null;
|
||||
createdAt: Generated<Timestamp>;
|
||||
updatedAt: Generated<Timestamp>;
|
||||
deletedAt: Timestamp | null;
|
||||
}
|
||||
|
||||
export interface IntegrationConnections {
|
||||
id: Generated<string>;
|
||||
integrationId: string;
|
||||
userId: string;
|
||||
workspaceId: string;
|
||||
providerUserId: string | null;
|
||||
accessToken: string;
|
||||
refreshToken: string | null;
|
||||
tokenExpiresAt: Timestamp | null;
|
||||
scopes: string | null;
|
||||
metadata: Json | null;
|
||||
createdAt: Generated<Timestamp>;
|
||||
updatedAt: Generated<Timestamp>;
|
||||
}
|
||||
|
||||
export interface IntegrationWebhooks {
|
||||
id: Generated<string>;
|
||||
integrationId: string;
|
||||
workspaceId: string;
|
||||
eventType: string;
|
||||
webhookUrl: string | null;
|
||||
secret: string | null;
|
||||
isEnabled: Generated<boolean>;
|
||||
createdAt: Generated<Timestamp>;
|
||||
updatedAt: Generated<Timestamp>;
|
||||
}
|
||||
|
||||
export interface DB {
|
||||
apiKeys: ApiKeys;
|
||||
attachments: Attachments;
|
||||
@@ -401,6 +440,9 @@ export interface DB {
|
||||
fileTasks: FileTasks;
|
||||
groups: Groups;
|
||||
groupUsers: GroupUsers;
|
||||
integrationConnections: IntegrationConnections;
|
||||
integrationWebhooks: IntegrationWebhooks;
|
||||
integrations: Integrations;
|
||||
notifications: Notifications;
|
||||
pageHistory: PageHistory;
|
||||
pages: Pages;
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
import { DB } from '@docmost/db/types/db';
|
||||
import { PageEmbeddings } from '@docmost/db/types/embeddings.types';
|
||||
import {
|
||||
Integrations,
|
||||
IntegrationConnections,
|
||||
IntegrationWebhooks,
|
||||
} from '@docmost/db/types/db';
|
||||
|
||||
export interface DbInterface extends DB {
|
||||
pageEmbeddings: PageEmbeddings;
|
||||
integrations: Integrations;
|
||||
integrationConnections: IntegrationConnections;
|
||||
integrationWebhooks: IntegrationWebhooks;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ import {
|
||||
Attachments,
|
||||
Comments,
|
||||
Groups,
|
||||
Integrations as _Integrations,
|
||||
IntegrationConnections as _IntegrationConnections,
|
||||
IntegrationWebhooks as _IntegrationWebhooks,
|
||||
Notifications,
|
||||
Pages,
|
||||
Spaces,
|
||||
@@ -143,3 +146,23 @@ export type UpdatableNotification = Updateable<Omit<Notifications, 'id'>>;
|
||||
export type Watcher = Selectable<Watchers>;
|
||||
export type InsertableWatcher = Insertable<Watchers>;
|
||||
export type UpdatableWatcher = Updateable<Omit<Watchers, 'id'>>;
|
||||
|
||||
// Integration
|
||||
export type Integration = Selectable<_Integrations>;
|
||||
export type InsertableIntegration = Insertable<_Integrations>;
|
||||
export type UpdatableIntegration = Updateable<Omit<_Integrations, 'id'>>;
|
||||
|
||||
// Integration Connection
|
||||
export type IntegrationConnection = Selectable<_IntegrationConnections>;
|
||||
export type InsertableIntegrationConnection =
|
||||
Insertable<_IntegrationConnections>;
|
||||
export type UpdatableIntegrationConnection = Updateable<
|
||||
Omit<_IntegrationConnections, 'id'>
|
||||
>;
|
||||
|
||||
// Integration Webhook
|
||||
export type IntegrationWebhook = Selectable<_IntegrationWebhooks>;
|
||||
export type InsertableIntegrationWebhook = Insertable<_IntegrationWebhooks>;
|
||||
export type UpdatableIntegrationWebhook = Updateable<
|
||||
Omit<_IntegrationWebhooks, 'id'>
|
||||
>;
|
||||
|
||||
Reference in New Issue
Block a user