Skip to content

Commit f124259

Browse files
committed
make the default access group created on migration to avoid primary key sequence issues
1 parent 7103ac9 commit f124259

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/inc/utils/AccessUtils.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ public static function getAccessGroupsOfAgent(Agent $agent): array {
164164
public static function getOrCreateDefaultAccessGroup() {
165165
$accessGroup = Factory::getAccessGroupFactory()->get(1);
166166
if ($accessGroup == null) {
167+
// this should never happen anymore (unless someone deleted access group with ID 1)
167168
$accessGroup = new AccessGroup(1, "Default Group");
168169
$accessGroup = Factory::getAccessGroupFactory()->save($accessGroup);
169170
}

src/install/updates/update_v1.0.0-rainbow4_vx.x.x.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
if (!Util::databaseTableExists("_sqlx_migrations")) {
2626
// this creates the existing state for sqlx to continue with migrations for all further updates
2727
Factory::getAgentFactory()->getDB()->query("CREATE TABLE `_sqlx_migrations` (`version` bigint NOT NULL, `description` text NOT NULL, `installed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `success` tinyint(1) NOT NULL, `checksum` blob NOT NULL, `execution_time` bigint NOT NULL, PRIMARY KEY (`version`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;");
28-
Factory::getAgentFactory()->getDB()->query("INSERT INTO `_sqlx_migrations` VALUES (20251127000000,'initial','2025-11-28 14:29:13',1,0x22F3A0D84CF66E9694946A244FBC19B314F0EA85B9B5C66A3C2BB67EE365AA78D025D9C90FBCCE8E4896FD20988A6740,1);");
28+
Factory::getAgentFactory()->getDB()->query("INSERT INTO `_sqlx_migrations` VALUES (20251127000000,'initial','2025-11-28 14:29:13',1,0xA5A8F03AAD0827C86C4A380D935BF1CCB3B5D5F174D7FC40B3D267FD0B6BB7DD4181A9C25EFC5CFCE24DF760F4C2D881,1);");
2929
}
3030
$EXECUTED["v1.0.0-rainbow4_migration_to_migrations"] = true;
3131
}

src/migrations/mysql/20251127000000_initial.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CREATE TABLE IF NOT EXISTS `AccessGroup` (
1212
`groupName` VARCHAR(50) NOT NULL
1313
) ENGINE = InnoDB;
1414

15+
INSERT INTO `AccessGroup` (`accessGroupId`, `groupName`) VALUES
16+
(1, 'Default Group');
17+
1518
CREATE TABLE IF NOT EXISTS `AccessGroupAgent` (
1619
`accessGroupAgentId` INT(11) NOT NULL,
1720
`accessGroupId` INT(11) NOT NULL,
@@ -1272,7 +1275,8 @@ ALTER TABLE `Preprocessor`
12721275

12731276
-- Add AUTO_INCREMENT for tables
12741277
ALTER TABLE `AccessGroup`
1275-
MODIFY `accessGroupId` INT(11) NOT NULL AUTO_INCREMENT;
1278+
MODIFY `accessGroupId` INT(11) NOT NULL AUTO_INCREMENT,
1279+
AUTO_INCREMENT = 2;
12761280

12771281
ALTER TABLE `AccessGroupAgent`
12781282
MODIFY `accessGroupAgentId` INT(11) NOT NULL AUTO_INCREMENT;

src/migrations/postgres/20251127000000_initial.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CREATE TABLE AccessGroup (
44
groupName TEXT NOT NULL
55
);
66

7+
INSERT INTO AccessGroup (accessGroupId, groupName) VALUES
8+
(1, 'Default Group');
9+
710
CREATE TABLE AccessGroupAgent (
811
accessGroupAgentId SERIAL NOT NULL PRIMARY KEY,
912
accessGroupId INT NOT NULL,

0 commit comments

Comments
 (0)