pgroll icon indicating copy to clipboard operation
pgroll copied to clipboard

Allow to create a table with a self reference column with a single operation

Open exekias opened this issue 1 year ago • 0 comments

Right now it's not possible to create a table referencing itself, like this:

{
    "$schema": "https://raw.githubusercontent.com/xataio/pgroll/main/schema.json",
    "name": "branches",
    "operations": [
        {
            "create_table": {
                "name": "users",
                "columns": [
                {
                    "name": "id",
                    "type": "text",
                    "pk": true
                },
                {
                    "name": "name",
                    "type": "text"
                },
                {
                    "name": "parent_id",
                    "type": "text",
                    "nullable": true,
                    "references": {
                        "name": "parent_id",
                        "table": "users",
                        "column": "id",
                        "on_delete": "SET NULL"
                    }
                }
            ]
            }
        }
    ]
}

This is still doable by adding a new migration to include the parent_id column, but ideally this can be done in one go

exekias avatar Nov 21 '24 14:11 exekias