FIX: ensures migration order is correct (#27)

FIX: ensures migration order is correct (#27)

diff --git a/db/migrate/20200409102639_drop_incorrect_future_schema_migrations.rb b/db/migrate/20200409102639_drop_incorrect_future_schema_migrations.rb
new file mode 100644
index 0000000..619b699
--- /dev/null
+++ b/db/migrate/20200409102639_drop_incorrect_future_schema_migrations.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+
+class DropIncorrectFutureSchemaMigrations < ActiveRecord::Migration[5.2]
+  def up
+    execute <<-SQL
+      DELETE FROM schema_migrations WHERE version = '20201303000001';
+      DELETE FROM schema_migration_details WHERE version = '20201303000001';
+      DELETE FROM schema_migrations WHERE version = '20201303000002';
+      DELETE FROM schema_migration_details WHERE version = '20201303000002';
+    SQL
+  end
+end
diff --git a/db/migrate/20200409102640_create_post_events_table.rb b/db/migrate/20200409102640_create_post_events_table.rb
new file mode 100644
index 0000000..68b74de
--- /dev/null
+++ b/db/migrate/20200409102640_create_post_events_table.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+class CreatePostEventsTable < ActiveRecord::Migration[5.2]
+  def up
+    unless ActiveRecord::Base.connection.table_exists?('discourse_calendar_post_events')
+      create_table :discourse_calendar_post_events, id: false do |t|
+        t.bigint :id, null: false, primary_key: true
+        t.integer :status, default: 0, null: false
+        t.integer :display_invitees, default: 0, null: false
+        t.datetime :starts_at, null: false, default: -> { 'CURRENT_TIMESTAMP' }
+        t.datetime :ends_at
+        t.datetime :deleted_at
+        t.string :raw_invitees, array: true
+        t.string :name
+      end
+    end
+  end
+
+  def down
+    drop_table :discourse_calendar_post_events
+  end
+end
diff --git a/db/migrate/20200409102641_create_invitees_table.rb b/db/migrate/20200409102641_create_invitees_table.rb
new file mode 100644
index 0000000..9fb75cb
--- /dev/null
+++ b/db/migrate/20200409102641_create_invitees_table.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class CreateInviteesTable < ActiveRecord::Migration[5.2]
+  def up
+    unless ActiveRecord::Base.connection.table_exists?('discourse_calendar_invitees')
+      create_table :discourse_calendar_invitees do |t|
+        t.integer :post_id, null: false
+        t.integer :user_id, null: false
+        t.integer :status
+        t.timestamps null: false
+        t.boolean :notified, null: false, default: false
+      end
+
+      add_index :discourse_calendar_invitees, [:post_id, :user_id], unique: true
+    end
+  end
+
+  def down
+    drop_table :discourse_calendar_invitees
+  end
+end
diff --git a/db/migrate/20201303000001_create_post_events_table.rb b/db/migrate/20201303000001_create_post_events_table.rb
deleted file mode 100644
index 1f3c758..0000000
--- a/db/migrate/20201303000001_create_post_events_table.rb
+++ /dev/null
@@ -1,20 +0,0 @@
-# frozen_string_literal: true
-
-class CreatePostEventsTable < ActiveRecord::Migration[5.2]
-  def up
-    create_table :discourse_calendar_post_events, id: false do |t|
-      t.bigint :id, null: false, primary_key: true
-      t.integer :status, default: 0, null: false
-      t.integer :display_invitees, default: 0, null: false
-      t.datetime :starts_at, null: false, default: -> { 'CURRENT_TIMESTAMP' }
-      t.datetime :ends_at
-      t.datetime :deleted_at
-      t.string :raw_invitees, array: true
-      t.string :name
-    end
-  end
-
-  def down
-    drop_table :discourse_calendar_post_events
-  end
-end
diff --git a/db/migrate/20201303000002_create_invitees_table.rb b/db/migrate/20201303000002_create_invitees_table.rb
deleted file mode 100644
index cb3432b..0000000
--- a/db/migrate/20201303000002_create_invitees_table.rb
+++ /dev/null
@@ -1,19 +0,0 @@
-# frozen_string_literal: true
-
-class CreateInviteesTable < ActiveRecord::Migration[5.2]
-  def up
-    create_table :discourse_calendar_invitees do |t|
-      t.integer :post_id, null: false
-      t.integer :user_id, null: false
-      t.integer :status
-      t.timestamps null: false
-      t.boolean :notified, null: false, default: false
-    end
-
-    add_index :discourse_calendar_invitees, [:post_id, :user_id], unique: true
-  end
-
-  def down
-    drop_table :discourse_calendar_invitees
-  end
-end

GitHub sha: 646201d7

This commit appears in #27 which was approved by davidtaylorhq. It was merged by jjaffeux.