From cf5bb85cede5b05b58ed2b40460d0b913e8b2cf6 Mon Sep 17 00:00:00 2001 From: jloup Date: Sun, 13 May 2018 15:47:59 +0100 Subject: User roles. --- db/migrations.go | 11 +++++++++++ db/user.go | 10 ++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'db') diff --git a/db/migrations.go b/db/migrations.go index f0df49c..e8fc40d 100644 --- a/db/migrations.go +++ b/db/migrations.go @@ -89,4 +89,15 @@ var migrations []Migration = []Migration{ "DROP TYPE market_config_status", }, }, + { + Version: 201805131000, + Up: []string{ + "CREATE TYPE user_role AS ENUM ('admin', 'user')", + "ALTER TABLE users ADD role user_role NOT NULL DEFAULT 'user'", + }, + Down: []string{ + "ALTER TABLE users DROP COLUMN role", + "DROP TYPE user_role", + }, + }, } diff --git a/db/user.go b/db/user.go index 64ca6a6..24ce491 100644 --- a/db/user.go +++ b/db/user.go @@ -11,10 +11,16 @@ const ( AwaitingConfirmation ) +type UserRole string + +const RoleUser UserRole = "user" +const RoleAdmin UserRole = "admin" + type User struct { Id int64 - Email string `sql:",unique,notnull"` - PasswordHash string `sql:",notnull"` + Role UserRole + Email string + PasswordHash string OtpSecret string IsOtpSetup bool Status UserStatus -- cgit v1.2.3