about summary refs log tree commit diff
path: root/db
diff options
context:
space:
mode:
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>2017-04-30 07:27:31 +0900
committerEugen Rochko <eugen@zeonfederated.com>2017-04-30 00:27:31 +0200
commit5135d609b774b177d3d3894b176a822d86b73d3c (patch)
treed0c2d75383518ab63fa80df617dd62bec25bba89 /db
parentf48cb3eb170314cba1938522c0da44af21d47e83 (diff)
Use PostgreSQL inheritance for blocks and mutes (#2520)
Diffstat (limited to 'db')
-rw-r--r--db/migrate/20180428000000_create_block_mutes.rb19
-rw-r--r--db/schema.rb14
2 files changed, 32 insertions, 1 deletions
diff --git a/db/migrate/20180428000000_create_block_mutes.rb b/db/migrate/20180428000000_create_block_mutes.rb
new file mode 100644
index 000000000..149c91a4d
--- /dev/null
+++ b/db/migrate/20180428000000_create_block_mutes.rb
@@ -0,0 +1,19 @@
+class CreateBlockMutes < ActiveRecord::Migration[5.0]
+  def change
+    create_table "block_mutes", force: :casecade do |t|
+      t.integer  "account_id",        null: false
+      t.integer  "target_account_id", null: false
+      t.boolean  "block",             null: false
+      t.datetime "created_at",        null: false
+      t.datetime "updated_at",        null: false
+    end
+
+    add_column       :blocks, :block, :boolean, null: false
+    execute          "ALTER TABLE blocks ADD CONSTRAINT check_mutes_on_block CHECK(block = TRUE), INHERIT block_mutes"
+    Block.update_all block: true
+
+    add_column       :mutes, :block, :boolean, null: false
+    execute          "ALTER TABLE mutes ADD CONSTRAINT check_mutes_on_block CHECK(block = FALSE), INHERIT block_mutes"
+    Mute.update_all block: false
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 66326f2e2..ea948c429 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: 20170425202925) do
+ActiveRecord::Schema.define(version: 20180428000000) do
 
   # These are extensions that must be enabled in order to support this database
   enable_extension "plpgsql"
@@ -54,13 +54,23 @@ ActiveRecord::Schema.define(version: 20170425202925) do
     t.index ["username", "domain"], name: "index_accounts_on_username_and_domain", unique: true, using: :btree
   end
 
+  create_table "block_mutes", force: :cascade, id: false do |t|
+    t.integer  "account_id",        null: false
+    t.integer  "target_account_id", null: false
+    t.boolean  "block",             null: false
+    t.datetime "created_at",        null: false
+    t.datetime "updated_at",        null: false
+  end
+
   create_table "blocks", force: :cascade do |t|
     t.integer  "account_id",        null: false
     t.integer  "target_account_id", null: false
+    t.boolean  "block",             null: false
     t.datetime "created_at",        null: false
     t.datetime "updated_at",        null: false
     t.index ["account_id", "target_account_id"], name: "index_blocks_on_account_id_and_target_account_id", unique: true, using: :btree
   end
+  execute   "ALTER TABLE blocks ADD CONSTRAINT check_blocks_on_block CHECK(block = TRUE), INHERIT block_mutes"
 
   create_table "domain_blocks", force: :cascade do |t|
     t.string   "domain",       default: "", null: false
@@ -137,10 +147,12 @@ ActiveRecord::Schema.define(version: 20170425202925) do
   create_table "mutes", force: :cascade do |t|
     t.integer  "account_id",        null: false
     t.integer  "target_account_id", null: false
+    t.boolean  "block",             null: false
     t.datetime "created_at",        null: false
     t.datetime "updated_at",        null: false
     t.index ["account_id", "target_account_id"], name: "index_mutes_on_account_id_and_target_account_id", unique: true, using: :btree
   end
+  execute   "ALTER TABLE mutes ADD CONSTRAINT check_mutes_on_block CHECK(block = FALSE), INHERIT block_mutes"
 
   create_table "notifications", force: :cascade do |t|
     t.integer  "account_id"