{"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646642666", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646642666, "node_id": "IC_kwDOCGYnMM5iJcXq", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T18:13:19Z", "updated_at": "2023-07-22T18:13:19Z", "author_association": "OWNER", "body": "https://sqlite-utils.datasette.io/en/stable/cli-reference.html#create-table\r\n\r\n```bash\r\nsqlite-utils create-table ... --replace\r\n```\r\nThat also has `--ignore`:\r\n\r\n```\r\n --ignore If table already exists, do nothing\r\n --replace If table already exists, replace it\r\n --transform If table already exists, try to transform the schema\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646642959", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646642959, "node_id": "IC_kwDOCGYnMM5iJccP", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T18:14:49Z", "updated_at": "2023-07-22T18:14:49Z", "author_association": "OWNER", "body": "Here's where those are implemented for the `create-table` CLI command: https://github.com/simonw/sqlite-utils/blob/f7af23837deab5c98dae9441d1f68318065d7d8c/sqlite_utils/cli.py#L1543-L1564", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646652105", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646652105, "node_id": "IC_kwDOCGYnMM5iJerJ", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:05:13Z", "updated_at": "2023-07-22T19:05:13Z", "author_association": "OWNER", "body": "I think this is `replace=True` and `ignore=True` to match the CLI. And refactoring the CLI to use them.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646653382", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646653382, "node_id": "IC_kwDOCGYnMM5iJe_G", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:13:20Z", "updated_at": "2023-07-22T19:13:20Z", "author_association": "OWNER", "body": "Demo:\r\n```pycon\r\n>>> from sqlite_utils import Database\r\n>>> db = Database(memory=True)\r\n>>> db[\"foo\"].create({\"id\": int})\r\n\r\n>>> db[\"foo\"].create({\"id\": int})\r\nTraceback (most recent call last):\r\n File \"\", line 1, in \r\n File \"/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/db.py\", line 1647, in create\r\n self.db.create_table(\r\n File \"/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/db.py\", line 1030, in create_table\r\n self.execute(sql)\r\n File \"/Users/simon/Dropbox/Development/sqlite-utils/sqlite_utils/db.py\", line 510, in execute\r\n return self.conn.execute(sql)\r\n ^^^^^^^^^^^^^^^^^^^^^^\r\nsqlean.dbapi2.OperationalError: table [foo] already exists\r\n>>> db[\"foo\"].create({\"id\": int}, ignore=True)\r\n
\r\n>>> db[\"foo\"].create({\"id\": int, \"name\": str}, replace=True)\r\n
\r\n>>> db[\"foo\"].create({\"id\": int, \"name\": str, \"age\": int}, transform=True)\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": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646653610", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646653610, "node_id": "IC_kwDOCGYnMM5iJfCq", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:14:56Z", "updated_at": "2023-07-22T19:14:56Z", "author_association": "OWNER", "body": "Manual testing of CLI command as well:\r\n```\r\n$ sqlite-utils create-table /tmp/f.db foo id integer \r\n$ sqlite-utils create-table /tmp/f.db foo id integer\r\nError: Table \"foo\" already exists. Use --replace to delete and replace it.\r\n$ sqlite-utils create-table /tmp/f.db foo id integer --replace\r\n$ sqlite-utils create-table /tmp/f.db foo id \r\n$ sqlite-utils schema /tmp/f.db\r\nCREATE TABLE [foo] (\r\n [id] INTEGER\r\n);\r\n$ sqlite-utils create-table /tmp/f.db foo id integer name str --transform\r\nError: column types must be one of ('INTEGER', 'TEXT', 'FLOAT', 'BLOB')\r\n$ sqlite-utils create-table /tmp/f.db foo id integer name text --transform\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 create-table /tmp/f.db foo id integer name text --ignore \r\n$ sqlite-utils create-table /tmp/f.db foo id integer name text --replace\r\n$ sqlite-utils schema /tmp/f.db \r\nCREATE TABLE [foo] (\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": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646654818", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646654818, "node_id": "IC_kwDOCGYnMM5iJfVi", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:22:40Z", "updated_at": "2023-07-22T19:22:40Z", "author_association": "OWNER", "body": "I think this broke a test:\r\n```\r\n$ pytest tests/test_tracer.py \r\n=============================================== test session starts ================================================\r\nplatform darwin -- Python 3.11.4, pytest-7.2.2, pluggy-1.0.0\r\nrootdir: /Users/simon/Dropbox/Development/sqlite-utils\r\nplugins: icdiff-0.6, hypothesis-6.68.2\r\ncollected 2 items \r\n\r\ntests/test_tracer.py F. [100%]\r\n\r\n===================================================== FAILURES =====================================================\r\n___________________________________________________ test_tracer ____________________________________________________\r\n\r\n def test_tracer():\r\n collected = []\r\n db = Database(\r\n memory=True, tracer=lambda sql, params: collected.append((sql, params))\r\n )\r\n db[\"dogs\"].insert({\"name\": \"Cleopaws\"})\r\n db[\"dogs\"].enable_fts([\"name\"])\r\n db[\"dogs\"].search(\"Cleopaws\")\r\n> assert collected == [\r\n (\"PRAGMA recursive_triggers=on;\", None),\r\n (\"select name from sqlite_master where type = 'view'\", None),\r\n (\"select name from sqlite_master where type = 'table'\", None),\r\n (\"select name from sqlite_master where type = 'view'\", None),\r\n (\"CREATE TABLE [dogs] (\\n [name] TEXT\\n);\\n \", None),\r\n (\"select name from sqlite_master where type = 'view'\", None),\r\n (\"INSERT INTO [dogs] ([name]) VALUES (?);\", [\"Cleopaws\"]),\r\n (\"select name from sqlite_master where type = 'view'\", None),\r\n (\r\n \"CREATE VIRTUAL TABLE [dogs_fts] USING FTS5 (\\n [name],\\n content=[dogs]\\n)\",\r\n None,\r\n ),\r\n (\r\n \"INSERT INTO [dogs_fts] (rowid, [name])\\n SELECT rowid, [name] FROM [dogs];\",\r\n None,\r\n ),\r\n (\"select name from sqlite_master where type = 'view'\", None),\r\n ]\r\nE assert equals failed\r\nE [ [ \r\nE ('PRAGMA recursive_triggers=on;', None), ('PRAGMA recursive_triggers=on;', None), \r\nE ( \r\nE \"select name from sqlite_master where type = \r\nE 'view'\", \r\nE None, ...\r\nE \r\nE ...Full output truncated (13 lines hidden), use '-vv' to show\r\n\r\ntests/test_tracer.py:12: AssertionError\r\n============================================= short test summary info ==============================================\r\nFAILED tests/test_tracer.py::test_tracer - assert equals failed\r\n=========================================== 1 failed, 1 passed in 0.05s ============================================\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/568#issuecomment-1646655272", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/568", "id": 1646655272, "node_id": "IC_kwDOCGYnMM5iJfco", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-07-22T19:25:35Z", "updated_at": "2023-07-22T19:25:35Z", "author_association": "OWNER", "body": "Here's why that test broke: https://github.com/simonw/sqlite-utils/blob/58b577279fcd5ef6ce88f88b28668dffebfe7f44/sqlite_utils/db.py#L960-L964\r\n\r\nI added an extra `if self[name].exists()` check to the `db.create_table()` method.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1816851056, "label": "table.create(..., replace=True)"}, "performed_via_github_app": null}