Skip to content

Commit 3578cc6

Browse files
committed
db/sqlc: priv map schemas and crud
Define the privacy mapper schemas and queries.
1 parent c0fba9a commit 3578cc6

File tree

7 files changed

+155
-1
lines changed

7 files changed

+155
-1
lines changed

db/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// daemon.
2323
//
2424
// NOTE: This MUST be updated when a new migration is added.
25-
LatestMigrationVersion = 3
25+
LatestMigrationVersion = 4
2626
)
2727

2828
// MigrationTarget is a functional option that can be passed to applyMigrations
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP INDEX IF EXISTS privacy_pairs_group_id_idx;
2+
DROP INDEX IF EXISTS privacy_pairs_unique_real;
3+
DROP INDEX IF EXISTS privacy_pairs_unique_pseudo;
4+
DROP TABLE IF EXISTS privacy_pairs;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- privacy_pairs stores the privacy map pairs for a given session group.
2+
CREATE TABLE IF NOT EXISTS privacy_pairs (
3+
-- The group ID of the session that this privacy pair is associated
4+
-- with.
5+
group_id BIGINT NOT NULL REFERENCES sessions(id) ON DELETE CASCADE,
6+
7+
-- The real value of the privacy pair.
8+
real_val TEXT NOT NULL,
9+
10+
-- The pseudo value of the privacy pair.
11+
pseudo_val TEXT NOT NULL
12+
);
13+
14+
-- We'll want easy access to the privacy pairs for a given group ID.
15+
CREATE INDEX IF NOT EXISTS privacy_pairs_group_id_idx ON privacy_pairs(group_id);
16+
17+
-- There should be no duplicate real values for a given group ID.
18+
CREATE UNIQUE INDEX privacy_pairs_unique_real ON privacy_pairs (
19+
group_id, real_val
20+
);
21+
22+
-- There should be no duplicate pseudo values for a given group ID.
23+
CREATE UNIQUE INDEX privacy_pairs_unique_pseudo ON privacy_pairs (
24+
group_id, pseudo_val
25+
);
26+

db/sqlc/models.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/sqlc/privacy_paris.sql.go

Lines changed: 96 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/sqlc/querier.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

db/sqlc/queries/privacy_paris.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-- name: InsertPrivacyPair :exec
2+
INSERT INTO privacy_pairs (group_id, real_val, pseudo_val)
3+
VALUES ($1, $2, $3);
4+
5+
-- name: GetRealForPseudo :one
6+
SELECT real_val
7+
FROM privacy_pairs
8+
WHERE group_id = $1 AND pseudo_val = $2;
9+
10+
-- name: GetPseudoForReal :one
11+
SELECT pseudo_val
12+
FROM privacy_pairs
13+
WHERE group_id = $1 AND real_val = $2;
14+
15+
-- name: GetAllPrivacyPairs :many
16+
SELECT real_val, pseudo_val
17+
FROM privacy_pairs
18+
WHERE group_id = $1;

0 commit comments

Comments
 (0)