{"html_url": "https://github.com/simonw/sqlite-utils/issues/586#issuecomment-1683404978", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/586", "id": 1683404978, "node_id": "IC_kwDOCGYnMM5kVriy", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T06:13:46Z", "updated_at": "2023-08-18T06:13:46Z", "author_association": "OWNER", "body": "I shipped the view recreating fix in `datasette-edit-schema`, so at least I can start exercising that fix and see if it has any weird issues.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1856075668, "label": ".transform() fails to drop column if table is part of a view"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/586#issuecomment-1683398866", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/586", "id": 1683398866, "node_id": "IC_kwDOCGYnMM5kVqDS", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T06:05:50Z", "updated_at": "2023-08-18T06:06:42Z", "author_association": "OWNER", "body": "Options:\r\n- Provide a `recreate_views: bool` parameter to `table.transform()` controlling if views that might reference this table are stashed and dropped and recreated within a transaction as part of the operation. But should that be `True` or `False` by default?\r\n- Read that `PRAGMA` and automatically do that view workaround if it's turned on\r\n- Toggle that `PRAGMA` off for the duration of the `.transform()` operation and on again at the end. Does it only affect the current connection?\r\n- Try the `transform()` in a transaction, detect the `\"error in view\"`, `\"no such table\"`error, if spotted then do the VIEW workaround and try again\r\n\r\nI'm on the fence as to which of these I like the most. I'm tempted to go with the one which just drops VIEWS and recreates them all the time, because it feels simpler.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1856075668, "label": ".transform() fails to drop column if table is part of a view"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/586#issuecomment-1683396150", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/586", "id": 1683396150, "node_id": "IC_kwDOCGYnMM5kVpY2", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T06:02:18Z", "updated_at": "2023-08-18T06:06:31Z", "author_association": "OWNER", "body": "More notes in here:\r\n- https://github.com/simonw/datasette-edit-schema/issues/35#issuecomment-1683392873\r\n\r\nNot all Python/SQLite installations exhibit this problem by default!\r\n\r\nIt turns out this is controlled by the `legacy_alter_table` pragma: https://sqlite.org/pragma.html#pragma_legacy_alter_table\r\n\r\nIf that PRAGMA is turned on (default in newer SQLites) then `alter table` will error if you try to rename a table that is referenced in a view.\r\n\r\nHere's a one-liner to test if it is on or not:\r\n\r\n```bash\r\npython -c 'import sqlite3; print(sqlite3.connect(\":memory:\").execute(\"PRAGMA legacy_alter_table\").fetchall())'\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1856075668, "label": ".transform() fails to drop column if table is part of a view"}, "performed_via_github_app": null}