SQL refactor

master
E. Almqvist 3 years ago
parent eebab9d185
commit 64e429f474
  1. 10
      src/db_models.rb
  2. 2
      src/sql/tables/User.sql

@ -1,15 +1,15 @@
# User model # User model
class User < EntityModel class User < EntityModel
attr_reader :email, :name, :bio_text, :avatar_url, :pw_hash, :reputation attr_reader :email, :name, :bio_text, :balance, :avatar_url, :pw_hash, :reputation
def initialize(data) def initialize(data)
super data super data
@email = data["email"] @email = data["email"]
@name = data["name"] @name = data["name"]
@bio_text = data["bio_text"] @bio_text = data["bio_text"]
@balance = data["balance"] @balance = data["balance"].to_f
@avatar_url = data["avatar_url"] @avatar_url = data["avatar_url"]
@reputation = data["reputation"] @reputation = data["reputation"].to_f
@pw_hash = data["pw_hash"] @pw_hash = data["pw_hash"]
end end
@ -17,10 +17,6 @@ class User < EntityModel
return @avatar_url return @avatar_url
end end
def balance
@balance.to_f
end
def role def role
user_roles = roles user_roles = roles
if user_roles.length > 0 then if user_roles.length > 0 then

@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS "User" (
"pw_hash" TEXT NOT NULL UNIQUE, "pw_hash" TEXT NOT NULL UNIQUE,
"name" TEXT NOT NULL DEFAULT 'Unknown', "name" TEXT NOT NULL DEFAULT 'Unknown',
"bio_text" TEXT NOT NULL DEFAULT 'No information given.', "bio_text" TEXT NOT NULL DEFAULT 'No information given.',
"balance" REAL NOT NULL DEFAULT 0, "balance" FLOAT NOT NULL DEFAULT 0,
"avatar_url" TEXT NOT NULL DEFAULT '/avatars/default.png', "avatar_url" TEXT NOT NULL DEFAULT '/avatars/default.png',
"reputation" INTEGER NOT NULL DEFAULT 0, "reputation" INTEGER NOT NULL DEFAULT 0,
PRIMARY KEY("id" AUTOINCREMENT) PRIMARY KEY("id" AUTOINCREMENT)

Loading…
Cancel
Save