UI Verbesserungen in Web App, Passwort/Lektoren
This commit is contained in:
1 parent
692b9b6ef8
commit
d7113afa5f
23 files changed
+1340
-116
No files matched your search
+47
-1
@@ -97,6 +97,9 @@ CREATE TABLE IF NOT EXISTS users (
|
||||
password_hash TEXT NOT NULL,
|
||||
role TEXT NOT NULL,
|
||||
active INTEGER NOT NULL DEFAULT 1,
|
||||
must_change_password INTEGER NOT NULL DEFAULT 1,
|
||||
linked_tenant_id TEXT NOT NULL DEFAULT '',
|
||||
linked_person_id TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL
|
||||
);
|
||||
|
||||
@@ -253,14 +256,57 @@ func (s *Store) migrate(ctx context.Context) error {
|
||||
if _, err := s.db.ExecContext(ctx, schema); err != nil {
|
||||
return fmt.Errorf("apply schema: %w", err)
|
||||
}
|
||||
// Existing databases predate the password-state and person-link columns.
|
||||
// CREATE TABLE IF NOT EXISTS does not modify them, so add the columns here.
|
||||
columns := []struct {
|
||||
name string
|
||||
definition string
|
||||
}{
|
||||
{"must_change_password", "INTEGER NOT NULL DEFAULT 1"},
|
||||
{"linked_tenant_id", "TEXT NOT NULL DEFAULT ''"},
|
||||
{"linked_person_id", "TEXT NOT NULL DEFAULT ''"},
|
||||
}
|
||||
for _, column := range columns {
|
||||
exists, err := s.hasColumn(ctx, "users", column.name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("inspect users table: %w", err)
|
||||
}
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
"ALTER TABLE users ADD COLUMN "+column.name+" "+column.definition); err != nil {
|
||||
return fmt.Errorf("add users.%s: %w", column.name, err)
|
||||
}
|
||||
}
|
||||
if _, err := s.db.ExecContext(ctx,
|
||||
"INSERT INTO schema_meta(key, value) VALUES('schemaVersion', '1') "+
|
||||
"INSERT INTO schema_meta(key, value) VALUES('schemaVersion', '2') "+
|
||||
"ON CONFLICT(key) DO UPDATE SET value=excluded.value"); err != nil {
|
||||
return fmt.Errorf("record schema version: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Store) hasColumn(ctx context.Context, table, column string) (bool, error) {
|
||||
rows, err := s.db.QueryContext(ctx, "PRAGMA table_info("+table+")")
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var cid, notNull, pk int
|
||||
var name, kind string
|
||||
var defaultValue sql.NullString
|
||||
if err := rows.Scan(&cid, &name, &kind, ¬Null, &defaultValue, &pk); err != nil {
|
||||
return false, err
|
||||
}
|
||||
if name == column {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, rows.Err()
|
||||
}
|
||||
|
||||
func (s *Store) transaction(ctx context.Context, fn func(*sql.Tx) error) error {
|
||||
tx, err := s.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user