mirror of https://github.com/nocodb/nocodb
Pranav C
7 months ago
committed by
GitHub
14 changed files with 767 additions and 39 deletions
@ -0,0 +1,64 @@
|
||||
import type { Knex } from 'knex'; |
||||
import { MetaTable } from '~/utils/globals'; |
||||
|
||||
const up = async (knex: Knex) => { |
||||
console.log('Adding index to view column tables...'); |
||||
console.time('Added index to Grid view columns'); |
||||
await knex.schema.alterTable(MetaTable.GRID_VIEW_COLUMNS, (table) => { |
||||
table.index(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
console.timeEnd('Added index to Grid view columns'); |
||||
|
||||
console.time('Added index to Gallery view columns'); |
||||
await knex.schema.alterTable(MetaTable.GALLERY_VIEW_COLUMNS, (table) => { |
||||
table.index(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
console.timeEnd('Added index to Gallery view columns'); |
||||
|
||||
console.time('Added index to Kanban view columns'); |
||||
await knex.schema.alterTable(MetaTable.KANBAN_VIEW_COLUMNS, (table) => { |
||||
table.index(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
console.timeEnd('Added index to Kanban view columns'); |
||||
|
||||
console.time('Added index to Form view columns'); |
||||
await knex.schema.alterTable(MetaTable.FORM_VIEW_COLUMNS, (table) => { |
||||
table.index(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
console.timeEnd('Added index to Form view columns'); |
||||
|
||||
console.time('Added index to Calendar view columns'); |
||||
await knex.schema.alterTable(MetaTable.CALENDAR_VIEW_COLUMNS, (table) => { |
||||
table.index(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
console.timeEnd('Added index to Calendar view columns'); |
||||
|
||||
console.time('Added index to Map view columns'); |
||||
await knex.schema.alterTable(MetaTable.MAP_VIEW_COLUMNS, (table) => { |
||||
table.index(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
console.timeEnd('Added index to Map view columns'); |
||||
}; |
||||
|
||||
const down = async (knex: Knex) => { |
||||
await knex.schema.alterTable(MetaTable.GRID_VIEW_COLUMNS, (table) => { |
||||
table.dropIndex(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
await knex.schema.alterTable(MetaTable.GALLERY_VIEW_COLUMNS, (table) => { |
||||
table.dropIndex(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
await knex.schema.alterTable(MetaTable.KANBAN_VIEW_COLUMNS, (table) => { |
||||
table.dropIndex(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
await knex.schema.alterTable(MetaTable.FORM_VIEW_COLUMNS, (table) => { |
||||
table.dropIndex(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
await knex.schema.alterTable(MetaTable.CALENDAR_VIEW_COLUMNS, (table) => { |
||||
table.dropIndex(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
await knex.schema.alterTable(MetaTable.MAP_VIEW_COLUMNS, (table) => { |
||||
table.dropIndex(['fk_view_id', 'fk_column_id']); |
||||
}); |
||||
}; |
||||
|
||||
export { up, down }; |
@ -0,0 +1,47 @@
|
||||
import request from 'supertest'; |
||||
import type View from '../../../src/models/View'; |
||||
import { APIContext } from 'nocodb-sdk' |
||||
|
||||
const updateViewColumns = async ( |
||||
context, |
||||
{ |
||||
view, |
||||
viewColumns, |
||||
}: { |
||||
view: View; |
||||
viewColumns: Record<string, any>[] | Record<string, Record<string, any>[]>; |
||||
}, |
||||
) => { |
||||
// generate key-value pair of column id and column
|
||||
const fields = Array.isArray(viewColumns) |
||||
? viewColumns.reduce((acc, column) => { |
||||
acc[column.fk_column_id] = column; |
||||
return acc; |
||||
}, {}) |
||||
: viewColumns; |
||||
|
||||
// configure view to hide selected fields
|
||||
await request(context.app) |
||||
.patch(`/api/v3/meta/views/${view.id}/columns`) |
||||
.set('xc-auth', context.token) |
||||
.send({ [APIContext.VIEW_COLUMNS]: fields }) |
||||
.expect(200); |
||||
}; |
||||
|
||||
const getViewColumns = async ( |
||||
context, |
||||
{ |
||||
view, |
||||
}: { |
||||
view: View; |
||||
}, |
||||
) => { |
||||
return ( |
||||
await request(context.app) |
||||
.get(`/api/v3/meta/views/${view.id}/columns`) |
||||
.set('xc-auth', context.token) |
||||
.expect(200) |
||||
).body; |
||||
}; |
||||
|
||||
export { updateViewColumns, getViewColumns }; |
Loading…
Reference in new issue