diffable-sql


Namediffable-sql JSON
Version 0.2.0 PyPI version JSON
download
home_page
SummaryOutput normalised diffable database schemas
upload_time2023-06-05 14:32:29
maintainer
docs_urlNone
authorTom Forbes
requires_python>=3.10,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Diffable SQL

This is a small tool that outputs SQL from a number of databases in a sorted, diff-friendly order.

## Install

The tool supports any database [that SQLAlchemy supports](https://docs.sqlalchemy.org/en/20/dialects/index.html).
You must install the correct connector for your database:

```
$ pip install diffable-sql
$ pip install psycopg2-binary # postgres
$ pip install mysqlclient # mysql
```

## Usage

You can pass any number of DSNs as arguments, for example `postgresql:///db-name`. The tool will output normalised SQL
DDL statements for each DSN.

```shell
$ diffable-sql sqlite:///db.sqlite3
CREATE TABLE sometable (
	foo VARCHAR,
	id BIGINT NOT NULL
);

ALTER TABLE sometable ADD CONSTRAINT c PRIMARY KEY (id);
ALTER TABLE sometable ADD CONSTRAINT c UNIQUE (foo);
CREATE INDEX i ON sometable (foo);
```

Specifically:
- The tables and columns will be sorted by name
- Indexes and constraints will be renamed as `i` and `c`
- Deferrable constraint information will be hidden
- Identity columns will be hidden

These allow schemas to be more easily diffed.

## JSON output

Passing `--output-format=json` will output a json structure for each table, containing information on the column
types, SQL, nullability, indexes and constraints:

```shell
$ poetry run diffable-sql sqlite:///tools/db.sqlite3 --output-format=json | jq
```

Outputs:
```json
{
  "name": "sometable",
  "database": "tools/db.sqlite3",
  "columns": {
    "id": {
      "type": "BIGINT",
      "sql": "id BIGINT NOT NULL",
      "nullable": false
    },
    "foo": {
      "type": "VARCHAR",
      "sql": "foo VARCHAR",
      "nullable": true
    }
  },
  "indexes": [
    {
      "name": "foobar",
      "type": "Index",
      "sql": "CREATE INDEX foobar ON sometable (foo)",
      "columns": [
        "foo"
      ],
      "expressions": []
    }
  ],
  "constraints": [
    {
      "name": null,
      "type": "PrimaryKeyConstraint",
      "sql": "ALTER TABLE sometable ADD PRIMARY KEY (id)",
      "columns": [
        "id"
      ],
      "expression": null
    },
    {
      "name": null,
      "type": "UniqueConstraint",
      "sql": "ALTER TABLE sometable ADD UNIQUE (foo)",
      "columns": [
        "foo"
      ],
      "expression": null
    }
  ]
}
```

## Args

```console
$ diffable-sql --help
Usage: diffable-sql [OPTIONS] [dsn]...

Options:
  --no-rename-indexes TEXT        Don't rename indexes
  --no-rename-constraints TEXT    Don't rename constraints
  --no-ignore-deferrable-constraints TEXT
                                  Include deferrable constraint information
  --no-ignore-identity-columns TEXT
                                  Don't ignore identity column information
  --output-format [sql|json]
  --help                          Show this message and exit.

```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "diffable-sql",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Tom Forbes",
    "author_email": "tom@tomforb.es",
    "download_url": "https://files.pythonhosted.org/packages/43/3f/bade6b922c25b1e00c2850865ccfe63f94a61f7a108d9727d4952e4e8e8f/diffable_sql-0.2.0.tar.gz",
    "platform": null,
    "description": "# Diffable SQL\n\nThis is a small tool that outputs SQL from a number of databases in a sorted, diff-friendly order.\n\n## Install\n\nThe tool supports any database [that SQLAlchemy supports](https://docs.sqlalchemy.org/en/20/dialects/index.html).\nYou must install the correct connector for your database:\n\n```\n$ pip install diffable-sql\n$ pip install psycopg2-binary # postgres\n$ pip install mysqlclient # mysql\n```\n\n## Usage\n\nYou can pass any number of DSNs as arguments, for example `postgresql:///db-name`. The tool will output normalised SQL\nDDL statements for each DSN.\n\n```shell\n$ diffable-sql sqlite:///db.sqlite3\nCREATE TABLE sometable (\n\tfoo VARCHAR,\n\tid BIGINT NOT NULL\n);\n\nALTER TABLE sometable ADD CONSTRAINT c PRIMARY KEY (id);\nALTER TABLE sometable ADD CONSTRAINT c UNIQUE (foo);\nCREATE INDEX i ON sometable (foo);\n```\n\nSpecifically:\n- The tables and columns will be sorted by name\n- Indexes and constraints will be renamed as `i` and `c`\n- Deferrable constraint information will be hidden\n- Identity columns will be hidden\n\nThese allow schemas to be more easily diffed.\n\n## JSON output\n\nPassing `--output-format=json` will output a json structure for each table, containing information on the column\ntypes, SQL, nullability, indexes and constraints:\n\n```shell\n$ poetry run diffable-sql sqlite:///tools/db.sqlite3 --output-format=json | jq\n```\n\nOutputs:\n```json\n{\n  \"name\": \"sometable\",\n  \"database\": \"tools/db.sqlite3\",\n  \"columns\": {\n    \"id\": {\n      \"type\": \"BIGINT\",\n      \"sql\": \"id BIGINT NOT NULL\",\n      \"nullable\": false\n    },\n    \"foo\": {\n      \"type\": \"VARCHAR\",\n      \"sql\": \"foo VARCHAR\",\n      \"nullable\": true\n    }\n  },\n  \"indexes\": [\n    {\n      \"name\": \"foobar\",\n      \"type\": \"Index\",\n      \"sql\": \"CREATE INDEX foobar ON sometable (foo)\",\n      \"columns\": [\n        \"foo\"\n      ],\n      \"expressions\": []\n    }\n  ],\n  \"constraints\": [\n    {\n      \"name\": null,\n      \"type\": \"PrimaryKeyConstraint\",\n      \"sql\": \"ALTER TABLE sometable ADD PRIMARY KEY (id)\",\n      \"columns\": [\n        \"id\"\n      ],\n      \"expression\": null\n    },\n    {\n      \"name\": null,\n      \"type\": \"UniqueConstraint\",\n      \"sql\": \"ALTER TABLE sometable ADD UNIQUE (foo)\",\n      \"columns\": [\n        \"foo\"\n      ],\n      \"expression\": null\n    }\n  ]\n}\n```\n\n## Args\n\n```console\n$ diffable-sql --help\nUsage: diffable-sql [OPTIONS] [dsn]...\n\nOptions:\n  --no-rename-indexes TEXT        Don't rename indexes\n  --no-rename-constraints TEXT    Don't rename constraints\n  --no-ignore-deferrable-constraints TEXT\n                                  Include deferrable constraint information\n  --no-ignore-identity-columns TEXT\n                                  Don't ignore identity column information\n  --output-format [sql|json]\n  --help                          Show this message and exit.\n\n```\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Output normalised diffable database schemas",
    "version": "0.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0c47b114e60eac52a8880da2f09c64c8029435a1c2f4746d46122b7185a0366e",
                "md5": "2ddcbe080a49b9a97a454fb67bdc4f41",
                "sha256": "d898942fde9b198420ec3f9127682614bd3f048c568506f68171121c5812cf2c"
            },
            "downloads": -1,
            "filename": "diffable_sql-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2ddcbe080a49b9a97a454fb67bdc4f41",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 4078,
            "upload_time": "2023-06-05T14:32:27",
            "upload_time_iso_8601": "2023-06-05T14:32:27.608010Z",
            "url": "https://files.pythonhosted.org/packages/0c/47/b114e60eac52a8880da2f09c64c8029435a1c2f4746d46122b7185a0366e/diffable_sql-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "433fbade6b922c25b1e00c2850865ccfe63f94a61f7a108d9727d4952e4e8e8f",
                "md5": "0857a64b0d22ed7050db3fd12ef9e644",
                "sha256": "f1023f3e023a0ad5cbf5e2ad183939a513bef10c7ab32e21fe99ab38ffe2369d"
            },
            "downloads": -1,
            "filename": "diffable_sql-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0857a64b0d22ed7050db3fd12ef9e644",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 3292,
            "upload_time": "2023-06-05T14:32:29",
            "upload_time_iso_8601": "2023-06-05T14:32:29.167217Z",
            "url": "https://files.pythonhosted.org/packages/43/3f/bade6b922c25b1e00c2850865ccfe63f94a61f7a108d9727d4952e4e8e8f/diffable_sql-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-05 14:32:29",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "diffable-sql"
}
        
Elapsed time: 0.18974s