From 10171cb32161c9a5ad446ec3f799331cb6133b42 Mon Sep 17 00:00:00 2001
From: Oliver Facklam <oliver.facklam.lfgeb@gmail.com>
Date: Sat, 2 Feb 2019 12:16:21 +0100
Subject: [PATCH] authors et recipients tables dans Knex

---
 ...90202114345_create_announcements_authors.js | 18 ++++++++++++++++++
 ...02114346_create_announcements_recipients.js | 18 ++++++++++++++++++
 .../20190202114347_create_events_authors.js    | 18 ++++++++++++++++++
 .../20190202114348_create_events_recipients.js | 18 ++++++++++++++++++
 4 files changed, 72 insertions(+)
 create mode 100644 db/migrations/20190202114345_create_announcements_authors.js
 create mode 100644 db/migrations/20190202114346_create_announcements_recipients.js
 create mode 100644 db/migrations/20190202114347_create_events_authors.js
 create mode 100644 db/migrations/20190202114348_create_events_recipients.js

diff --git a/db/migrations/20190202114345_create_announcements_authors.js b/db/migrations/20190202114345_create_announcements_authors.js
new file mode 100644
index 0000000..cbc58e4
--- /dev/null
+++ b/db/migrations/20190202114345_create_announcements_authors.js
@@ -0,0 +1,18 @@
+
+exports.up = function (knex, Promise) {
+    return knex.schema.createTable('announcements_authors', function (table) {
+        table.increments('id'); //autoincrementing (non-nullable) primary key
+
+        table.integer('mid').notNullable()
+            .references('mid').inTable('messages_announcements')
+            .onDelete('CASCADE'); //if announcement is deleted, also delete authors
+
+        table.integer('gid').notNullable()
+            .references('gid').inTable('groups')
+            .onDelete('CASCADE'); //if group is deleted, also delete authors
+    });
+};
+
+exports.down = function (knex, Promise) {
+    return knex.schema.dropTable('announcements_authors');
+};
diff --git a/db/migrations/20190202114346_create_announcements_recipients.js b/db/migrations/20190202114346_create_announcements_recipients.js
new file mode 100644
index 0000000..db72ec6
--- /dev/null
+++ b/db/migrations/20190202114346_create_announcements_recipients.js
@@ -0,0 +1,18 @@
+
+exports.up = function (knex, Promise) {
+    return knex.schema.createTable('announcements_recipients', function (table) {
+        table.increments('id'); //autoincrementing (non-nullable) primary key
+
+        table.integer('mid').notNullable()
+            .references('mid').inTable('messages_announcements')
+            .onDelete('CASCADE'); //if announcement is deleted, also delete recipients
+
+        table.integer('gid').notNullable()
+            .references('gid').inTable('groups')
+            .onDelete('CASCADE'); //if group is deleted, also delete recipient
+    });
+};
+
+exports.down = function (knex, Promise) {
+    return knex.schema.dropTable('announcements_recipients');
+};
diff --git a/db/migrations/20190202114347_create_events_authors.js b/db/migrations/20190202114347_create_events_authors.js
new file mode 100644
index 0000000..904d67e
--- /dev/null
+++ b/db/migrations/20190202114347_create_events_authors.js
@@ -0,0 +1,18 @@
+
+exports.up = function (knex, Promise) {
+    return knex.schema.createTable('events_authors', function (table) {
+        table.increments('id'); //autoincrementing (non-nullable) primary key
+
+        table.integer('mid').notNullable()
+            .references('mid').inTable('messages_events')
+            .onDelete('CASCADE'); //if event is deleted, also delete authors
+
+        table.integer('gid').notNullable()
+            .references('gid').inTable('groups')
+            .onDelete('CASCADE'); //if group is deleted, also delete authors
+    });
+};
+
+exports.down = function (knex, Promise) {
+    return knex.schema.dropTable('events_authors');
+};
diff --git a/db/migrations/20190202114348_create_events_recipients.js b/db/migrations/20190202114348_create_events_recipients.js
new file mode 100644
index 0000000..762a3f0
--- /dev/null
+++ b/db/migrations/20190202114348_create_events_recipients.js
@@ -0,0 +1,18 @@
+
+exports.up = function (knex, Promise) {
+    return knex.schema.createTable('events_recipients', function (table) {
+        table.increments('id'); //autoincrementing (non-nullable) primary key
+
+        table.integer('mid').notNullable()
+            .references('mid').inTable('messages_events')
+            .onDelete('CASCADE'); //if event is deleted, also delete recipients
+
+        table.integer('gid').notNullable()
+            .references('gid').inTable('groups')
+            .onDelete('CASCADE'); //if group is deleted, also delete recipient
+    });
+};
+
+exports.down = function (knex, Promise) {
+    return knex.schema.dropTable('events_recipients');
+};
-- 
GitLab