From 035551629c97c80c79986c69de5d58c6fe1e4a3a Mon Sep 17 00:00:00 2001 From: Alex Wright Date: Sun, 1 Mar 2020 19:36:10 +0100 Subject: [PATCH] Fixed option/nullable fields --- migrations/2020-03-01-120634_create_users/up.sql | 4 ++-- src/models.rs | 5 ++--- src/schema.rs | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/migrations/2020-03-01-120634_create_users/up.sql b/migrations/2020-03-01-120634_create_users/up.sql index 33db209..6064ee5 100644 --- a/migrations/2020-03-01-120634_create_users/up.sql +++ b/migrations/2020-03-01-120634_create_users/up.sql @@ -1,8 +1,8 @@ -- Your SQL goes here CREATE TABLE users ( id SERIAL PRIMARY KEY, - username VARCHAR(32), - is_active BOOLEAN DEFAULT TRUE, + username VARCHAR(32) UNIQUE NOT NULL, + is_active BOOLEAN DEFAULT TRUE NOT NULL, created_at TIMESTAMPTZ DEFAULT now(), updated_at TIMESTAMPTZ DEFAULT NULL ); diff --git a/src/models.rs b/src/models.rs index 609104d..d8402e9 100644 --- a/src/models.rs +++ b/src/models.rs @@ -3,13 +3,12 @@ use chrono::{ }; use diesel::prelude::*; use diesel::PgConnection; -use serde_derive::Serialize; #[derive(Queryable, Debug)] pub struct User { pub id: i32, - pub username: Option, - pub is_active: Option, + pub username: String, + pub is_active: bool, pub created_at: Option, pub updated_at: Option, } diff --git a/src/schema.rs b/src/schema.rs index b789b3b..7981f88 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -11,8 +11,8 @@ table! { table! { users (id) { id -> Int4, - username -> Nullable, - is_active -> Nullable, + username -> Varchar, + is_active -> Bool, created_at -> Nullable, updated_at -> Nullable, }