Needs check: can we drop the PK from a table? #19
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
We don't support creating a table with no PK, so an attempt to drop it should be met with a friendly error message.
Checked end-to-end. Dropping a PK column is already refused, in both modes — so the core concern here is satisfied.
do_drop_columnexecutor (src/db.rs): it pre-checkscol_info.primary_keyand returns "cannot drop primary-key columnT.col. Drop the table or change the primary key first."drop column T: id→Command::DropColumn, and advancedALTER TABLE T DROP COLUMN id→AlterTableAction::DropColumn→database.drop_column(...)(runtime.rs). Same executor, same guard.e2e_alter_drop_primary_key_column_is_refused/e2e_alter_drop_compound_primary_key_member_is_refusedintests/it/sql_alter_table.rs. The single-column worker path was already covered bydrop_column_refuses_primary_key+ the message is locked inengine_vocabulary_audit.rs.One premise correction: the issue says "we don't support creating a table with no PK" — that's true for simple mode only. The advanced SQL surface follows standard SQL and does allow a PK-less table (
create table t (a int)— verified end-to-end). This is fine: SQLite keys every ordinary table by its implicitrowid, so a PK-less table is valid and fully handled (show data … limitfalls back to rowid order;update/deletetarget rows by rowid). A PK-less table simply has no "PK column" to drop, so the guard is moot there.This advanced-mode difference is now documented in
docs/simple-mode-limitations.md(Table creation section).Recommendation: close — the drop-PK guard is in place, refused in both modes, and now covered by tests; the no-PK-in-advanced-mode capability is intentional and documented.