This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
The following commit(s) were added to refs/heads/trunk by this push:
new 67117dc Align on singular for table names.
67117dc is described below
commit 67117dc5ef9c28aea168e90b45ef37b4def1bf85
Author: Greg Stein <[email protected]>
AuthorDate: Thu Sep 25 17:31:53 2025 -0500
Align on singular for table names.
We tend to operate on these tables as one row at a time, so we are
looking for "an election", "a person", "an issue", or "a vote". Thus,
shift the table names to the singular form.
* schema.sql: simple updates to tables, references, indexes.
* election.py: lots of sneaky little places to change. Do eet.
---
v3/schema.sql | 14 +++++++-------
v3/steve/election.py | 44 ++++++++++++++++++++++----------------------
2 files changed, 29 insertions(+), 29 deletions(-)
diff --git a/v3/schema.sql b/v3/schema.sql
index 0650386..c06896f 100644
--- a/v3/schema.sql
+++ b/v3/schema.sql
@@ -54,7 +54,7 @@
3. Closed. The election is closed.
DEFINITION: salt and opened_key are NOT NULL. closed is 1.
*/
-CREATE TABLE elections (
+CREATE TABLE election (
/* The Election ID; 10 hex characters. We do not use AUTOINCREMENT,
so that URLs for Elections cannot be deduced. */
@@ -104,7 +104,7 @@ CREATE TABLE elections (
/* --------------------------------------------------------------------- */
/* The set of Issues to vote upon for a given Election. */
-CREATE TABLE issues (
+CREATE TABLE issue (
/* The Issue ID; 10 hex characters. We do not use AUTOINCREMENT,
so that URLs for Issues cannot be deduced. */
@@ -134,13 +134,13 @@ CREATE TABLE issues (
kv TEXT,
/* Enforce/declare/document relationships. */
- FOREIGN KEY (eid) REFERENCES elections(eid)
+ FOREIGN KEY (eid) REFERENCES election(eid)
ON DELETE RESTRICT
ON UPDATE NO ACTION
) STRICT;
-CREATE INDEX idx_issues_eid ON issues(eid);
+CREATE INDEX idx_issue_eid ON issue(eid);
/* --------------------------------------------------------------------- */
@@ -186,7 +186,7 @@ CREATE TABLE mayvote (
ON DELETE RESTRICT
ON UPDATE NO ACTION,
- FOREIGN KEY (iid) REFERENCES issues(iid)
+ FOREIGN KEY (iid) REFERENCES issue(iid)
ON DELETE RESTRICT
ON UPDATE NO ACTION
@@ -197,7 +197,7 @@ CREATE TABLE mayvote (
/* The registered votes, once the Election has been opened. Note that
duplicates of (person, issue) may occur (the vote_token will be the
same), as re-voting is allowed. Only the latest is used. */
-CREATE TABLE votes (
+CREATE TABLE vote (
/* The key is auto-incrementing to provide a record of insert-order,
so that we have an ordering to find the "most recent" when
@@ -215,6 +215,6 @@ CREATE TABLE votes (
) STRICT;
/* ### review queries.yaml to figure out proper indexes */
-CREATE INDEX idx_by_vote_token ON votes (vote_token);
+CREATE INDEX idx_by_vote_token ON vote (vote_token);
/* --------------------------------------------------------------------- */
diff --git a/v3/steve/election.py b/v3/steve/election.py
index 2f76c31..09fa972 100644
--- a/v3/steve/election.py
+++ b/v3/steve/election.py
@@ -49,13 +49,13 @@ class Election:
self.c_salt_mayvote = self.db.add_statement(
'UPDATE mayvote SET salt = ? WHERE _ROWID_ = ?')
self.c_open = self.db.add_statement(
- 'UPDATE ELECTIONS SET salt = ?, opened_key = ?'
+ 'UPDATE election SET salt = ?, opened_key = ?'
' WHERE eid = ?')
self.c_close = self.db.add_statement(
- 'UPDATE ELECTIONS SET closed = 1'
+ 'UPDATE election SET closed = 1'
' WHERE eid = ?')
self.c_add_issue = self.db.add_statement(
- '''INSERT INTO ISSUES VALUES (?, ?, ?, ?, ?, ?)
+ '''INSERT INTO issue VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT DO UPDATE SET
title=excluded.title,
description=excluded.description,
@@ -63,37 +63,37 @@ class Election:
kv=excluded.kv
''')
self.c_delete_issue = self.db.add_statement(
- 'DELETE FROM ISSUES WHERE iid = ?')
+ 'DELETE FROM issue WHERE iid = ?')
self.c_add_vote = self.db.add_statement(
- 'INSERT INTO VOTES VALUES (NULL, ?, ?)')
+ 'INSERT INTO vote VALUES (NULL, ?, ?)')
self.c_add_mayvote = self.db.add_statement(
'INSERT INTO mayvote (pid, iid, salt) VALUES (?, ?, NULL)')
self.c_add_mayvote_all = self.db.add_statement(
'INSERT INTO mayvote (pid, iid, salt)'
- ' SELECT ?, iid, NULL FROM issues WHERE eid = ?')
+ ' SELECT ?, iid, NULL FROM issue WHERE eid = ?')
self.c_delete_mayvote = self.db.add_statement(
'''DELETE FROM mayvote
WHERE iid IN (
SELECT iid
- FROM issues
+ FROM issue
WHERE eid = ?
)''')
self.c_delete_issues = self.db.add_statement(
- 'DELETE FROM issues WHERE eid = ?')
+ 'DELETE FROM issue WHERE eid = ?')
self.c_delete_election = self.db.add_statement(
- 'DELETE FROM elections WHERE eid = ?')
+ 'DELETE FROM election WHERE eid = ?')
# Cursors for running queries.
- self.q_metadata = self.db.add_query('elections',
- 'SELECT * FROM ELECTIONS WHERE eid = ?')
- self.q_issues = self.db.add_query('issues',
- 'SELECT * FROM ISSUES WHERE eid = ? ORDER BY iid')
- self.q_get_issue = self.db.add_query('issues',
- 'SELECT * FROM ISSUES WHERE iid = ?')
+ self.q_metadata = self.db.add_query('election',
+ 'SELECT * FROM election WHERE eid = ?')
+ self.q_issues = self.db.add_query('issue',
+ 'SELECT * FROM issue WHERE eid = ? ORDER BY iid')
+ self.q_get_issue = self.db.add_query('issue',
+ 'SELECT * FROM issue WHERE iid = ?')
self.q_get_mayvote = self.db.add_query('mayvote',
- 'SELECT * FROM MAYVOTE WHERE pid = ? AND iid = ?')
+ 'SELECT * FROM mayvote WHERE pid = ? AND iid = ?')
self.q_tally = self.db.add_query('mayvote',
- 'SELECT * FROM MAYVOTE WHERE iid = ?')
+ 'SELECT * FROM mayvote WHERE iid = ?')
# Manual queries: these queries do not follow the 'SELECT * '
# pattern, so we cannot use .add_query() and will not have
@@ -101,16 +101,16 @@ class Election:
self.m_find_issues = self.db.add_statement(
'''SELECT m.*
FROM mayvote m
- JOIN issues i ON m.iid = i.iid
+ JOIN issue i ON m.iid = i.iid
WHERE m.pid = ? AND i.eid = ?
''')
self.m_has_voted = self.db.add_statement(
- '''SELECT 1 FROM VOTES
+ '''SELECT 1 FROM vote
WHERE vote_token = ?
LIMIT 1
''')
self.m_recent_vote = self.db.add_statement(
- '''SELECT ciphertext FROM VOTES
+ '''SELECT ciphertext FROM vote
WHERE vote_token = ?
ORDER BY _ROWID_ DESC
LIMIT 1
@@ -118,7 +118,7 @@ class Election:
self.m_all_issues = self.db.add_statement(
'''SELECT m._ROWID_
FROM mayvote m
- JOIN issues i ON m.iid = i.iid
+ JOIN issue i ON m.iid = i.iid
WHERE i.eid = ?;
''')
@@ -429,7 +429,7 @@ class Election:
while True:
eid = crypto.create_id()
try:
- conn.execute('INSERT INTO elections (eid, title, owner_pid)'
+ conn.execute('INSERT INTO election (eid, title, owner_pid)'
' VALUES (?, ?, ?)',
(eid, title, owner_pid,))
break