about summary refs log tree commit diff
path: root/db/migrate
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-31 01:52:08 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:16 -0500
commita036e8561344866b072c2874906c9c9533cd27ea (patch)
tree4bfced891c9ece25baf5f2f644a4176d82b8b611 /db/migrate
parenta0ae00eeb5b89ccd23868e530608fbbc07349a7e (diff)
[Feature] Add general-purpose account metadata to backend
Diffstat (limited to 'db/migrate')
-rw-r--r--db/migrate/20200731064236_create_account_metadata.rb10
-rw-r--r--db/migrate/20200731135033_backfill_account_metadata.rb11
2 files changed, 21 insertions, 0 deletions
diff --git a/db/migrate/20200731064236_create_account_metadata.rb b/db/migrate/20200731064236_create_account_metadata.rb
new file mode 100644
index 000000000..c2eb32b79
--- /dev/null
+++ b/db/migrate/20200731064236_create_account_metadata.rb
@@ -0,0 +1,10 @@
+class CreateAccountMetadata < ActiveRecord::Migration[5.2]
+  disable_ddl_transaction!
+
+  def change
+    create_table :account_metadata do |t|
+      t.references :account, null: false, unique: true, foreign_key: { on_delete: :cascade }
+      t.jsonb :fields, null: false, default: {}
+    end
+  end
+end
diff --git a/db/migrate/20200731135033_backfill_account_metadata.rb b/db/migrate/20200731135033_backfill_account_metadata.rb
new file mode 100644
index 000000000..2ddfa6081
--- /dev/null
+++ b/db/migrate/20200731135033_backfill_account_metadata.rb
@@ -0,0 +1,11 @@
+class BackfillAccountMetadata < ActiveRecord::Migration[5.2]
+  def up
+    safety_assured do
+      execute("INSERT INTO account_metadata (account_id) SELECT id FROM accounts WHERE domain IS NULL OR domain = ''")
+    end
+  end
+
+  def down
+    true
+  end
+end