From e88f77b03eafbcb62371415ad5b5bd3694eeef0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix=20Veillette-Potvin?= <fveillette@gitlab.com>
Date: Fri, 24 May 2024 12:44:14 +0000
Subject: [PATCH] Add database migration in preparation to add advanced scope
 tokens

---
 ...20240517192053_add_advanced_token_scope.rb | 21 +++++++++++++++++++
 db/schema_migrations/20240517192053           |  1 +
 db/structure.sql                              |  4 +++-
 3 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 db/migrate/20240517192053_add_advanced_token_scope.rb
 create mode 100644 db/schema_migrations/20240517192053

diff --git a/db/migrate/20240517192053_add_advanced_token_scope.rb b/db/migrate/20240517192053_add_advanced_token_scope.rb
new file mode 100644
index 0000000000000..fb34cdcaea94f
--- /dev/null
+++ b/db/migrate/20240517192053_add_advanced_token_scope.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+class AddAdvancedTokenScope < Gitlab::Database::Migration[2.2]
+  disable_ddl_transaction!
+
+  milestone '17.1'
+
+  def up
+    with_lock_retries do
+      add_column :personal_access_tokens, :advanced_scopes, :text, if_not_exists: true
+    end
+
+    add_text_limit :personal_access_tokens, :advanced_scopes, 4096
+  end
+
+  def down
+    with_lock_retries do
+      remove_column :personal_access_tokens, :advanced_scopes, if_exists: true
+    end
+  end
+end
diff --git a/db/schema_migrations/20240517192053 b/db/schema_migrations/20240517192053
new file mode 100644
index 0000000000000..76fd64e2c0b90
--- /dev/null
+++ b/db/schema_migrations/20240517192053
@@ -0,0 +1 @@
+520aba73d923a667f37068c1d39cb0f8cc2b5b84c4653ebf50248961e65d6566
\ No newline at end of file
diff --git a/db/structure.sql b/db/structure.sql
index 05788f3b2e657..ae44d9ba49a1a 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -13522,7 +13522,9 @@ CREATE TABLE personal_access_tokens (
     expire_notification_delivered boolean DEFAULT false NOT NULL,
     last_used_at timestamp with time zone,
     after_expiry_notification_delivered boolean DEFAULT false NOT NULL,
-    previous_personal_access_token_id bigint
+    previous_personal_access_token_id bigint,
+    advanced_scopes text,
+    CONSTRAINT check_aa95773861 CHECK ((char_length(advanced_scopes) <= 4096))
 );
 
 CREATE SEQUENCE personal_access_tokens_id_seq
-- 
GitLab