From 70963c68a75ca12322fe0c46943ad903949bbe97 Mon Sep 17 00:00:00 2001
From: ManifoldFR <wilson.jallet@gmail.com>
Date: Fri, 16 Mar 2018 00:48:37 +0100
Subject: [PATCH] Migrations to reimplement posts and add views counter to
 announcements

---
 .../20180305111321_metaGroup_member_table.js  | 14 ++++++-------
 db/migrations/20180309145434_supervision.js   |  2 +-
 .../20180316003119_create_posts_again.js      | 20 +++++++++++++++++++
 db/seeds/02_make_posts.js                     | 10 ++++------
 4 files changed, 32 insertions(+), 14 deletions(-)
 create mode 100644 db/migrations/20180316003119_create_posts_again.js

diff --git a/db/migrations/20180305111321_metaGroup_member_table.js b/db/migrations/20180305111321_metaGroup_member_table.js
index ab7268d..b69354e 100644
--- a/db/migrations/20180305111321_metaGroup_member_table.js
+++ b/db/migrations/20180305111321_metaGroup_member_table.js
@@ -1,13 +1,13 @@
 
 exports.up = function(knex, Promise) {
-  return knex.schema.createTable('meta_group_membership', function (table){
-    table.timestamp(true, true);
-    table.string('member_uid').notNullable();
-    table.string('union_uid').notNullable();
-    table.enum('status', ['admin', 'speaker', 'basic']).notNullable();
-  });
+    return knex.schema.createTable('meta_group_membership', function (table){
+        table.timestamp(true, true);
+        table.string('member_uid').notNullable();
+        table.string('union_uid').notNullable();
+        table.enum('status', ['admin', 'speaker', 'basic']).notNullable();
+    });
 };
 
 exports.down = function(knex, Promise) {
-  return knex.schema.dropTable('meta_group_membership');
+    return knex.schema.dropTable('meta_group_membership');
 };
diff --git a/db/migrations/20180309145434_supervision.js b/db/migrations/20180309145434_supervision.js
index d7ffa96..554e48a 100644
--- a/db/migrations/20180309145434_supervision.js
+++ b/db/migrations/20180309145434_supervision.js
@@ -10,5 +10,5 @@ exports.up = function(knex, Promise) {
 };
 
 exports.down = function(knex, Promise) {
-  return knex.schema.dropTable('taken_rights');
+    return knex.schema.dropTable('taken_rights');
 };
diff --git a/db/migrations/20180316003119_create_posts_again.js b/db/migrations/20180316003119_create_posts_again.js
new file mode 100644
index 0000000..6378378
--- /dev/null
+++ b/db/migrations/20180316003119_create_posts_again.js
@@ -0,0 +1,20 @@
+
+exports.up = async function(knex, Promise) {
+    await knex.schema.createTable('posts', function(table) {
+        table.inherits('messages');
+    });
+    await knex.schema.table('announcements', function(table) {
+        table.integer('views').defaultTo(0);
+    });
+    return;
+};
+
+exports.down = async function(knex, Promise) {
+    await knex.schema.dropTable('posts');
+
+    await knex.schema.table("announcements", function(table) {
+        table.dropColumn('views');
+    });
+
+    return;
+};
diff --git a/db/seeds/02_make_posts.js b/db/seeds/02_make_posts.js
index 039ff10..c17781b 100644
--- a/db/seeds/02_make_posts.js
+++ b/db/seeds/02_make_posts.js
@@ -1,28 +1,26 @@
 
 exports.seed = function(knex, Promise) {
   // Deletes ALL existing entries
-  /*
   return knex('posts').del()
     .then(function () {
       const posts = [{
         title: "Fissurer c'est bien",
-        description: "Les nouveaux ordis du JTX sont arrivés ! Le BR aide à les installer ;)",
+        content: "Les nouveaux ordis du JTX sont arrivés ! Le BR aide à les installer ;)",
         authors: ['br','jtx']
       },{
         title: "Proj'et Promotion",
-        description: "La nouvelle proj' du JTX arrive !",
+        content: "La nouvelle proj' du JTX arrive !",
         authors: ['br']
       },{
         title: "Fête de la Lune",
-        description: "C'est bientôt la fête de la Lune ! Inscrivez-vous pour un dîner-spectacle dans le Grand Hall !",
+        content: "C'est bientôt la fête de la Lune ! Inscrivez-vous pour un dîner-spectacle dans le Grand Hall !",
         authors: ['x-chine']
       },{
         title: "Formation Web",
-        description: "Envie d'apprendre à faire un site Web en Django ? Alors viens en amphi Sauvy ce jeudi à 20h !",
+        content: "Envie d'apprendre à faire un site Web en Django ? Alors viens en amphi Sauvy ce jeudi à 20h !",
         authors: ['br']
       }];
 
       return knex('posts').insert(posts);
     });
-    */
 };
-- 
GitLab