{"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696435194", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696435194, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzNTE5NA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:34:14Z", "updated_at": "2020-09-21T23:35:00Z", "author_association": "OWNER", "body": "I think the fiddliest part of the implementation here is code that takes the existing `columns_dict` of the table and the incoming `columns=` and `drop=` and `rename=` parameters and produces the columns dictionary for the new table, ready to be fed to `.create_table()`.\r\n\r\nThis logic probably also needs to return a structure that can be used to build the `INSERT INTO ... SELECT ... FROM` query.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696434638", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696434638, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzNDYzOA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:32:26Z", "updated_at": "2020-09-21T23:32:26Z", "author_association": "OWNER", "body": "A test that confirms that this mechanism can turn a `rowid` into a non-rowid table would be good too.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696434237", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696434237, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzNDIzNw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:31:07Z", "updated_at": "2020-09-21T23:31:57Z", "author_association": "OWNER", "body": "Does it make sense to support the `pk=` argument for changing the primary key?\r\n\r\nIf the user requests a primary key that doesn't make sense I think an integrity error will be raised when the SQL is being executed, which should hopefully cancel the transaction and raise an error. Need to check that this is what happens.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696434097", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696434097, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzNDA5Nw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:30:40Z", "updated_at": "2020-09-21T23:30:40Z", "author_association": "OWNER", "body": "Since I have a `column_order=None` argument already, maybe I can ignore the order of the columns in that first argument and use that instead?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696433778", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696433778, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzMzc3OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:29:39Z", "updated_at": "2020-09-21T23:29:39Z", "author_association": "OWNER", "body": "The `columns=` argument is optional - so you can do just a rename operation like so:\r\n```\r\ntable.transform(rename={\"age\": \"dog_age\"})\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696433542", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696433542, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzMzU0Mg==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:28:58Z", "updated_at": "2020-09-21T23:28:58Z", "author_association": "OWNER", "body": "If you want to both change the type of a column AND rename it in the same operation, how would you do that? I think like this:\r\n```python\r\ntable.transform({\"age\": int}, rename={\"age\": \"dog_age\"})\r\n```\r\nSo any rename logic is applied at the end, after the type transformation or re-ordering logic.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696432690", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696432690, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzMjY5MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:26:32Z", "updated_at": "2020-09-21T23:27:38Z", "author_association": "OWNER", "body": "To expand on what that first argument - the `columns` argument - does. Say you have a table like this:\r\n```\r\nid integer\r\nname text\r\nage text\r\n```\r\nAny columns omitted from the `columns=` argument are left alone - they have to be explicitly dropped using `drop=` if you want to drop them.\r\n\r\nAny new columns are added (at the end of the table):\r\n\r\n```\r\ntable.tranform({\"size\": float})\r\n```\r\n\r\nAny columns that have their type changed will have their type changed:\r\n\r\n```\r\ntable.tranform({\"age\": int})\r\n```\r\n\r\nShould I also re-order columns if the order doesn't match? I think so. Open question as to what happens to columns that aren't mentioned at all in the dictionary though - what order should they go in?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696431058", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696431058, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzMTA1OA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:21:37Z", "updated_at": "2020-09-21T23:21:37Z", "author_association": "OWNER", "body": "I may need to do something special for `rowid` tables to ensure that the `rowid` values in the transformed table match those from the old table.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696430843", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696430843, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQzMDg0Mw==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T23:21:00Z", "updated_at": "2020-09-21T23:21:00Z", "author_association": "OWNER", "body": "For FTS tables associated with the table that is being transformed, should I automatically drop the old FTS table and recreate it against the new one or will it just magically continue to work after the table is renamed?", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696423138", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696423138, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQyMzEzOA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T22:59:17Z", "updated_at": "2020-09-21T23:01:06Z", "author_association": "OWNER", "body": "I'm going to sketch out a prototype of this new API design in that branch.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696423066", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696423066, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQyMzA2Ng==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T22:59:01Z", "updated_at": "2020-09-21T22:59:01Z", "author_association": "OWNER", "body": "I'm rethinking the API design now. Maybe it could look like this:\r\n\r\nTo change the type of the `author_id` column from `text` to `int`:\r\n```python\r\nbooks.transform({\"author_id\": int})\r\n```\r\nThis would leave the existing columns alone, but would change the type of this column.\r\n\r\nTo rename `author_id` to `author_identifier`:\r\n```python\r\nbooks.transform(rename={\"author_id\": \"author_identifier\"})\r\n```\r\nTo drop a column:\r\n```python\r\nbooks.transform(drop=[\"author_id\"])\r\n```\r\nSince the parameters all operate on columns they don't need to be called `drop_column` and `rename_column`.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/114#issuecomment-696421240", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/114", "id": 696421240, "node_id": "MDEyOklzc3VlQ29tbWVudDY5NjQyMTI0MA==", "user": {"value": 9599, "label": "simonw"}, "created_at": "2020-09-21T22:53:48Z", "updated_at": "2020-09-21T22:53:48Z", "author_association": "OWNER", "body": "I've decided to call this `table.transform()` - I was over-thinking whether people would remember that `.transform()` actually transforms the table, but that's what documentation is for.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 621989740, "label": "table.transform() method for advanced alter table"}, "performed_via_github_app": null}