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

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

Open
exekias opened this issue Nov 21, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@exekias
Copy link
Member

exekias commented Nov 21, 2024

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 exekias added the enhancement New feature or request label Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant