Skip to content

Commit

Permalink
Revise flashcard and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Jul 5, 2024
1 parent 65e0656 commit 690a2d7
Show file tree
Hide file tree
Showing 11 changed files with 941 additions and 150 deletions.
2 changes: 1 addition & 1 deletion backend/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fmt: ## Format code
test: ## Run tests
printf "${GREEN}Run all tests\n\n${WHITE}"; \
go clean -testcache; \
${ENV} go test -v ./...; \
${ENV} go test -race ./...; \
printf "${GREEN}Done\n"; \

.PHONY: help
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,21 @@ CREATE TABLE users
CREATE TABLE cards
(
id SERIAL PRIMARY KEY,
front TEXT NOT NULL,
back TEXT NOT NULL,
review_date TIMESTAMP NOT NULL,
interval_days INT NOT NULL DEFAULT 1,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
front TEXT NOT NULL,
back TEXT NOT NULL,
review_date TIMESTAMP NOT NULL,
interval_days INT NOT NULL DEFAULT 1,
created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
user_id VARCHAR(255) NOT NULL,
CONSTRAINT fk_user
FOREIGN KEY (user_id)
REFERENCES users (id)
ON DELETE CASCADE
);

CREATE
OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated
= CURRENT_TIMESTAMP;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER update_users_updated_at
BEFORE UPDATE
ON users
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();

CREATE TRIGGER update_cards_updated_at
BEFORE UPDATE
ON cards
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();

-- +goose Down
-- SQL section 'Down' is executed when this migration is rolled back.

DROP TRIGGER IF EXISTS update_users_updated_at ON users;
DROP TRIGGER IF EXISTS update_cards_updated_at ON cards;
DROP FUNCTION IF EXISTS update_updated_at_column;
DROP TABLE IF EXISTS cards;
DROP TABLE IF EXISTS users;
Loading

0 comments on commit 690a2d7

Please sign in to comment.