From cca93aa1d8dbb9651fe950880ae24f6347713257 Mon Sep 17 00:00:00 2001
From: kirbylife <kirbylife@protonmail.com>
Date: Thu, 22 Dec 2022 15:46:42 -0600
Subject: [PATCH] add views filed in the database

---
 migrations/.gitkeep                                       | 0
 .../down.sql                                              | 0
 .../up.sql                                                | 2 ++
 src/schema.rs                                             | 8 +++++---
 templates/admin/edit_post.html.tera                       | 1 +
 5 files changed, 8 insertions(+), 3 deletions(-)
 delete mode 100644 migrations/.gitkeep
 rename migrations/{2019-11-13-074151_create_posts => 2022-12-22-062417_create_posts}/down.sql (100%)
 rename migrations/{2019-11-13-074151_create_posts => 2022-12-22-062417_create_posts}/up.sql (86%)

diff --git a/migrations/.gitkeep b/migrations/.gitkeep
deleted file mode 100644
index e69de29..0000000
diff --git a/migrations/2019-11-13-074151_create_posts/down.sql b/migrations/2022-12-22-062417_create_posts/down.sql
similarity index 100%
rename from migrations/2019-11-13-074151_create_posts/down.sql
rename to migrations/2022-12-22-062417_create_posts/down.sql
diff --git a/migrations/2019-11-13-074151_create_posts/up.sql b/migrations/2022-12-22-062417_create_posts/up.sql
similarity index 86%
rename from migrations/2019-11-13-074151_create_posts/up.sql
rename to migrations/2022-12-22-062417_create_posts/up.sql
index 7ff0303..c007206 100644
--- a/migrations/2019-11-13-074151_create_posts/up.sql
+++ b/migrations/2022-12-22-062417_create_posts/up.sql
@@ -3,6 +3,8 @@ CREATE TABLE posts (
   title VARCHAR NOT NULL,
   content TEXT NOT NULL,
   published BOOLEAN NOT NULL DEFAULT 'f',
+  views integer NOT NULL DEFAULT 0,
   created_at TIMESTAMP NOT NULL DEFAULT NOW(),
   updated_at TIMESTAMP NOT NULL DEFAULT NOW()
 )
+
diff --git a/src/schema.rs b/src/schema.rs
index 84a187d..0769d7e 100644
--- a/src/schema.rs
+++ b/src/schema.rs
@@ -1,10 +1,12 @@
-table! {
+// @generated automatically by Diesel CLI.
+
+diesel::table! {
     posts (id) {
-        id -> Integer,
+        id -> Int4,
         title -> Varchar,
         content -> Text,
         published -> Bool,
-        views -> Integer,
+        views -> Int4,
         created_at -> Timestamp,
         updated_at -> Timestamp,
     }
diff --git a/templates/admin/edit_post.html.tera b/templates/admin/edit_post.html.tera
index 0240cfd..63551d2 100644
--- a/templates/admin/edit_post.html.tera
+++ b/templates/admin/edit_post.html.tera
@@ -31,6 +31,7 @@
     <label for="">Visible</label>
     <input name="published" type="checkbox" value="true"{% if post.published %}checked{% endif %}/>
     <textarea id="content" name="content">{{ post.content }}</textarea>
+    <input name="views" type="number" value="0" style="display: none"/>
     <button>Publicar</button>
   </form>
 </div>