How to use transactions to control bulk creating records into the corteza?

How to use transactions to control bulk creating records into corteza platform?When the one fails to create,the whole records should be rolled back?How to achieve it?Thanks a lot!

Hey @danniel, I don’t know if we can do that

but as a workaround I use, I retrieve data from an external system and do bulk create to corteza
so to handle failure cases, I ordered the data based on a specific field (e.g. created_time)
and before performing the bulk create I get last record of that field then do the bulk create

not sure if that could help

You currently can’t interact with transactions on your own.
If we manage, this will be available in the next release or the one after that (we are currently reworking record storage).

1 Like

@tjerman will that include physical tables?

Yes. Along with that, we’re also looking for a way to allow you to create a transaction, do whatever, and then commit/rollback the transaction.

2 Likes

There is an another problem about transactions with records.
The following is the test:
1、Calling the record creating interface,the url is /namespace/{namespaceID}/module/{moduleID}/record/
2、the request body is like this
{

"values": [

    {

        "name": "name",

        "value": "fdsafasf"

    },

    {

        "name": "number",

        "value": "A015743"

    }

],

"records": [

    {

        "refField": "org_id",

        "set": [

            {

                "name":"remarks",

                "value":""

            },

            {

                "name":"email",

                "value":"test@163.com"

            },

            {

                "name":"phone",

                "value":"1291481"

            },

            {

                "name":"department",

                "value":"1"

            }

        ],

        "module": {

            "moduleID": "255881161568420888",

            "namespaceID": "255450917715837976",

            "name": "department_info",

            "handle": "organize_department_info",

            "moduleType": "",

            "fields": [

                {

                    "fieldID": "255881161568879640",

                    "name": "email",

                    "kind": "String",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": false,

                    "isPrivate": false,

                    "isPrimary": false,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": true,

                    "options": {

                        "multiLine": false,

                        "useRichTextEditor": false,

                        "auto": false,

                        "isListNumber": false,

                        "key": "",

                        "name": "",

                        "multiDelimiter": "\n"

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                },

                {

                    "fieldID": "255881161568814104",

                    "name": "phone",

                    "kind": "String",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": false,

                    "isPrivate": false,

                    "isPrimary": false,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": true,

                    "options": {

                        "multiLine": false,

                        "useRichTextEditor": false,

                        "auto": false,

                        "isListNumber": false,

                        "key": "",

                        "name": "",

                        "multiDelimiter": "\n"

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                },

                {

                    "fieldID": "255881161568748568",

                    "name": "concact",

                    "kind": "String",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": true,

                    "isPrivate": false,

                    "isPrimary": false,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": true,

                    "options": {

                        "multiLine": false,

                        "useRichTextEditor": false,

                        "auto": false,

                        "isListNumber": false,

                        "key": "",

                        "name": "",

                        "multiDelimiter": "\n"

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                },

                {

                    "fieldID": "255881161568617496",

                    "name": "department",

                    "kind": "String",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": false,

                    "isPrivate": false,

                    "isPrimary": false,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": true,

                    "options": {

                        "multiLine": false,

                        "useRichTextEditor": false,

                        "auto": false,

                        "isListNumber": false,

                        "key": "",

                        "name": "",

                        "multiDelimiter": "\n"

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                },

                {

                    "fieldID": "255881161568551960",

                    "name": "org_id",

                    "kind": "Record",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": false,

                    "isPrivate": false,

                    "isPrimary": false,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": false,

                    "options": {

                        "moduleID": "255881161534866456",

                        "labelField": "org_id",

                        "queryFields": [

                            "org_id"

                        ],

                        "selectType": "default",

                        "multiDelimiter": "\n"

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                },

                {

                    "fieldID": "255881161568486424",

                    "name": "_department_info_id",

                    "kind": "Number",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": false,

                    "isPrivate": false,

                    "isPrimary": true,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": true,

                    "options": {

                        "format": "",

                        "prefix": "",

                        "suffix": "",

                        "precision": 0,

                        "multiDelimiter": "\n",

                        "isPositive": false

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                },

                {

                    "fieldID": "265173111400301636",

                    "name": "remarks",

                    "kind": "String",

                    "label": "",

                    "defaultValue": [

                        

                    ],

                    "maxLength": 0,

                    "isRequired": false,

                    "isPrivate": false,

                    "isPrimary": false,

                    "isBusiPrimary": false,

                    "isMulti": false,

                    "isSystem": false,

                    "isSortable": true,

                    "options": {

                        "multiLine": false,

                        "useRichTextEditor": false,

                        "auto": false,

                        "isListNumber": false,

                        "key": "",

                        "name": "",

                        "multiDelimiter": "\n"

                    },

                    "expressions": {

                        

                    },

                    "extension": {

                        

                    },

                    "canUpdateRecordValue": true,

                    "canReadRecordValue": true

                }

            ],

            "meta": {

                

            },

            "labels": {

                

            },

            "createdAt": "2021-11-01T05:50:57.000Z",

            "updatedAt": "2022-01-04T12:28:37.000Z",

            "canUpdateModule": true,

            "canDeleteModule": true,

            "canCreateRecord": true,

            "canReadRecord": true,

            "canUpdateRecord": true,

            "canDeleteRecord": true,

            "canGrant": true

        },

        "idPrefix": "rl:1"

    }

]

}
3、The module with the values and the records data is different. In the url /namespace/{namespaceID}/module/{moduleID}/record/ that {moduleID} refers to the module which has the field in the values but not in the records,because there are different modules.So under my test case,in the records of the request body json data,I didn’t put the field which the field type is required in that module into the records,so the response must be failed because the required field is not supported.

The result is that these values data outside the records of request body json have been put into database successfully,but the records data of request body json have not.

4、I think if the records data in the request body json occurs an error,these values data outside the records of the request body json shoud not be put into the database.So how can solve this problem or bug?

The data in records was not saved because the request is malformed.
Refer to here for more.

I’ll ask around to see what the expected behaviour would be.
For now, use some workaround like the one suggested by @munawir