Schema: public_id + version columns with UNIQUE constraint, delete_timestamp for soft-delete. Tools: store_flashcard accepts optional public_id, update_flashcard creates a new version preserving history, delete_flashcard inserts a tombstone row and removes the Qdrant point. Qdrant: point ID is public_id (only latest version indexed).
11 lines
469 B
SQL
11 lines
469 B
SQL
-- +goose Up
|
|
ALTER TABLE flashcard ADD COLUMN public_id INTEGER NOT NULL DEFAULT 0;
|
|
ALTER TABLE flashcard ADD COLUMN version INTEGER NOT NULL DEFAULT 1;
|
|
UPDATE flashcard SET public_id = _id WHERE public_id = 0;
|
|
CREATE UNIQUE INDEX IF NOT EXISTS idx_flashcard_public_id_version ON flashcard(public_id, version);
|
|
|
|
-- +goose Down
|
|
DROP INDEX IF EXISTS idx_flashcard_public_id_version;
|
|
ALTER TABLE flashcard DROP COLUMN version;
|
|
ALTER TABLE flashcard DROP COLUMN public_id;
|