File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change
1
+ import TableMetadata from '@/models/table-metadata'
1
2
import { getTableOperations } from '@/models/tiles/factory'
2
3
3
4
import type { MutationResolvers } from '../../__generated__/types.generated'
@@ -35,18 +36,23 @@ const createTable: MutationResolvers['createTable'] = async (
35
36
36
37
const tableOperations = getTableOperations ( databaseType )
37
38
38
- // TODO: should i wrap this in a transaction?
39
- const table = await context . currentUser . $relatedQuery ( 'tables' ) . insertGraph ( {
40
- name : tableName ,
41
- role : 'owner' ,
42
- db : databaseType ,
43
- columns : isBlankTable ? [ ] : PLACEHOLDER_COLUMNS ,
44
- } )
39
+ const table = await TableMetadata . transaction ( async ( trx ) => {
40
+ const pendingTable = await context . currentUser
41
+ . $relatedQuery ( 'tables' , trx )
42
+ . insertGraph ( {
43
+ name : tableName ,
44
+ role : 'owner' ,
45
+ db : databaseType ,
46
+ columns : isBlankTable ? [ ] : PLACEHOLDER_COLUMNS ,
47
+ } )
45
48
46
- await tableOperations . createTable (
47
- table . id ,
48
- isBlankTable ? [ ] : table . columns . map ( ( column ) => column . id ) ,
49
- )
49
+ await tableOperations . createTable (
50
+ pendingTable . id ,
51
+ isBlankTable ? [ ] : pendingTable . columns . map ( ( column ) => column . id ) ,
52
+ )
53
+
54
+ return pendingTable
55
+ } )
50
56
51
57
if ( ! isBlankTable ) {
52
58
await tableOperations . createTableRows ( {
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class TableColumnMetadata extends Base {
32
32
modelClass : TableMetadata ,
33
33
join : {
34
34
from : `${ this . tableName } .table_id` ,
35
- to : `${ TableColumnMetadata . tableName } .id` ,
35
+ to : `${ TableMetadata . tableName } .id` ,
36
36
} ,
37
37
} ,
38
38
} )
You can’t perform that action at this time.
0 commit comments