{"html_url": "https://github.com/simonw/sqlite-utils/issues/565#issuecomment-1618380888", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/565", "id": 1618380888, "node_id": "IC_kwDOCGYnMM5gdohY", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-03T14:09:11Z", "updated_at": "2023-07-03T14:09:31Z", "author_association": "OWNER", "body": "For the CLI:\r\n\r\n```bash\r\nsqlite-utils rename-table data.db old_table_name new_table_name\r\n```\r\n\r\nFor the Python code, should it go on Table or on Database?\r\n```python\r\ndb[\"foo\"].rename_table(\"bar\")\r\n\r\ndb.rename_table(\"foo\", \"bar\")\r\n```\r\nI think I like the second better, it's slightly more clear.\r\n\r\nAlso need a design for an option for the `.transform()` method to indicate that the new table should be created with a new name without dropping the old one.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1786258502, "label": "Table renaming: db.rename_table() and sqlite-utils rename-table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/565#issuecomment-1646656246", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/565", "id": 1646656246, "node_id": "IC_kwDOCGYnMM5iJfr2", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:32:07Z", "updated_at": "2023-07-22T19:32:07Z", "author_association": "OWNER", "body": "Trying out a simple first implementation:\r\n```pycon\r\n>>> from sqlite_utils import Database\r\n>>> db = Database(memory=True, tracer=print)\r\nPRAGMA recursive_triggers=on; None\r\n>>> db[\"foo\"].insert({\"id\": 1})\r\nselect name from sqlite_master where type = 'view' None\r\nselect name from sqlite_master where type = 'table' None\r\nselect name from sqlite_master where type = 'view' None\r\nselect name from sqlite_master where type = 'table' None\r\nselect name from sqlite_master where type = 'view' None\r\nCREATE TABLE [foo] (\r\n [id] INTEGER\r\n);\r\n None\r\nselect name from sqlite_master where type = 'view' None\r\nINSERT INTO [foo] ([id]) VALUES (?); [1]\r\nselect name from sqlite_master where type = 'table' None\r\nselect name from sqlite_master where type = 'table' None\r\nPRAGMA table_info([foo]) None\r\n\r\n>>> db.rename_table(\"foo\", \"baz\")\r\nALTER TABLE [foo] RENAME TO [baz] None\r\n>>> print(db.schema)\r\nselect sql from sqlite_master where sql is not null None\r\nCREATE TABLE \"baz\" (\r\n [id] INTEGER\r\n);\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1786258502, "label": "Table renaming: db.rename_table() and sqlite-utils rename-table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/565#issuecomment-1646657324", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/565", "id": 1646657324, "node_id": "IC_kwDOCGYnMM5iJf8s", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:39:06Z", "updated_at": "2023-07-22T19:39:06Z", "author_association": "OWNER", "body": "> Also need a design for an option for the `.transform()` method to indicate that the new table should be created with a new name without dropping the old one.\r\n\r\nI think `keep_table=\"name_of_table\"` is good for this.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1786258502, "label": "Table renaming: db.rename_table() and sqlite-utils rename-table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/565#issuecomment-1646657849", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/565", "id": 1646657849, "node_id": "IC_kwDOCGYnMM5iJgE5", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:42:02Z", "updated_at": "2023-07-22T19:42:02Z", "author_association": "OWNER", "body": "Manually testing new `rename-table` command:\r\n```\r\n$ sqlite-utils schema /tmp/f.db \r\nCREATE TABLE [foo] (\r\n [id] INTEGER,\r\n [name] TEXT\r\n);\r\n$ sqlite-utils rename-table /tmp/f.db bad-table hi\r\nError: Table \"bad-table\" could not be renamed. no such table: bad-table\r\n$ sqlite-utils rename-table /tmp/f.db foo foo \r\nError: Table \"foo\" could not be renamed. there is already another table or index with this name: foo\r\n$ sqlite-utils rename-table /tmp/f.db foo bar\r\n$ sqlite-utils schema /tmp/f.db \r\nCREATE TABLE \"bar\" (\r\n [id] INTEGER,\r\n [name] TEXT\r\n);\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1786258502, "label": "Table renaming: db.rename_table() and sqlite-utils rename-table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/565#issuecomment-1646658978", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/565", "id": 1646658978, "node_id": "IC_kwDOCGYnMM5iJgWi", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:48:54Z", "updated_at": "2023-07-22T19:48:54Z", "author_association": "OWNER", "body": "Python method documentation:\r\n- https://sqlite-utils.datasette.io/en/latest/reference.html#sqlite_utils.db.Database.rename_table\r\n- https://sqlite-utils.datasette.io/en/latest/python-api.html#renaming-a-table", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1786258502, "label": "Table renaming: db.rename_table() and sqlite-utils rename-table"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/565#issuecomment-1646659809", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/565", "id": 1646659809, "node_id": "IC_kwDOCGYnMM5iJgjh", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:53:56Z", "updated_at": "2023-07-22T19:53:56Z", "author_association": "OWNER", "body": "CLI documentation:\r\n\r\n- https://sqlite-utils.datasette.io/en/latest/cli.html#renaming-a-table\r\n- https://sqlite-utils.datasette.io/en/latest/cli-reference.html#rename-table", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1786258502, "label": "Table renaming: db.rename_table() and sqlite-utils rename-table"}, "performed_via_github_app": null}