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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 1 addition & 1 deletion api/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export {Lock} from '../src/db/models/new/lock';
export {Favorite} from '../src/db/models/new/favorite';
export {UserSettings} from '../src/db/models/new/user-settings';
export {Comment, CommentType} from '../src/db/models/new/comment';

export {DataExport} from '../src/db/models/new/data-export';
export {EmbedModel, EmbedModelColumn} from '../src/db/models/new/embed';
export {
EmbeddingSecretModel,
Expand Down
40 changes: 40 additions & 0 deletions src/db/migrations/20241219092946_data_export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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,
imsitnikov marked this conversation as resolved.
Show resolved Hide resolved
chart_rev_id BIGINT NOT NULL,
dataset_id BIGINT,
dataset_rev_id BIGINT,
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
);

CREATE INDEX data_exports_chart_id_idx ON data_exports(chart_id);
CREATE INDEX data_exports_dataset_id_idx ON data_exports(dataset_id);
CREATE INDEX data_exports_connection_id_idx ON data_exports(connection_id);
CREATE INDEX data_exports_expired_at_idx ON data_exports(expired_at);
`);
}

export async function down(knex: Knex): Promise<void> {
return knex.raw(`
DROP INDEX data_exports_chart_id_idx;
DROP INDEX data_exports_dataset_id_idx;
DROP INDEX data_exports_connection_id_idx;
DROP INDEX data_exports_expired_at_idx;

DROP TABLE data_exports;
`);
}
28 changes: 28 additions & 0 deletions src/db/models/new/data-export/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {Model} from '../../..';

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

static get idColumn() {
return 'dataExportId';
}

dataExportId!: string;
title!: string;
tenantId!: string;
chartId!: string;
chartRevId!: string;
datasetId!: Nullable<string>;
datasetRevId!: string;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

datasetRevId!: Nullable<string>;?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, added

connectionId!: string;
connectionRevId!: string;
params!: Record<string, unknown>;
createdBy!: string;
createdAt!: string;
expiredAt!: string;
jobId!: string;
resultLink!: Nullable<string>;
error!: Nullable<Record<string, unknown>>;
}
Loading