Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schema RFC #1

Closed
roertbb opened this issue Dec 4, 2020 · 0 comments
Closed

Schema RFC #1

roertbb opened this issue Dec 4, 2020 · 0 comments

Comments

@roertbb
Copy link
Owner

roertbb commented Dec 4, 2020

CREATE KEYSPACE IF NOT EXISTS casspoll 
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };
USE casspoll;

CREATE TABLE IF NOT EXISTS Polls (
    pollId uuid,
    title text,
    description text,
    dueTime timestamp,
    pollType int,

    PRIMARY KEY (pollId)
);

CREATE TABLE IF NOT EXISTS Answers (
    answerId uuid,
    answer text,
    pollId uuid,

    PRIMARY KEY (pollId, answerId)
)

-- idea #1
-- "server" prevents from inserting due to exceeding the deadline
CREATE TABLE IF NOT EXISTS Votes (
    pollId uuid,
    answerId uuid,
    votesNo counter,
    PRIMARY KEY (pollId, answerId)
);

-- voting
-- now := time.Now().Unix()
SELECT dueTime FROM polls WHERE pollId = ?;
-- if now < dueTime {}
--     for answer := range selectedAnswers {
UPDATE Votes SET votesNo = votesNo + 1 WHERE pollId = ? AND answerId = ?
--     }
-- }

-- calculating votes
-- for answer := range answers {
SELECT votesNo FROM Votes WHERE pollId = ? AND answerId = ?
-- }

-- idea #2
CREATE TABLE IF NOT EXISTS Votes (
    pollId uuid,
    answerId uuid,
    voterId uuid,

    PRIMARY KEY (pollId, answerId)
);

-- voting
-- now := time.Now().Unix()
-- for answer := range selectedAnswers {
INSERT INTO Votes (voterId) VALUES (?) WHERE pollId = ? AND answerId = ? USING TIMESTAMP now;
-- }

-- calculating votes
-- for answer := range answers {
-- SELECT COUNT(*) FROM Votes WHERE pollId = ? AND answerId = ? AND writetime(voterId) < dueTime
-- }

SELECT COUNT(*) FROM Votes WHERE pollId = ? AND writetime(voterId) < dueTime GROUP BY answerId

-- other options
-- + Votes include text for answer, no need for Answers table
@roertbb roertbb closed this as completed Dec 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant