{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683197882", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683197882, "node_id": "IC_kwDOCGYnMM5kU4-6", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:25:53Z", "updated_at": "2023-08-18T01:25:53Z", "author_association": "OWNER", "body": "Probably most relevant here is this snippet from:\r\n```bash\r\nsqlite-utils create-table --help\r\n```\r\n```\r\n  --default <TEXT TEXT>...  Default value that should be set for a column\r\n  --fk <TEXT TEXT TEXT>...  Column, other table, other column to set as a\r\n                            foreign key\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683195669", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683195669, "node_id": "IC_kwDOCGYnMM5kU4cV", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:24:57Z", "updated_at": "2023-08-18T01:24:57Z", "author_association": "OWNER", "body": "Currently:\r\n```bash\r\nsqlite-utils transform --help\r\n```\r\n```\r\nUsage: sqlite-utils transform [OPTIONS] PATH TABLE\r\n\r\n  Transform a table beyond the capabilities of ALTER TABLE\r\n\r\n  Example:\r\n\r\n      sqlite-utils transform mydb.db mytable \\\r\n          --drop column1 \\\r\n          --rename column2 column_renamed\r\n\r\nOptions:\r\n  --type <TEXT CHOICE>...   Change column type to INTEGER, TEXT, FLOAT or BLOB\r\n  --drop TEXT               Drop this column\r\n  --rename <TEXT TEXT>...   Rename this column to X\r\n  -o, --column-order TEXT   Reorder columns\r\n  --not-null TEXT           Set this column to NOT NULL\r\n  --not-null-false TEXT     Remove NOT NULL from this column\r\n  --pk TEXT                 Make this column the primary key\r\n  --pk-none                 Remove primary key (convert to rowid table)\r\n  --default <TEXT TEXT>...  Set default value for this column\r\n  --default-none TEXT       Remove default from this column\r\n  --drop-foreign-key TEXT   Drop foreign key constraint for this column\r\n  --sql                     Output SQL without executing it\r\n  --load-extension TEXT     Path to SQLite extension, with optional\r\n                            :entrypoint\r\n  -h, --help                Show this message and exit.\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683198740", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683198740, "node_id": "IC_kwDOCGYnMM5kU5MU", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:26:47Z", "updated_at": "2023-08-18T01:26:47Z", "author_association": "OWNER", "body": "The only CLI feature that supports providing just the column name appears to be this:\r\n```bash\r\nsqlite-utils add-foreign-key --help\r\n```\r\n```\r\nUsage: sqlite-utils add-foreign-key [OPTIONS] PATH TABLE COLUMN [OTHER_TABLE]\r\n                                    [OTHER_COLUMN]\r\n\r\n  Add a new foreign key constraint to an existing table\r\n\r\n  Example:\r\n\r\n      sqlite-utils add-foreign-key my.db books author_id authors id\r\n\r\n  WARNING: Could corrupt your database! Back up your database file first.\r\n```\r\nI can drop that WARNING now since I'm not writing to `sqlite_master` any more.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683200128", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683200128, "node_id": "IC_kwDOCGYnMM5kU5iA", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:29:00Z", "updated_at": "2023-08-18T01:29:00Z", "author_association": "OWNER", "body": "I'm not going to implement the `foreign_keys=` option that entirely replaces existing foreign keys - I'll just do a `--add-foreign-key` multi-option.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683201239", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683201239, "node_id": "IC_kwDOCGYnMM5kU5zX", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:30:46Z", "updated_at": "2023-08-18T01:30:46Z", "author_association": "OWNER", "body": "Help can now look like this:\r\n```\r\n  --drop-foreign-key TEXT         Drop foreign key constraint for this column\r\n  --add-foreign-key <TEXT TEXT TEXT>...\r\n                                  Add a foreign key constraint from a column\r\n                                  to another table with another column\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683212074", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683212074, "node_id": "IC_kwDOCGYnMM5kU8cq", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:43:54Z", "updated_at": "2023-08-18T01:43:54Z", "author_association": "OWNER", "body": "Some manual testing:\r\n```bash\r\nsqlite-utils create-table /tmp/t.db places id integer name text country integer city integer continent integer --pk id\r\nsqlite-utils schema /tmp/t.db\r\n```\r\n```sql\r\nCREATE TABLE [places] (\r\n   [id] INTEGER PRIMARY KEY,\r\n   [name] TEXT,\r\n   [country] INTEGER,\r\n   [city] INTEGER,\r\n   [continent] INTEGER\r\n);\r\n```\r\n```bash\r\nsqlite-utils create-table /tmp/t.db country id integer name text\r\nsqlite-utils create-table /tmp/t.db city id integer name text\r\nsqlite-utils create-table /tmp/t.db continent id integer name text\r\nsqlite-utils schema /tmp/t.db\r\n```\r\n```sql\r\nCREATE TABLE [places] (\r\n   [id] INTEGER PRIMARY KEY,\r\n   [name] TEXT,\r\n   [country] INTEGER,\r\n   [city] INTEGER,\r\n   [continent] INTEGER\r\n);\r\nCREATE TABLE [country] (\r\n   [id] INTEGER,\r\n   [name] TEXT\r\n);\r\nCREATE TABLE [city] (\r\n   [id] INTEGER,\r\n   [name] TEXT\r\n);\r\nCREATE TABLE [continent] (\r\n   [id] INTEGER,\r\n   [name] TEXT\r\n);\r\n```\r\n```bash\r\nsqlite-utils transform /tmp/t.db places --add-foreign-key country country id --add-foreign-key continent continent id\r\nsqlite-utils schema /tmp/t.db\r\n```\r\n```sql\r\nCREATE TABLE [country] (\r\n   [id] INTEGER,\r\n   [name] TEXT\r\n);\r\nCREATE TABLE [city] (\r\n   [id] INTEGER,\r\n   [name] TEXT\r\n);\r\nCREATE TABLE [continent] (\r\n   [id] INTEGER,\r\n   [name] TEXT\r\n);\r\nCREATE TABLE \"places\" (\r\n   [id] INTEGER PRIMARY KEY,\r\n   [name] TEXT,\r\n   [country] INTEGER REFERENCES [country]([id]),\r\n   [city] INTEGER,\r\n   [continent] INTEGER REFERENCES [continent]([id])\r\n);\r\n```\r\n```bash\r\nsqlite-utils transform /tmp/t.db places --drop-foreign-key country\r\nsqlite-utils schema /tmp/t.db places\r\n```\r\n```sql\r\nCREATE TABLE \"places\" (\r\n   [id] INTEGER PRIMARY KEY,\r\n   [name] TEXT,\r\n   [country] INTEGER,\r\n   [city] INTEGER,\r\n   [continent] INTEGER REFERENCES [continent]([id])\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": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}
{"html_url": "https://github.com/simonw/sqlite-utils/issues/585#issuecomment-1683217284", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/585", "id": 1683217284, "node_id": "IC_kwDOCGYnMM5kU9uE", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-08-18T01:50:21Z", "updated_at": "2023-08-18T01:50:21Z", "author_association": "OWNER", "body": "And a test of the `--sql` option:\r\n```bash\r\nsqlite-utils create-table /tmp/t.db places id integer name text country integer city integer continent integer --pk id\r\nsqlite-utils create-table /tmp/t.db country id integer name text\r\nsqlite-utils create-table /tmp/t.db city id integer name text\r\nsqlite-utils create-table /tmp/t.db continent id integer name text\r\nsqlite-utils transform /tmp/t.db places --add-foreign-key country country id --add-foreign-key continent continent id --sql\r\n```\r\nOutputs:\r\n```sql\r\nCREATE TABLE [places_new_6a705d2f5a13] (\r\n   [id] INTEGER PRIMARY KEY,\r\n   [name] TEXT,\r\n   [country] INTEGER REFERENCES [country]([id]),\r\n   [city] INTEGER,\r\n   [continent] INTEGER REFERENCES [continent]([id])\r\n);\r\nINSERT INTO [places_new_6a705d2f5a13] ([id], [name], [country], [city], [continent])\r\n   SELECT [id], [name], [country], [city], [continent] FROM [places];\r\nDROP TABLE [places];\r\nALTER TABLE [places_new_6a705d2f5a13] RENAME TO [places];\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1855894222, "label": "CLI equivalents to `transform(add_foreign_keys=)`"}, "performed_via_github_app": null}