{"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696494070", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696494070, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ5NDA3MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T03:48:58Z", "updated_at": "2020-09-22T03:48:58Z", "author_association": "OWNER", "body": "One last thing. https://www.sqlite.org/lang_altertable.html#making_other_kinds_of_table_schema_change says that the first step should be:\r\n\r\n> If foreign key constraints are enabled, disable them using PRAGMA foreign_keys=OFF. \r\n\r\nAnd the last steps should be:\r\n\r\n> If foreign key constraints were originally enabled then run PRAGMA foreign_key_check to verify that the schema change did not break any foreign key constraints.\r\n>\r\n> Commit the transaction started in step 2.\r\n>\r\n> If foreign keys constraints were originally enabled, reenable them now. \r\n\r\nI need to implement that.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696490851", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696490851, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ5MDg1MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T03:33:54Z", "updated_at": "2020-09-22T03:33:54Z", "author_association": "OWNER", "body": "It would be neat if `.transform(pk=None)` converted a primary key table to a rowid table.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696488201", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696488201, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ4ODIwMQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T03:21:16Z", "updated_at": "2020-09-22T03:21:16Z", "author_association": "OWNER", "body": "Just needs documentation now.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696485791", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696485791, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ4NTc5MQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T03:10:15Z", "updated_at": "2020-09-22T03:10:15Z", "author_association": "OWNER", "body": "Design decision needed on foreign keys: what does the syntax look like for removing an existing foreign key?\r\n\r\nSince I already have a good implementation of `add_foreign_key()` I'm tempted to only support dropping them. Maybe like this:\r\n\r\n```python\r\ntable.transform(drop_foreign_keys=[(\"author_id\", \"author\", \"id\")])\r\n```\r\nIt's a bit crufty but it's such a rare use-case that I think this will be good enough.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696480925", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696480925, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ4MDkyNQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T02:45:47Z", "updated_at": "2020-09-22T02:45:47Z", "author_association": "OWNER", "body": "I'm not going to do `conversions=` because it would be inconsistent with how they work elsewhere. The SQL generated by this function looks like this:\r\n\r\n INSERT INTO dogs_new_tmp VALUES (a, b) SELECT a, b from dogs;\r\n\r\nSo passing `conversions={\"name\": \"upper(?)\"})` wouldn't make sense, since we're not using arguments hence there is no-where for that `?` to go.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696446658", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696446658, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0NjY1OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:13:55Z", "updated_at": "2020-09-22T00:14:21Z", "author_association": "OWNER", "body": "Idea: allow a `conversions=` parameter, as seen on `.insert_all()` and friends, which lets you apply a SQL transformation function as part of the operation. E.g.:\r\n\r\n```python\r\ntable.transform({\"age\": int}, conversions={\"name\": \"upper(?)\"})\r\n```\r\n\r\nhttps://sqlite-utils.readthedocs.io/en/stable/python-api.html#converting-column-values-using-sql-functions", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696445766", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696445766, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0NTc2Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:10:50Z", "updated_at": "2020-09-22T00:11:12Z", "author_association": "OWNER", "body": "A less horrible interface might be the following:\r\n```python\r\n# Ensure the 'age' column is not null:\r\ntable.transform(not_null={\"age\"})\r\n# The 'age' column is not null but I don't want it to be:\r\ntable.transform(not_null={\"age\": False})\r\n```\r\nSo if the argument is a set it means \"make sure these are all not null\" - if the argument is a dictionary it means \"set these to be null or not null depending on if their dictionary value is true or false\".", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696444842", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696444842, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0NDg0Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:07:43Z", "updated_at": "2020-09-22T00:09:05Z", "author_association": "OWNER", "body": "Syntax challenge: I could use `.transform(defaults={\"age\": None})` to indicate that the `age` column should have its default removed, but how would I tell `.transform()` that the `age` column, currently `not null`, should have the `not null` removed from it?\r\n\r\nI could do this: `.transform(not_not_null={\"age\"})` - it's a bit gross but it's also kind of funny. I actually like it!", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696444353", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696444353, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0NDM1Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:06:12Z", "updated_at": "2020-09-22T00:06:12Z", "author_association": "OWNER", "body": "I should support `not_null=` and `default=` arguments to the `.transform()` method because it looks like you can't use `ALTER TABLE` to change those.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696443845", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696443845, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0Mzg0NQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:04:31Z", "updated_at": "2020-09-22T00:04:44Z", "author_association": "OWNER", "body": "Good news: the `.columns` introspection does tell me those things:\r\n```\r\n>>> import sqlite_utils\r\n>>> db = sqlite_utils.Database(memory=True)\r\n>>> db.create_table(\"foo\", {\"id\": int, \"name\": str, \"age\": int}, defaults={\"age\": 1}, not_null={\"name\", \"age\"})\r\n\r\n>>> db[\"foo\"]\r\n
\r\n>>> print(db[\"foo\"].schema)\r\nCREATE TABLE [foo] (\r\n [id] INTEGER,\r\n [name] TEXT NOT NULL,\r\n [age] INTEGER NOT NULL DEFAULT 1\r\n)\r\n>>> db[\"foo\"].columns\r\n[Column(cid=0, name='id', type='INTEGER', notnull=0, default_value=None, is_pk=0),\r\n Column(cid=1, name='name', type='TEXT', notnull=1, default_value=None, is_pk=0),\r\n Column(cid=2, name='age', type='INTEGER', notnull=1, default_value='1', is_pk=0)]\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696443190", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696443190, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0MzE5MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:02:22Z", "updated_at": "2020-09-22T00:02:22Z", "author_association": "OWNER", "body": "How would I detect which columns are `not_null` and what their defaults are? I don`t think my introspection logic handles that yet.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696443042", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696443042, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0MzA0Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:01:50Z", "updated_at": "2020-09-22T00:01:50Z", "author_association": "OWNER", "body": "When you transform a table, it should keep its primary key, foreign keys, not_null and defaults. I don't think it needs to care about `hash_id` or `extracts=` since those don't affect the structure of the table as it is being created - well, `hash_id` does but if we are transforming an existing table we will get the `hash_id` column for free.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/pull/161#issuecomment-696442621", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/161", "id": 696442621, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQ0MjYyMQ==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-22T00:00:23Z", "updated_at": "2020-09-22T00:00:23Z", "author_association": "OWNER", "body": "I still need to figure out what to do about these various other table properties: https://github.com/simonw/sqlite-utils/blob/b34c9b40c206d7a9d7ee57a8c1f198ff1f522735/sqlite_utils/db.py#L775-L787", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 705975133, "label": "table.transform() method"}, "performed_via_github_app": null}