From a036e8561344866b072c2874906c9c9533cd27ea Mon Sep 17 00:00:00 2001 From: Fire Demon Date: Fri, 31 Jul 2020 01:52:08 -0500 Subject: [Feature] Add general-purpose account metadata to backend --- db/migrate/20200731064236_create_account_metadata.rb | 10 ++++++++++ db/migrate/20200731135033_backfill_account_metadata.rb | 11 +++++++++++ db/schema.rb | 9 ++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20200731064236_create_account_metadata.rb create mode 100644 db/migrate/20200731135033_backfill_account_metadata.rb (limited to 'db') 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 diff --git a/db/schema.rb b/db/schema.rb index 4fcdd7e2f..06d012600 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_07_28_173757) do +ActiveRecord::Schema.define(version: 2020_07_31_135033) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -66,6 +66,12 @@ ActiveRecord::Schema.define(version: 2020_07_28_173757) do t.index ["account_id", "provider", "provider_username"], name: "index_account_proofs_on_account_and_provider_and_username", unique: true end + create_table "account_metadata", force: :cascade do |t| + t.bigint "account_id", null: false + t.jsonb "fields", default: {}, null: false + t.index ["account_id"], name: "index_account_metadata_on_account_id" + end + create_table "account_migrations", force: :cascade do |t| t.bigint "account_id" t.string "acct", default: "", null: false @@ -976,6 +982,7 @@ ActiveRecord::Schema.define(version: 2020_07_28_173757) do add_foreign_key "account_domain_blocks", "accounts", name: "fk_206c6029bd", on_delete: :cascade add_foreign_key "account_domain_permissions", "accounts", on_delete: :cascade add_foreign_key "account_identity_proofs", "accounts", on_delete: :cascade + add_foreign_key "account_metadata", "accounts", on_delete: :cascade add_foreign_key "account_migrations", "accounts", column: "target_account_id", on_delete: :nullify add_foreign_key "account_migrations", "accounts", on_delete: :cascade add_foreign_key "account_moderation_notes", "accounts" -- cgit