diff --git a/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb b/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb new file mode 100644 index 0000000000000000000000000000000000000000..e934da182fd1a166794ed0103348be2c126ead88 --- /dev/null +++ b/db/migrate/20240822195511_add_notification_cols_to_personal_access_tokens.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class AddNotificationColsToPersonalAccessTokens < Gitlab::Database::Migration[2.2] + milestone '17.4' + + def up + add_column :personal_access_tokens, :seven_days_notification_sent_at, :datetime_with_timezone + add_column :personal_access_tokens, :thirty_days_notification_sent_at, :datetime_with_timezone + add_column :personal_access_tokens, :sixty_days_notification_sent_at, :datetime_with_timezone + end + + def down + remove_column :personal_access_tokens, :seven_days_notification_sent_at + remove_column :personal_access_tokens, :thirty_days_notification_sent_at + remove_column :personal_access_tokens, :sixty_days_notification_sent_at + end +end diff --git a/db/post_migrate/20240822200619_add_indices_for_pat_expiry_columns.rb b/db/post_migrate/20240822200619_add_indices_for_pat_expiry_columns.rb new file mode 100644 index 0000000000000000000000000000000000000000..73f1ab9225a66782b8e2c6a31eb56c2bbcca16c2 --- /dev/null +++ b/db/post_migrate/20240822200619_add_indices_for_pat_expiry_columns.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +class AddIndicesForPatExpiryColumns < Gitlab::Database::Migration[2.2] + disable_ddl_transaction! + + milestone '17.4' + + def up + add_concurrent_index :personal_access_tokens, + [:expires_at, :id], + where: 'impersonation = false AND revoked = false AND seven_days_notification_sent_at IS NULL', + name: 'index_pats_on_expiring_at_seven_days_notification_sent_at' + + add_concurrent_index :personal_access_tokens, + [:expires_at, :id], + where: 'impersonation = false AND revoked = false AND thirty_days_notification_sent_at IS NULL', + name: 'index_pats_on_expiring_at_thirty_days_notification_sent_at' + + add_concurrent_index :personal_access_tokens, + [:expires_at, :id], + where: 'impersonation = false AND revoked = false AND sixty_days_notification_sent_at IS NULL', + name: 'index_pats_on_expiring_at_sixty_days_notification_sent_at' + end + + def down + remove_concurrent_index_by_name :personal_access_tokens, + name: 'index_pats_on_expiring_at_seven_days_notification_sent_at' + remove_concurrent_index_by_name :personal_access_tokens, + name: 'index_pats_on_expiring_at_thirty_days_notification_sent_at' + remove_concurrent_index_by_name :personal_access_tokens, + name: 'index_pats_on_expiring_at_sixty_days_notification_sent_at' + end +end diff --git a/db/schema_migrations/20240822195511 b/db/schema_migrations/20240822195511 new file mode 100644 index 0000000000000000000000000000000000000000..45c3c17bdf0ac2f3037938b47ca659b0bf1eb8c1 --- /dev/null +++ b/db/schema_migrations/20240822195511 @@ -0,0 +1 @@ +234b63a3ca62c94f3d2a7b56d466528151d82c36dbdb11614fc035c7ac23d434 \ No newline at end of file diff --git a/db/schema_migrations/20240822200619 b/db/schema_migrations/20240822200619 new file mode 100644 index 0000000000000000000000000000000000000000..9495d9228b5ded44cd81de05729c3062b43f770d --- /dev/null +++ b/db/schema_migrations/20240822200619 @@ -0,0 +1 @@ +d7ef657ff096c75aa7113e0e2562d9432fddfa4e1bb9a3a148fb29aa2926f006 \ No newline at end of file diff --git a/db/structure.sql b/db/structure.sql index 9ce4f88579bd334ed71236298c51d4531549e264..ea7adbad95fdba96dc42a90d8c7745c7abb66141 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -15396,6 +15396,9 @@ CREATE TABLE personal_access_tokens ( previous_personal_access_token_id bigint, advanced_scopes text, organization_id bigint DEFAULT 1 NOT NULL, + seven_days_notification_sent_at timestamp with time zone, + thirty_days_notification_sent_at timestamp with time zone, + sixty_days_notification_sent_at timestamp with time zone, CONSTRAINT check_aa95773861 CHECK ((char_length(advanced_scopes) <= 4096)) ); @@ -29435,6 +29438,12 @@ CREATE INDEX index_path_locks_on_project_id ON path_locks USING btree (project_i CREATE INDEX index_path_locks_on_user_id ON path_locks USING btree (user_id); +CREATE INDEX index_pats_on_expiring_at_seven_days_notification_sent_at ON personal_access_tokens USING btree (expires_at, id) WHERE ((impersonation = false) AND (revoked = false) AND (seven_days_notification_sent_at IS NULL)); + +CREATE INDEX index_pats_on_expiring_at_sixty_days_notification_sent_at ON personal_access_tokens USING btree (expires_at, id) WHERE ((impersonation = false) AND (revoked = false) AND (sixty_days_notification_sent_at IS NULL)); + +CREATE INDEX index_pats_on_expiring_at_thirty_days_notification_sent_at ON personal_access_tokens USING btree (expires_at, id) WHERE ((impersonation = false) AND (revoked = false) AND (thirty_days_notification_sent_at IS NULL)); + CREATE INDEX index_pe_approval_rules_on_required_approvals_and_created_at ON protected_environment_approval_rules USING btree (required_approvals, created_at); CREATE INDEX index_personal_access_tokens_on_id_and_created_at ON personal_access_tokens USING btree (id, created_at);