From 601ca87235915ed6ccf96e9cc5be90cd47a284f0 Mon Sep 17 00:00:00 2001 From: Gellert Ilya Date: Fri, 10 Apr 2026 20:55:47 +0300 Subject: [PATCH] feat(migrations): add sql script for init card progress --- .../migrations/20260331233522_init_schema.sql | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/internal/repository/migrations/20260331233522_init_schema.sql b/backend/internal/repository/migrations/20260331233522_init_schema.sql index 2bfec79..2f78282 100644 --- a/backend/internal/repository/migrations/20260331233522_init_schema.sql +++ b/backend/internal/repository/migrations/20260331233522_init_schema.sql @@ -43,9 +43,26 @@ CREATE TABLE IF NOT EXISTS card_progress -- B-Tree index to efficiently fetch cards that are due for review. CREATE INDEX IF NOT EXISTS idx_progress_next_review ON card_progress (next_review_at); +-- +goose StatementBegin +CREATE OR REPLACE FUNCTION init_card_progress() + RETURNS TRIGGER AS $$ +BEGIN + INSERT INTO card_progress (card_id, interval, easiness, repetitions, next_review_at) + VALUES (NEW.id, 0, 2.5, 0, NOW()); + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER trigger_init_card_progress + AFTER INSERT ON card_contents + FOR EACH ROW +EXECUTE FUNCTION init_card_progress(); +-- +goose StatementEnd + -- +goose Down DROP TABLE IF EXISTS card_progress; DROP TABLE IF EXISTS card_contents; DROP EXTENSION IF EXISTS vector; -DROP EXTENSION IF EXISTS "uuid-ossp"; \ No newline at end of file +DROP EXTENSION IF EXISTS "uuid-ossp"; +DROP FUNCTION IF EXISTS init_card_progress(); \ No newline at end of file