Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data export migration #223

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/db/migrations/20241219092946_data_export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type {Knex} from 'knex';

export async function up(knex: Knex): Promise<void> {
return knex.raw(`
CREATE TABLE data_exports (
data_export_id BIGINT NOT NULL PRIMARY KEY DEFAULT get_id(),
title TEXT NOT NULL,
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,
dataset_rev_id BIGINT NOT NULL,
connection_id BIGINT NOT NULL,
connection_rev_id BIGINT NOT NULL,
params JSONB NOT NULL DEFAULT '{}'::jsonb,
created_by TEXT NOT NULL,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
expired_at TIMESTAMPTZ NOT NULL,
job_id TEXT NOT NULL,
result_link TEXT,
error JSONB
);
`);
}

export async function down(knex: Knex): Promise<void> {
return knex.raw(`
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>;
}
Loading