From 89cb0f5fd432245426a7d155b3e1cd8c547bccab Mon Sep 17 00:00:00 2001
From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Date: Wed, 28 Jun 2023 12:18:53 +0000
Subject: [PATCH] Bug 33537: Database revision, adding table mail_domain_limits
Content-Type: text/plain; charset=utf-8

Test plan:
Run dbrev or new install.
Verify that table is created as expected.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com>
---
 installer/data/mysql/atomicupdate/bug33537.pl | 28 +++++++++++++++++++
 installer/data/mysql/kohastructure.sql        | 18 ++++++++++++
 2 files changed, 46 insertions(+)
 create mode 100755 installer/data/mysql/atomicupdate/bug33537.pl

diff --git a/installer/data/mysql/atomicupdate/bug33537.pl b/installer/data/mysql/atomicupdate/bug33537.pl
new file mode 100755
index 0000000000..8a621d9f81
--- /dev/null
+++ b/installer/data/mysql/atomicupdate/bug33537.pl
@@ -0,0 +1,28 @@
+use Modern::Perl;
+
+return {
+    bug_number => 33537,
+    description => "Add table mail_domain_limits",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+
+        if ( !table_exists('mail_domain_limits') ) {
+            $dbh->do(q{
+CREATE TABLE `mail_domain_limits` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `domain_name` tinytext COLLATE utf8mb4_unicode_ci NOT NULL,
+  `domain_limit` int(11) DEFAULT NULL,
+  `units` int(11) DEFAULT NULL,
+  `unit_type` enum('minutes','hours','days') COLLATE utf8mb4_unicode_ci,
+  `belongs_to` int(11) DEFAULT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `mail_domain_limits_uniq1` (`domain_name`(191)),
+  KEY `mail_domain_limits_fk1` (`belongs_to`),
+  CONSTRAINT `mail_domain_limits_fk1` FOREIGN KEY (`belongs_to`) REFERENCES `mail_domain_limits` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+            });
+            say $out "Added new table 'mail_domain_limits'";
+        }
+    },
+};
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index d91bd46b32..ce3b40be05 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -4025,6 +4025,24 @@ CREATE TABLE `localization` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
 /*!40101 SET character_set_client = @saved_cs_client */;
 
+--
+-- Table structure for table `mail_domain_limits`
+--
+
+CREATE TABLE `mail_domain_limits` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `domain_name` tinytext COLLATE utf8mb4_unicode_ci NOT NULL,
+  `domain_limit` int(11) DEFAULT NULL,
+  `units` int(11),
+  `unit_type` enum('minutes','hours','days') COLLATE utf8mb4_unicode_ci,
+  `belongs_to` int(11) DEFAULT NULL,
+  PRIMARY KEY (`id`),
+  UNIQUE KEY `mail_domain_limits_uniq1` (`domain_name`(191)),
+  KEY `mail_domain_limits_fk1` (`belongs_to`),
+  CONSTRAINT `mail_domain_limits_fk1` FOREIGN KEY (`belongs_to`) REFERENCES `mail_domain_limits` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+/*!40101 SET character_set_client = @saved_cs_client */;
+
 --
 -- Table structure for table `marc_matchers`
 --
-- 
2.30.2