DEV: Promote historic post-deploy migrations (#30)

DEV: Promote historic post-deploy migrations (#30)

diff --git a/db/migrate/20190817010201_migrate_post_policy_data.rb b/db/migrate/20190817010201_migrate_post_policy_data.rb
new file mode 100644
index 0000000..1f88648
--- /dev/null
+++ b/db/migrate/20190817010201_migrate_post_policy_data.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+class MigratePostPolicyData < ActiveRecord::Migration[5.2]
+  def up
+    execute(<<~SQL)
+      INSERT INTO post_policies(
+        post_id,
+        group_id,
+        version,
+        reminder,
+        last_reminded_at,
+        renew_days,
+        updated_at,
+        created_at
+      )
+      SELECT
+        f1.post_id,
+        (select id from groups where name ilike f1.value) group_id,
+        f2.value as version,
+        f3.value as reminder,
+        case when f4.value ~ '^[0-9]+$' then
+          TIMESTAMP 'epoch' + f4.value::integer * interval '1 second'
+          else null end
+        as last_reminded_at,
+        case when f5.value ~ '^[0-9]+$' then
+           f5.value::integer else null end
+        as renew_days,
+        greatest(f1.updated_at, f2.updated_at) as updated_at,
+        least(f1.updated_at, f2.updated_at) as created_at
+      FROM post_custom_fields f1
+      LEFT JOIN post_custom_fields f2 ON
+        f1.post_id = f2.post_id AND f2.name = 'PolicyVersion'
+      LEFT JOIN post_custom_fields f3 ON
+        f1.post_id = f3.post_id AND f3.name = 'PolicyReminder'
+      LEFT JOIN post_custom_fields f4 ON
+        f1.post_id = f4.post_id AND f4.name = 'LastRemindedAt'
+      LEFT JOIN post_custom_fields f5 ON
+        f1.post_id = f5.post_id AND f5.name = 'PolicyRenewDays'
+      WHERE f1.name = 'PolicyGroup'
+      AND  (select id from groups where name ilike f1.value) is not null
+      ON CONFLICT DO NOTHING
+    SQL
+
+    execute(<<~SQL)
+      INSERT INTO post_custom_fields (post_id, name, value, created_at, updated_at)
+      SELECT post_id, 'HasPolicy', 'true', created_at, updated_at
+      FROM post_policies
+    SQL
+
+    execute(<<~SQL)
+      DELETE FROM post_custom_fields
+      WHERE name in (
+        'PolicyGroup',
+        'PolicyVersion',
+        'PolicyReminder',
+        'PolicyRemindedAt',
+        'PolicyRenewDays'
+      )
+    SQL
+  end
+end
diff --git a/db/migrate/20191014224419_migrate_custom_field_to_policy_users.rb b/db/migrate/20191014224419_migrate_custom_field_to_policy_users.rb
new file mode 100644
index 0000000..86a22e9
--- /dev/null
+++ b/db/migrate/20191014224419_migrate_custom_field_to_policy_users.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class MigrateCustomFieldToPolicyUsers < ActiveRecord::Migration[5.2]
+  def up
+    execute(<<~SQL)
+    INSERT INTO policy_users(post_policy_id, user_id, version, accepted_at, created_at, updated_at)
+    SELECT post_policies.id, post_custom_fields.value::INTEGER, post_policies.version, post_custom_fields.created_at, post_custom_fields.created_at, post_custom_fields.updated_at
+    FROM post_custom_fields
+    INNER JOIN post_policies ON post_policies.post_id = post_custom_fields.post_id
+    WHERE post_custom_fields.name = 'PolicyAcceptedBy'
+    SQL
+
+    execute(<<~SQL)
+    DELETE FROM post_custom_fields WHERE name = 'PolicyAcceptedBy'
+    SQL
+  end
+end
diff --git a/db/post_migrate/20190817010201_migrate_post_policy_data.rb b/db/post_migrate/20190817010201_migrate_post_policy_data.rb
deleted file mode 100644
index 1f88648..0000000
--- a/db/post_migrate/20190817010201_migrate_post_policy_data.rb
+++ /dev/null
@@ -1,61 +0,0 @@
-# frozen_string_literal: true
-
-class MigratePostPolicyData < ActiveRecord::Migration[5.2]
-  def up
-    execute(<<~SQL)
-      INSERT INTO post_policies(
-        post_id,
-        group_id,
-        version,
-        reminder,
-        last_reminded_at,
-        renew_days,
-        updated_at,
-        created_at
-      )
-      SELECT
-        f1.post_id,
-        (select id from groups where name ilike f1.value) group_id,
-        f2.value as version,
-        f3.value as reminder,
-        case when f4.value ~ '^[0-9]+$' then
-          TIMESTAMP 'epoch' + f4.value::integer * interval '1 second'
-          else null end
-        as last_reminded_at,
-        case when f5.value ~ '^[0-9]+$' then
-           f5.value::integer else null end
-        as renew_days,
-        greatest(f1.updated_at, f2.updated_at) as updated_at,
-        least(f1.updated_at, f2.updated_at) as created_at
-      FROM post_custom_fields f1
-      LEFT JOIN post_custom_fields f2 ON
-        f1.post_id = f2.post_id AND f2.name = 'PolicyVersion'
-      LEFT JOIN post_custom_fields f3 ON
-        f1.post_id = f3.post_id AND f3.name = 'PolicyReminder'
-      LEFT JOIN post_custom_fields f4 ON
-        f1.post_id = f4.post_id AND f4.name = 'LastRemindedAt'
-      LEFT JOIN post_custom_fields f5 ON
-        f1.post_id = f5.post_id AND f5.name = 'PolicyRenewDays'
-      WHERE f1.name = 'PolicyGroup'
-      AND  (select id from groups where name ilike f1.value) is not null
-      ON CONFLICT DO NOTHING
-    SQL
-
-    execute(<<~SQL)
-      INSERT INTO post_custom_fields (post_id, name, value, created_at, updated_at)
-      SELECT post_id, 'HasPolicy', 'true', created_at, updated_at
-      FROM post_policies
-    SQL
-
-    execute(<<~SQL)
-      DELETE FROM post_custom_fields
-      WHERE name in (
-        'PolicyGroup',
-        'PolicyVersion',
-        'PolicyReminder',
-        'PolicyRemindedAt',
-        'PolicyRenewDays'
-      )
-    SQL
-  end
-end
diff --git a/db/post_migrate/20191014224419_migrate_custom_field_to_policy_users.rb b/db/post_migrate/20191014224419_migrate_custom_field_to_policy_users.rb
deleted file mode 100644
index 86a22e9..0000000
--- a/db/post_migrate/20191014224419_migrate_custom_field_to_policy_users.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-# frozen_string_literal: true
-
-class MigrateCustomFieldToPolicyUsers < ActiveRecord::Migration[5.2]
-  def up
-    execute(<<~SQL)
-    INSERT INTO policy_users(post_policy_id, user_id, version, accepted_at, created_at, updated_at)
-    SELECT post_policies.id, post_custom_fields.value::INTEGER, post_policies.version, post_custom_fields.created_at, post_custom_fields.created_at, post_custom_fields.updated_at
-    FROM post_custom_fields
-    INNER JOIN post_policies ON post_policies.post_id = post_custom_fields.post_id
-    WHERE post_custom_fields.name = 'PolicyAcceptedBy'
-    SQL
-
-    execute(<<~SQL)
-    DELETE FROM post_custom_fields WHERE name = 'PolicyAcceptedBy'
-    SQL
-  end
-end

GitHub sha: 2ae49bc105cb980308c660417621abf0c6b81d43

This commit appears in #30 which was approved by CvX. It was merged by davidtaylorhq.