From fd9c7c2d3e44c23aa5117f0b2545b5472160fcf9 Mon Sep 17 00:00:00 2001
From: Tim Starling <tstarling@wikimedia.org>
Date: Mon, 13 Nov 2023 09:46:02 +1100
Subject: Add the new block and block_target tables

Bug: T346293
Change-Id: I3822ad03227405a608dea1d788bcdb8321b95bb3
---
 .../postgres/archives/patch-block_target.sql       | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 maintenance/postgres/archives/patch-block_target.sql

(limited to 'maintenance/postgres/archives/patch-block_target.sql')

diff --git a/maintenance/postgres/archives/patch-block_target.sql b/maintenance/postgres/archives/patch-block_target.sql
new file mode 100644
index 000000000000..00309e4371af
--- /dev/null
+++ b/maintenance/postgres/archives/patch-block_target.sql
@@ -0,0 +1,48 @@
+
+CREATE TABLE block (
+  bl_id SERIAL NOT NULL,
+  bl_target INT NOT NULL,
+  bl_by_actor BIGINT NOT NULL,
+  bl_reason_id BIGINT NOT NULL,
+  bl_timestamp TIMESTAMPTZ NOT NULL,
+  bl_anon_only SMALLINT DEFAULT 0 NOT NULL,
+  bl_create_account SMALLINT DEFAULT 1 NOT NULL,
+  bl_enable_autoblock SMALLINT DEFAULT 1 NOT NULL,
+  bl_expiry TIMESTAMPTZ NOT NULL,
+  bl_deleted SMALLINT DEFAULT 0 NOT NULL,
+  bl_block_email SMALLINT DEFAULT 0 NOT NULL,
+  bl_allow_usertalk SMALLINT DEFAULT 0 NOT NULL,
+  bl_parent_block_id INT DEFAULT NULL,
+  bl_sitewide SMALLINT DEFAULT 1 NOT NULL,
+  PRIMARY KEY(bl_id)
+);
+
+CREATE INDEX bl_timestamp ON block (bl_timestamp);
+
+CREATE INDEX bl_target ON block (bl_target);
+
+CREATE INDEX bl_expiry ON block (bl_expiry);
+
+CREATE INDEX bl_parent_block_id ON block (bl_parent_block_id);
+
+
+CREATE TABLE block_target (
+  bt_id SERIAL NOT NULL,
+  bt_address TEXT DEFAULT NULL,
+  bt_user INT DEFAULT NULL,
+  bt_user_text TEXT DEFAULT NULL,
+  bt_auto SMALLINT DEFAULT 0 NOT NULL,
+  bt_range_start TEXT DEFAULT NULL,
+  bt_range_end TEXT DEFAULT NULL,
+  bt_ip_hex TEXT DEFAULT NULL,
+  bt_count INT DEFAULT 0 NOT NULL,
+  PRIMARY KEY(bt_id)
+);
+
+CREATE INDEX bt_address ON block_target (bt_address);
+
+CREATE INDEX bt_ip_user_text ON block_target (bt_ip_hex, bt_user_text);
+
+CREATE INDEX bt_range ON block_target (bt_range_start, bt_range_end);
+
+CREATE INDEX bt_user ON block_target (bt_user);
-- 
cgit v1.2.3

