Gastansicht, Verbesserungen bei Planung
This commit is contained in:
1 parent
b3afa3ef32
commit
c08d43e7dd
38 files changed
+3845
-219
No files matched your search
+89
-8
@@ -135,14 +135,17 @@ CREATE TABLE IF NOT EXISTS churches (
|
||||
CREATE TABLE IF NOT EXISTS people (
|
||||
tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
id TEXT NOT NULL,
|
||||
short_code TEXT NOT NULL DEFAULT '',
|
||||
first_name TEXT NOT NULL,
|
||||
last_name TEXT NOT NULL,
|
||||
roles TEXT NOT NULL,
|
||||
email TEXT NOT NULL DEFAULT '',
|
||||
preferred_church_ids TEXT NOT NULL DEFAULT '[]',
|
||||
preferred_weekdays TEXT NOT NULL DEFAULT '[]',
|
||||
preferred_weekday_periods TEXT NOT NULL DEFAULT '[]',
|
||||
preferred_service_titles TEXT NOT NULL DEFAULT '[]',
|
||||
max_per_month INTEGER NOT NULL DEFAULT 6,
|
||||
allow_beyond_preferences INTEGER NOT NULL DEFAULT 0,
|
||||
active INTEGER NOT NULL DEFAULT 1,
|
||||
notes TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (tenant_id, id)
|
||||
@@ -215,6 +218,7 @@ CREATE TABLE IF NOT EXISTS assignments (
|
||||
person_id TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
locked INTEGER NOT NULL DEFAULT 0,
|
||||
beyond_preferences INTEGER NOT NULL DEFAULT 0,
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL,
|
||||
PRIMARY KEY (tenant_id, id),
|
||||
@@ -315,6 +319,41 @@ CREATE TABLE IF NOT EXISTS secret_state (
|
||||
tenant_id TEXT PRIMARY KEY REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
initialized_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS contact_shares (
|
||||
tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
owner_person_id TEXT NOT NULL,
|
||||
viewer_user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
granted_at TEXT NOT NULL,
|
||||
PRIMARY KEY (tenant_id, owner_person_id, viewer_user_id)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_contact_shares_viewer ON contact_shares(viewer_user_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS contact_reviews (
|
||||
tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
owner_person_id TEXT NOT NULL,
|
||||
roster_hash TEXT NOT NULL,
|
||||
reviewed_at TEXT NOT NULL,
|
||||
PRIMARY KEY (tenant_id, owner_person_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS swap_requests (
|
||||
id TEXT PRIMARY KEY,
|
||||
tenant_id TEXT NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
|
||||
requester_user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
requester_person_id TEXT NOT NULL,
|
||||
target_user_id TEXT NOT NULL REFERENCES users(id) ON DELETE CASCADE,
|
||||
target_person_id TEXT NOT NULL,
|
||||
offered_assignment_id TEXT NOT NULL,
|
||||
wanted_assignment_id TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'pending',
|
||||
token_hash TEXT NOT NULL UNIQUE,
|
||||
created_at TEXT NOT NULL,
|
||||
responded_at TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_swap_requests_tenant ON swap_requests(tenant_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_swap_requests_requester ON swap_requests(requester_user_id, status);
|
||||
CREATE INDEX IF NOT EXISTS idx_swap_requests_target ON swap_requests(target_user_id, status);
|
||||
`
|
||||
|
||||
func (s *Store) migrate(ctx context.Context) error {
|
||||
@@ -344,8 +383,41 @@ func (s *Store) migrate(ctx context.Context) error {
|
||||
return fmt.Errorf("add users.%s: %w", column.name, err)
|
||||
}
|
||||
}
|
||||
// People gained a guest label, weekday time periods and permission to be
|
||||
// planned beyond their preferences. Assignments record when that happened.
|
||||
peopleColumns := []struct {
|
||||
name string
|
||||
definition string
|
||||
}{
|
||||
{"short_code", "TEXT NOT NULL DEFAULT ''"},
|
||||
{"preferred_weekday_periods", "TEXT NOT NULL DEFAULT '[]'"},
|
||||
{"allow_beyond_preferences", "INTEGER NOT NULL DEFAULT 0"},
|
||||
}
|
||||
for _, column := range peopleColumns {
|
||||
exists, err := s.hasColumn(ctx, "people", column.name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inspect people table: %w", err)
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
"ALTER TABLE people ADD COLUMN "+column.name+" "+column.definition); err != nil {
|
||||
return fmt.Errorf("add people.%s: %w", column.name, err)
|
||||
}
|
||||
}
|
||||
hasBeyond, err := s.hasColumn(ctx, "assignments", "beyond_preferences")
|
||||
if err != nil {
|
||||
return fmt.Errorf("inspect assignments table: %w", err)
|
||||
}
|
||||
if !hasBeyond {
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
"ALTER TABLE assignments ADD COLUMN beyond_preferences INTEGER NOT NULL DEFAULT 0"); err != nil {
|
||||
return fmt.Errorf("add assignments.beyond_preferences: %w", err)
|
||||
}
|
||||
}
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
"INSERT INTO schema_meta(key, value) VALUES('schemaVersion', '5') "+
|
||||
"INSERT INTO schema_meta(key, value) VALUES('schemaVersion', '7') "+
|
||||
"ON CONFLICT(key) DO UPDATE SET value=excluded.value"); err != nil {
|
||||
return fmt.Errorf("record schema version: %w", err)
|
||||
}
|
||||
@@ -365,7 +437,8 @@ func (s *Store) migrate(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
// Editors and linked readers hold key material; administrators never do.
|
||||
// Readers may only keep the scope of their linked person.
|
||||
// Readers keep their own person scope plus every scope that another reader
|
||||
// has explicitly shared with them.
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
"DELETE FROM key_wrappers WHERE user_id IN (SELECT id FROM users WHERE role='admin')"); err != nil {
|
||||
return fmt.Errorf("prune administrator key wrappers: %w", err)
|
||||
@@ -376,15 +449,23 @@ func (s *Store) migrate(ctx context.Context) error {
|
||||
}
|
||||
if _, err := s.db.ExecContext(ctx, `
|
||||
DELETE FROM key_wrappers WHERE user_id IN (
|
||||
SELECT u.id FROM users u WHERE u.role='reader' AND (
|
||||
u.linked_tenant_id='' OR u.linked_person_id='' OR NOT (
|
||||
key_wrappers.scope_type='person'
|
||||
AND key_wrappers.tenant_id=u.linked_tenant_id
|
||||
AND key_wrappers.scope_id=u.linked_person_id
|
||||
SELECT id FROM users WHERE role='reader'
|
||||
) AND NOT EXISTS (
|
||||
SELECT 1 FROM users u
|
||||
WHERE u.id=key_wrappers.user_id AND u.role='reader' AND u.active=1
|
||||
AND key_wrappers.scope_type='person'
|
||||
AND key_wrappers.tenant_id=u.linked_tenant_id
|
||||
AND (
|
||||
key_wrappers.scope_id=u.linked_person_id
|
||||
OR EXISTS (
|
||||
SELECT 1 FROM contact_shares cs
|
||||
WHERE cs.tenant_id=key_wrappers.tenant_id
|
||||
AND cs.owner_person_id=key_wrappers.scope_id
|
||||
AND cs.viewer_user_id=u.id
|
||||
)
|
||||
)
|
||||
)`); err != nil {
|
||||
return fmt.Errorf("prune unlinked reader key wrappers: %w", err)
|
||||
return fmt.Errorf("prune reader key wrappers: %w", err)
|
||||
}
|
||||
// Dispatch logs used to contain the full recipient address. Remove that
|
||||
// plaintext now that addresses are stored encrypted.
|
||||
|
||||
Reference in new issue
Block a user