Skip to content

Commit

Permalink
add DataExport model
Browse files Browse the repository at this point in the history
  • Loading branch information
sjorobekov committed Dec 20, 2024
1 parent c5ea22d commit b246333
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/db/migrations/20241219092946_data_export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type {Knex} from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex.raw(`
CREATE TABLE data_export (
CREATE TABLE data_exports (
data_export_id BIGINT NOT NULL PRIMARY KEY DEFAULT get_id(),
title TEXT NOT NULL,
tenant_id TEXT,
tenant_id TEXT NOT NULL DEFAULT 'common' REFERENCES tenants (tenant_id) ON UPDATE CASCADE ON DELETE CASCADE,
chart_id BIGINT NOT NULL,
chart_rev_id BIGINT NOT NULL,
dataset_id BIGINT,
Expand All @@ -25,6 +25,6 @@ export async function up(knex: Knex): Promise<void> {

export async function down(knex: Knex): Promise<void> {
return knex.raw(`
DROP TABLE data_export;
DROP TABLE data_exports;
`);
}
46 changes: 46 additions & 0 deletions src/db/models/new/data-export/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {Model} from '../../..';

export const DataExportModelColumn = {
DataExportId: 'dataExportId',
Title: 'title',
TenantId: 'tenantId',
ChartId: 'chartId',
ChartRevId: 'chartRevId',
DatasetId: 'datasetId',
DatasetRevId: 'datasetRevId',
ConnectionId: 'connectionId',
ConnectionRevId: 'connectionRevId',
Params: 'params',
CreatedBy: 'createdBy',
CreatedAt: 'createdAt',
ExpiredAt: 'expiredAt',
JobId: 'jobId',
ResultLink: 'resultLink',
Error: 'error',
} as const;

export class DataExportModel extends Model {
static get tableName() {
return 'data_exports';
}

static get idColumn() {
return DataExportModelColumn.DataExportId;
}

[DataExportModelColumn.Title]!: string;
[DataExportModelColumn.TenantId]!: string;
[DataExportModelColumn.ChartId]!: string;
[DataExportModelColumn.ChartRevId]!: string;
[DataExportModelColumn.DatasetId]!: Nullable<string>;
[DataExportModelColumn.DatasetRevId]!: string;
[DataExportModelColumn.ConnectionId]!: string;
[DataExportModelColumn.ConnectionRevId]!: string;
[DataExportModelColumn.Params]!: Record<string, unknown>;
[DataExportModelColumn.CreatedBy]!: string;
[DataExportModelColumn.CreatedAt]!: string;
[DataExportModelColumn.ExpiredAt]!: string;
[DataExportModelColumn.JobId]!: string;
[DataExportModelColumn.ResultLink]!: Nullable<string>;
[DataExportModelColumn.Error]!: Record<string, unknown>;
}

0 comments on commit b246333

Please sign in to comment.